- 引用composer包
composer require wushunyi/aliyun-sdk-mns
- 代码引用composer自动加载工具
require_once "vendor/autoload.php";
- 实例化客户端
use AliyunMNS\Client;
$client = new Client($endPoint, $accessId, $accessKey);
-
发送消息
- 主题消息
use AliyunMNS\Client; use AliyunMNS\Requests\PublishMessageRequest; $endPoint = ''; $accessId = ''; $accessKey = ''; $topicName = ''; $client = new Client($endPoint, $accessId, $accessKey); $topic = $client->getTopicRef($topicName);//获取Topic地址 $messageBody = 'test message'; //消息内容 $messageTag = 'pay_success'; //消息标签 $request = new PublishMessageRequest($messageBody,$messageTag); $res = $topic->publishMessage($request); $res->isSucceed();
- 队列消息
use AliyunMNS\Client; use AliyunMNS\Requests\PublishMessageRequest; $endPoint = ''; $accessId = ''; $accessKey = ''; $queueName = ''; $client = new Client($endPoint, $accessId, $accessKey); $topic = $client->getQueueRef($queueName);//获取Topic地址 $messageBody = 'test message'; //消息内容 $request = new PublishMessageRequest($messageBody); $res = $topic->publishMessage($request); $res->isSucceed();
-
MNS SDK for PHP
Please refer to http://www.aliyun.com/product/mns and https://docs.aliyun.com/?spm=5176.7393424.9.6.5ki1hv#/pub/mns/api_reference/intro&intro for more API details. -
Samples
You must fulfill the AccessId/AccessKey/AccountID in the example before running.