首頁 >php教程 >php手册 >极光推送代码

极光推送代码

WBOY
WBOY原創
2016-06-07 11:34:131556瀏覽

ThinkPHP+Cordova+极光推送SDK+CoreThink实现非原生APP的消息推送机制,iOS需要走苹果的APNS服务,所以需要开发者账号,安卓是TCP长连接。
ThinkPHP+Cordova+极光推送SDK+CoreThink实现非原生APP的消息推送机制,iOS需要走苹果的APNS服务,所以需要开发者账号,安卓是TCP长连接。<?php <br /> // +----------------------------------------------------------------------<br> // | OpenCMF [ Simple Efficient Excellent ]<br> // +----------------------------------------------------------------------<br> // | Copyright (c) 2014 http://www.opencmf.cn All rights reserved.<br> // +----------------------------------------------------------------------<br> // | Author: jry <br> // +----------------------------------------------------------------------<br> namespace Addons\Jpush\Model;<br> use Think\Model;<br> use Home\Controller\AddonController;<br> require_once dirname(dirname(__FILE__)).'/JPush/JPush.php';<br> /**<br>  * 推送模型<br>  * @author jry <br>  */<br> class JpushModel {<br>     /**<br>      * 单个用户推送消息发送函数<br>      * @param string $push_data 推送消息结构<br>      * @return boolean<br>      * @author jry <br>      */<br>     function send($push_data) {<br>         $addon_config = \Common\Controller\Addon::getConfig('Jpush');<br>         if ($addon_config['status']) {<br>             // 获取用户对应的设备识别<br>             $push_token_list = D('User/MessagePush')->where(array('uid' => $push_data['to_uid']))->getField('token', true);<br>             if ($addon_config['production']) {<br>                 $production = true;<br>             } else {<br>                 $production = false;<br>             }<br>             if ($push_token_list) {<br>                 // 初始化<br>                 $client = new \JPush($addon_config['app_key'], $addon_config['master_secret']);<br>                 $result = null;<br>                 foreach ($push_token_list as $key => $push_token) {<br>                     if ($push_token) {<br>                         // 简单推送<br>                         $tmp = $client->push()<br>                             ->setPlatform('all')<br>                             ->addRegistrationId($push_token)<br>                             ->setNotificationAlert($push_data['title'])<br>                              ->addAndroidNotification($push_data['title'], $push_data['title'], 1, array("url" => $push_data['url']))<br>                             ->addIosNotification($push_data['title'], 'default', '+1', true, 'iOS category', array("url" => $push_data['url']))<br>                             ->setOptions($sendno = null, $time_to_live = null, $override_msg_id = null, $apns_production = $production, $big_push_duration = null)<br>                             ->send();<br> <br>                         if ($tmp) {<br>                             $result[$key] = $tmp;<br>                         }<br>                     }<br>                 }<br>                 if ($result) {<br>                     return $result;<br>                 } else {<br>                     $this->error = '推送失败';<br>                     return false;<br>                 }<br>             } else {<br>                 $this->error = '该用户无可推送设备';<br>                 return false;<br>             }<br>         } else {<br>             $this->error = '插件关闭';<br>             return false;<br>         }<br>     }<br> }极光推送代码极光推送代码极光推送代码极光推送代码极光推送代码极光推送代码极光推送代码极光推送代码

AD:真正免费,域名+虚机+企业邮箱=0元

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn