极光推送简单推送配置

Posted pcyy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了极光推送简单推送配置相关的知识,希望对你有一定的参考价值。

0、首先去极光申请app应用,免费的!

1、composer引入极光sdk。PS:尽量使用composer,不然可能会有各种坑爹的不能自动加载问题等...

2、引入模块类

3、直接撸代码

protected $pushConfig=[
        ‘AppKey‘=>‘fbbcd8bdd8ce2276f2da04a9‘,
        ‘Secret‘=>‘64f673ce5c33016ec0e4ca49‘
    ];
/**极光推送
     * @param string $obj 推送对象手机号
     * @param string $pushInfo 推送信息
     */
    public function push($obj=‘‘,$pushInfo=‘‘)
    {
        $jpush=new Client($this->pushConfig[‘AppKey‘],$this->pushConfig[‘Secret‘]);
        $pusher = $jpush->push();
        $pusher->setPlatform(‘all‘);//平台设置
        $pusher->addAlias(‘u‘.$obj);//别名推送,跟app约定好格式  ps:官方还提供了标签推送,集体推送等功能,具体按需求查看文档!
        $pusher->setNotificationAlert($pushInfo);
        try {
            $pusher->send();
        } catch (JPushExceptionsJPushException $e) {
            // try something else here
           echo $e;
        }
    }

 

以上是关于极光推送简单推送配置的主要内容,如果未能解决你的问题,请参考以下文章