guanhui07/aliyun-sdk-mns

Aliyun MNS PHP SDK 阿里云官方 MNS composer包

v1.3.5.5 2017-11-21 09:36 UTC

This package is auto-updated.

Last update: 2024-11-19 10:28:00 UTC


README

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核心代码来自阿里云官方