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元
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号