it is clearly stated in the examples how to send message but, i am not clear with how to receive messages initiated by other client in the server any help is highly appreciated
Here is my code for sending the message
include("xmpphp/xmpp.php");
//username = user without domain, "user" and not "user#server" - home is the resource
$conn = new XMPPHP_XMPP('localhost', 5222, 'robel27', 'yoyene122127', 'kiyos');
// Enables TLS - enabled by default, call before connect()!
$conn->useEncryption(false);
$conn->connect();
// shows the user's status message
$conn->presence();
$conn->processUntil(array('session_start', 'roster_received'));
$conn->processTime(2);
$conn->message('kiyos12#kiyos', $_POST['msg1']);
$conn->disconnect();
To get messages you can use $data = $conn->processUntil('message');
Related
I am new to the Twilio PHP API and am finding it difficult using the sample code and even finding the correct documentation on the Twilio site to help me implement SMS messaging into our web app.
After much trial and error, and reading through some postings on this site, I have gotten far enough to figure out how to send a simple SMS message and even use a try/catch structure to deal with bad recipient phone numbers.
What I cannot for the life of me figure out is how to catch authentication errors with a client's SID and AUTH token. I'd like to catch authentication errors for a client's credentials before I try even sending messages for them. Some clients may blast a message to 200 customers so I don't want to spin my wheels if their authenticaiton fails. Heres what I have been trying:
require_once K_DOCROOT.'/includes/twilio-php-main/src/Twilio/autoload.php';
// use Twilio\Rest\Client;
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = "ACf6eXXXGGGDDDDDDDDDDDDDDDDDDDDDDD"; // intentionally incorrect
$token = "164d3a88f753e553691960fb4d405f82";
$dest = "+15106443333"; // recipient number
try {
$twilio = new Twilio\Rest\Client($sid, $token); // Had to change this to make it work without the USE above
// $message = $twilio->messages->create($dest, // to
// [
// "body" => "Testing 123",
// "from" => "+19998887777"
// ]
// );
//
// echo "Results: ".$message->sid;
}
catch (Exception $e) {
echo $e->getCode()." : ".$e->getMessage();
}
When I run this without the $twilio->messages->create() code, I get nothing... no errors, no responses whatsoever. If I uncomment the create() section where I try and send a message, I get the following:
20003 : [HTTP 401] Unable to create record: Authentication Error - invalid username
Which makes sense. But it is forcing me to catch the authentication error when sending a message and not before.
Maybe I am missing something, but is there some way to check for authentication errors, or get back some sort of status code letting me know a client's authentication was successful or not?
Also, if you have a link to the documentation that covers error handling for Client() calls, I would greatly appreciate it.
I am trying to send an (simple test) email when I receive an account.updated call for a custom account from Stripe API. My other webhooks to create charges and inform customers about successful or failed charges work like this, but here I get an error 500 (I can see that in the dashboard of the custom account) and the mail is NOT send, so I am not sure what I am doing wrong here. My code looks like this:
<?php
require_once('vendor/autoload.php');
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_XXXX");
// Retrieve the request's body and parse it as JSON
$input = #file_get_contents("php://input");
$event_json = json_decode($input);
// Verify the event by fetching it from Stripe
$event = \Stripe\Event::retrieve($event_json->id);
// Do something with $event
if ($event->type == 'account.updated') {
// The E-Mail message to send to inform about a succeeded charge
$message = 'test';
// Send the E-Mail
mail('test#example.com', 'We need more info about you!', $message);
}
http_response_code(200); // PHP 5.4 or greater
Thank you for your help!
If you look at your web server's error.log (usually accessible from your hosting control panel or in /var/log/) do you see more detail on what's causing the 500?
Could it be $event = \Stripe\Event::retrieve($event_json->id); failing?
If the event is occurring directly on a connected account, you may also need to pass the account id to retrieve it.
See here for a bit more context,
https://stripe.com/docs/connect/webhooks
The code would be more like:
$event = \Stripe\Event::retrieve(
array("id" => $event_json->id),
array("stripe_account" => $event_json->account));
https://stripe.com/docs/connect/authentication#authentication-via-the-stripe-account-header
With php-ews is there a possibility to copy a message from an inbox to other user's inbox?
The goal is that a message is created by php-ews in a web interface, saved to a shared inbox and after this save a copy of the message to user's inbox.
My code so far:
$id = $mail_items[$i]->ItemId->Id;
$change_key = $mail_items[$i]->ItemId->ChangeKey;
$request = new EWSType_CopyItemType();
$request->ToFolderId->FolderId->Id = $user_folder_id;
$request->ToFolderId->FolderId->ChangeKey = $user_folder_ckey;
$request->ItemIds->ItemId->Id = $id;
$request->ItemIds->ItemId->ChangeKey = $change_key;
$response = $ews->CopyItem($request);
The message does not appear in the other user's inbox. Thanks!
Thanks to Gareth Parker, my error was found.
I had forgotten to give always the exchange version in my clients.
just specify the same Exchange version in every client you create:
$ews = new ExchangeWebServices($host, $username, $password, ExchangeWebServices::VERSION_2007_SP1);
I have something wrong with my notifications but i can't see where is the problem. I have an app that generates the token successfully, at first I was able to send a notification from my localhost to the device, but after i restored the device and and tested with the new device token to push a simple notification i couldn't get get it to work even though I didn't made any changes to php code nor my app code, here is my php code :
require_once 'ApnsPHP/Autoload.php';
// Instantiate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
'server_certificates_bundle_sandbox.pem'
);
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
// Connect to the Apple Push Notification Service
$push->connect();
// Instantiate a new Message with a single recipient
$message = new ApnsPHP_Message($token);
// Set a simple welcome text
$message->setText("GELLLOOOOOO");
// Play the default sound
$message->setSound();
// Add the message to the message queue
$push->add($message);
$push->send();
$push->disconnect();
// Examine the error message container
$aErrorQueue = $push->getErrors();
var_dump($aErrorQueue);
I think it have something to do with certificates but i'm not sure where is the issues since it was working before and there is nothing in $aErrorQueue , just an empty array.
<?php
include("XMPP.php");
$conn = new XMPPHP_XMPP('server.com', 5222, 'user', 'pass', 'home');
$conn->useEncryption(true);
$conn->connect();
$conn->processUntil('session_start');
$conn->message('person#server.com', mktime());
$payloads = $conn->processUntil('message');
$conn->message('person#server.com', mktime());
$conn->disconnect();
?>
Right... so it connects - it starts the session and sends the first timestamp which is received on the jabber client I'm using.
Then its supposed to "processUntil" a message is received (afaik) and if a message is received send another timestamp. Well, this bit is the bit that doesn't work.
I have no prior knowledge of XMPP servers or XMPPHP, so all help, however basic, wouldn't go unappreciated! :)
Thanks.
I fought with this for a while. Turns out that you have to announce your presence when you connect. I extracted this from the cli_longrun_example.php and put it after my $conn->connect() and $conn->processUntil('session_start') calls:
$conn->presence($status='Controller available.');
you can recive first message in your jabber client. with
$conn->message('person#server.com', mktime());
but then you are recive message from server with
$payloads = $conn->processUntil('message');
but you cant recive message with that.
and scrpit cant load haead so you cant receive another message. i have a same problem. you can use jaxl for that.