PHP语言的 OPPO通道消息推送

1. 首先是外层封装的类

// 添加用到的引用
use oppoPush\oppoPush;

class OppoNoti
{
    function __construct()
    {
        $this->appKey = '**申请的appKey**';
        $this->mstSecret = ''**申请的Secret**'';
    }

    //单播消息
    public function sendAndroidUnicast($device_tokens,$param=[])
    {
        try {
            //引入类
            Vendor('oppopush.autoload');

            $client = new oppoPush($this->appKey, $this->mstSecret); // AppKey 与 MasterSecret(非 AppSecret)

            $extend = [
                'push_id' => $param['push_id'],
                'title' => $param['title'],
       
            ];

            $authToken = $client->getAuthToken(); // 有效期24小时
            $client->setTitle($param['title']);
            $client->setContent($param['sub']);
            $client->setAuthToken($authToken);
            $client->getAuthTokenExpiresTime();           // 获取 auth_token 过期时间
            $client->setIntent('com.***.****.oppopush');           // 打开应用内页的 intent action,这需要填写自己的应用定义
            //$client->setActionUrl('http://www.xxx.com');  // 打开网页
            $client->setActionParameters(json_encode($extend));   // 打开应用内页或网页时传递的参数 (数组或json类型)

            $client->addRegistrationId($device_tokens);   // 添加需要发送设备的 registration_id, 最多 1000 个
            //$client->broadcastByRegId();                 // registration_id 推送

            $result = $client->broadcastByRegId();  // registration_id 推送

            if (0 == $result['code']) {
                return true;
            } else {
                return false;
            }
        } catch (Exception $e) {
            print("Caught exception: " . $e->getMessage());
        }
    }
}

 

2. 然后是oppo的核心发送SDK,文件结构如下,从网盘上下载了直接引入即可

下载地址:链接:https://pan.baidu.com/s/1RnnpFMwQLHEGg36wWu21gA  密码:b1h0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值