最近公司项目需要用到APP推送消息 ,找到比较详细的相关的资料跟大家分享`http://www.cnblogs.com/jiqing...

下面是我自己的推送内容,已经成功发送,首先在获取极光推送的key和secret,并下载相关sdk
1.推送的通知消息

protected static $client;

    public function __construct()
    {
        static::$client = new \JPush\Client(t($config['key']), t($config['secret']));
    }
    /**
    *给指定用户推送通知消息
    *$uis设备别名,由设备设置传给服务器端
    *$device设备类型
    *$result通知内容
    */
    public function pushMsgtoUser($uis, $device, $result)
    {
        $options = array(
            'audience' => $uis
        );
        $result = static::$client->push()->setPlatform($device)->addAllAudience()
            ->setNotificationAlert($result)->options($options)->send();
        return $result;
    }
    /**
    *给所有用户推送通知消息
    **$result通知内容
    */
    public function pushAllMsg($result)
    {
        $result = static::$client->push()->setPlatform('all')->addAllAudience()->setNotificationAlert($result)->send();
        return $result;
    }
     /**
    *给所有用户推送自定义消息
    **$result通知内容
    */
     public function pushMsg($result)
    {
        $options = array(
            'time_to_live' => 0,
        );
        $result = static::$client->push()->setPlatform('all')->addAllAudience()
            ->message($result)->options($options)->send();
        return $result;
    }
    /**
    *给所有用户(指定用户 需设定addRegistrationId并且去掉addAllAudience)推送自定义消息,弹出通知内容,点击消息进入这定页面
    **$result通知内容
    */
    public function pushMsgAddUrl($push_data, $push_token=null)
    {
        $tmp = static::$client->push()
            ->setPlatform("all")
            ->addAllAudience()
//            ->addRegistrationId($push_token)
            ->addAndroidNotification($push_data['content'], $push_data['title'], 1, array("controller" => $push_data['controller'], "method" => $push_data['method'], 'param' => $push_data['param']))
            ->addIosNotification($push_data['content'], '$push_data['title']', '+1', true, 'iOS category', array("controller" => $push_data['controller'], "method" => $push_data['method'], 'param' => $push_data['param']))
            ->send();
        return $tmp;
    }

沿蒤丶末路
29 声望3 粉丝

没有人能让你放弃梦想,你自己试试就会放弃了