全部产品
Search
文档中心

PHP

更新时间: 2019-11-26

入参列表

参数名称 参数类型 必填与否 样例取值 参数说明
MessageType String 必填 SmsReport 有一种消息类型: SmsReport。
QueueName String 必填 Alicom-Queue-xxxxxx-SmsReport 阿里巴巴提供的消息队列名称,在短信控制台——系统设置可以查看到。

出参列表

出参名称 出参类型 样例取值 参数说明
MessageId String 10080303003003 短信的发送ID
To String 452220121 短信的发送号码
Status Number 3 短信的发送状态: 1 (Submitted), 2 (Failed), and 3 (Delivered).
ErrorCode String success 短信发送返回的错误码
ErrorDescription String success 短信发送返回的错误码详细描述
SendDate String Mon, 24 Dec 2018 16:58:22 +0800 短信转发给运营商的时间
ReceiveDate String Mon, 24 Dec 2018 16:58:22 +0800 短信收到运营商回执的时间
NumberDetail String 号码的详细属性
└Country String Hongkong, China 号码所属国家
└Region String HongKong Number Region
└Carrier String CMI 号码所属的运营商网络

技术对接步骤

1.SDK下载:点击查看下载地址

2.编写样例程序

需要依赖OpenAPI PHP Client包和OpenAPI PHP SDK包

调用接口时,请注意:

  • regionId必须为ap-southeast-1,请勿修改。
  • product必须为Dybaseapi,请勿修改。
  • version必须为2018-05-01,请勿修改。
  • host必须为dybaseapi.ap-southeast-1.aliyuncs.com,请勿修改。
  • mnsClient初始化时,第一个参数必须为http://1493622401794734.mns.ap-southeast-1.aliyuncs.com, 请勿修改。
  1. <?php
  2. use AlibabaCloud\Client\AlibabaCloud;
  3. use AlibabaCloud\Client\Exception\ClientException;
  4. use AlibabaCloud\Client\Exception\ServerException;
  5. use AlibabaCloud\Dybaseapi\MNS\Requests\BatchReceiveMessage;
  6. use AlibabaCloud\Dybaseapi\MNS\Requests\BatchDeleteMessage;
  7. AlibabaCloud::accessKeyClient('<AccessKeyId>', '<AccessSecret>')
  8. ->regionId('ap-southeast-1')
  9. ->asGlobalClient();
  10. // Message Quenue Name, you can get it from SMS console, like:Alicom-Queue-xxxxxx-SmsReport
  11. $queueName = '<QueueName>';
  12. // Message Type, smsReport
  13. $messageType = '<MessageType>';
  14. $response = null;
  15. $token = null;
  16. $i = 0;
  17. do {
  18. try {
  19. if (null == $token || strtotime($token['ExpireTime']) - time() > 2 * 60) {
  20. $response = AlibabaCloud::rpcRequest()
  21. ->product('Dybaseapi')
  22. ->version('2018-05-01')
  23. ->action('QueryTokenForMnsQueue')
  24. ->method('POST')
  25. ->host("sms-intl.ap-southeast-1.aliyuncs.com")
  26. ->options([
  27. 'query' => [
  28. 'MessageType' => $messageType,
  29. 'QueueName' => $queueName,
  30. ],
  31. ])
  32. ->request()
  33. ->toArray();
  34. }
  35. $token = $response['MessageTokenDTO'];
  36. $mnsClient = new \AlibabaCloud\Dybaseapi\MNS\MnsClient(
  37. "https://1493622401794734.mns.ap-southeast-1.aliyuncs.com",
  38. $token['AccessKeyId'],
  39. $token['AccessKeySecret'],
  40. $token['SecurityToken']
  41. );
  42. $mnsRequest = new BatchReceiveMessage(10, 5);
  43. $mnsRequest->setQueueName($queueName);
  44. $mnsResponse = $mnsClient->sendRequest($mnsRequest);
  45. $receiptHandles = Array();
  46. foreach ($mnsResponse->Message as $message) {
  47. // $receiptHandles[] = $message->ReceiptHandle;
  48. $messageBody = base64_decode($message->MessageBody);
  49. print_r($messageBody . "\n");
  50. }
  51. if (count($receiptHandles) > 0) {
  52. $deleteRequest = new BatchDeleteMessage($queueName, $receiptHandles);
  53. $mnsClient->sendRequest($deleteRequest);
  54. }
  55. } catch (ClientException $e) {
  56. echo $e->getErrorMessage() . PHP_EOL;
  57. } catch (ServerException $e) {
  58. if ($e->getCode() == 404) {
  59. $i++;
  60. }
  61. echo $e->getErrorMessage() . PHP_EOL;
  62. }
  63. } while ($i < 3);