// $moSubscription->notifyURL = ...; $moSubscription->callbackData = 'any string'; $moSubscription->criteria = $criteria; $moSubscription->destinationAddress = MO_NUMBER; // This step usually will be needed only once per application: $createSubscriptionsResult = $smsClient->subscribeToInboundMessagesNotifications($moSubscription); // Now that the subscription is saved, the application will store messages starting with $criteria and sent to $moNumber for you // Let's try to send a message ourselves (usually this will be done by the end user from a real mobile phone): $smsMessage = new SMSRequest(); $smsMessage->senderAddress = '38598123456'; $smsMessage->address = $moSubscription->destinationAddress; $smsMessage->message = $criteria . ' Some message'; $smsMessageSendResult = $smsClient->sendSMS($smsMessage); // Sleep a few seconds just to be sure the message is processed: echo 'Waiting for the message to be processed...'; sleep(20); // Note: the time lag depends on a lot of things. Usually a few seconds will be OK, but it depends on the // client roaming status, Newtorks, etc. // OK, let's see if there are any SMS message waiting for us (of course there is one!): $receivedInboundMessages = $smsClient->retrieveInboundMessages(100); echo 'Found ', sizeof($receivedInboundMessages->inboundSMSMessage), ' messages', "\n"; foreach ($receivedInboundMessages->inboundSMSMessage as $inboundMessage) { echo $inboundMessage . "\n"; echo 'destinationAddress:', $inboundMessage->destinationAddress, "\n"; echo 'message:', $inboundMessage->message, "\n"; echo 'senderAddress:', $inboundMessage->senderAddress, "\n"; } // Let's try once again. If nobody else sent any messages to our number, this one should be empty: $receivedInboundMessages = $smsClient->retrieveInboundMessages(100); echo 'Found ', sizeof($receivedInboundMessages->inboundSMSMessage), ' messages', "\n"; Logs::printLogs();
<?php require_once '../oneapi/client.php'; $smsClient = new SmsClient(USERNAME, PASSWORD); $smsClient->login(); # example:retrieve-inbound-messages $inboundMessages = $smsClient->retrieveInboundMessages(); foreach ($inboundMessages->inboundSMSMessage as $message) { echo $message->dateTime; echo $message->destinationAddress; echo $message->messageId; echo $message->message; echo $message->resourceURL; echo $message->senderAddress; } # ----------------------------------------------------------------------------------------------------
<?php require_once 'app.php'; $smsClient = new SmsClient(USERNAME, PASSWORD); $result = $smsClient->retrieveInboundMessages(); $result->inboundSMSMessage; ?> <html> <head> <title>Inbound messages</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <h1>Inbound messages</h1> <?php if ($result->inboundSMSMessage) { ?> <ul> <?php foreach ($result->inboundSMSMessage as $message) { ?> <li/> Message <b><?php echo $message->message; ?> </b> from <b><?php echo $message->senderAddress; ?> </b>. <?php } ?>