/aliyun-sdk-mns

aliyun php sdk mns

Primary LanguagePHPMIT LicenseMIT

Aliyun MNS PHP SDK

Latest Stable Version Build Status Coverage Status Total Downloads Latest Unstable Version License

安装方法

  • 引用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();
    
    

SDK核心代码来自阿里云官方