uniapp连接php,thinkphp5 对接手机uni-app的unipush推送(个推)
PHP对接unipush(推送)也是要按照个推的文档进行对接(其实unipush用的服务就是个推的,前者应该是和个推谈了合作,个推的厂商推送服务免费开放给uni的开发人员)
放入项目的extend文件夹(第三方扩展),并在getui的demo文件同级创建一个GeTui.php文件,用来实例化并调用,class代码贴在图片后面
因为需求问题,我项目只有用到单用户的推送,所以这边只贴我测试并通过的代码,没有多推的示例
这里需要注意的是:消息内容决定了系统的通知栏的通知等级,如果通知栏一直没有消息,可以去查一下各自手机厂商的消息等级,对应修改文字
class GeTui
{
private $host = 'http://sdk.open.api.igexin.com/apiex.htm';
//测试
private $appkey = '';
private $appid = '';
private $mastersecret = '';
private function init($appid=null,$appkey=null,$mastersecret=null)
{
$this->appid = !empty($appid) ? $appid : "fdVf****aUq4";
$this->appkey = !empty($appkey) ? $appkey : "fdVf****RUq4";
$this->mastersecret = !empty($mastersecret) ? $mastersecret : "39pj****VtQ5";
$this->host = "http://sdk.open.api.igexin.com/apiex.htm";
}
public function __construct($appid=null,$appkey=null,$mastersecret=null)
{
$this->init($appid,$appkey,$mastersecret);
$this->__loader();
}
private function __loader()
{
require_once(dirname(__FILE__) . '/' . 'IGt.Push.php');
require_once(dirname(__FILE__) . '/' . 'igetui/IGt.AppMessage.php');
require_once(dirname(__FILE__) . '/' . 'igetui/IGt.TagMessage.php');
require_once(dirname(__FILE__) . '/' . 'igetui/IGt.APNPayload.php');
require_once(dirname(__FILE__) . '/' . 'igetui/template/IGt.BaseTemplate.php');
require_once(dirname(__FILE__) . '/' . 'IGt.Batch.php');
require_once(dirname(__FILE__) . '/' . 'igetui/utils/AppConditions.php');
require_once(dirname(__FILE__) . '/' . 'igetui/template/notify/IGt.Notify.php');
require_once(dirname(__FILE__) . '/' . 'igetui/IGt.MultiMedia.php');
require_once(dirname(__FILE__) . '/' . 'payload/VOIPPayload.php');
}
//单推
function pushMessageToSingle($cid){
$igt = new \IGeTui($this->host,$this->appkey,$this->mastersecret);
// 透传消息模板
$template = $this->IGtTransmissionTemplateDemo();
//定义"SingleMessage"
$message = new \IGtSingleMessage();
$message->set_isOffline(false);//是否离线
$message->set_offlineExpireTime(3600*12*1000);//离线时间
$message->set_data($template);//设置推送消息类型
$message->set_PushNetWorkType(0);//设置是否根据WIFI推送消息,2为4G/3G/2G,1为wifi推送,0为不限制推送
//接收方
$target = new \IGtTarget();
$target->set_appId($this->appid);
$target->set_clientId($cid);
try {
$rep = $igt->pushMessageToSingle($message, $target);
var_dump($rep);
echo ("
");
}catch(RequestException $e){
$requstId =e.getRequestId();
//失败时重发
$rep = $igt->pushMessageToSingle($message, $target,$requstId);
var_dump($rep);
echo ("
");
}
}
//透传消息模板
public function IGtTransmissionTemplateDemo(){
$listId = [
'title' => '通知',
'content' => '你有一条新消息',
'payload' => [
"push"=> "inner",
"event"=> "warning",
"silent"=> false,
]
];
$mes = [
'title' => '通知',
'content' => '你有一条新消息',
'payload' => [
"push"=> "inner",
"event"=> "warning",
"silent"=> false,
"data"=> ""
]
];
$template = new \IGtTransmissionTemplate();
$template->set_appId($this -> appid);//应用appid
$template->set_appkey($this->appkey);//应用appkey
$template->set_transmissionType(1);//透传消息类型
$template->set_transmissionContent(json_encode($listId));//透传内容
//注意:如果设备离线(安卓),一定要设置厂商推送,不然接收不到推送(比如华为、小米等等)
//S.title=的值为推送消息标题,对应5+ API中PushMessage对象的title属性值;
//S.content=的值为推送消息内容,对应5+ API中PushMessage对象的content属性值;
//S.payload=的值为推送消息的数据,对应5+ API中PushMessage对象的payload属性值;
$intent = 'intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=此处为打包APP的包名/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=标题;S.content=内容;S.payload=数据;end';
$notify = new \IGtNotify();
$notify->set_title('通知');
$notify->set_content('你有一条新消息');
$notify->set_intent($intent);
$notify->set_type(NotifyInfo_type::_intent);
$template->set3rdNotifyInfo($notify);
//下面这些是苹果需要设置的,只要是ios系统的,都要设置这个,不然离线收不到
//APN高级推送
$alertmsg=new \DictionaryAlertMsg();
$alertmsg->body=$mes['content'];
$alertmsg->actionLocKey="查看";
$alertmsg->locKey=$listId['content'];
$alertmsg->locArgs=array("locargs");
$alertmsg->launchImage="launchimage";
// IOS8.2 支持
$alertmsg->title=$mes['title'];
$alertmsg->titleLocKey="测试";
$alertmsg->titleLocArgs=array("TitleLocArg");
$apn = new \IGtAPNPayload();
$apn->alertMsg=$alertmsg;
$apn->badge=0;
$apn->sound="";
$apn->add_customMsg("payload","payload");
$apn->contentAvailable=0;
$apn->category="ACTIONABLE";
$template->set_apnInfo($apn);
return $template;
}
}
调用
//个推消息推送
public function pushChat($cid=null, $type=null)
{
if(empty($cid)){
die;
}
import('getui.GeTui', EXTEND_PATH,".php");
$getui = new \GeTui($appid,$appkey,$mastersecret);
//单发测试 $cid 客户端id 前端获取
$getui->pushMessageToSingle($cid);
}
来源:https://www.cnblogs.com/j-jian/p/13061118.html
uniapp连接php,thinkphp5 对接手机uni-app的unipush推送(个推)相关推荐
- uni app对接php,thinkphp5 对接手机uni-app的unipush推送(个推)
class GeTui { private $host = 'http://sdk.open.api.igexin.com/apiex.htm'; //测试 private $appkey = ''; ...
- 小米手机退出app后收不到极光推送消息
场景: 进入app,发送消息,消息正常接收,连续2次back退出app后,收不到极光推送消息,pushService进程存在,app主进程被杀. 华为,魅族都能在相同条件下接收消息,**小米手机 收不 ...
- App系列之Push推送---实现推送方式解决方案
本文介绍在Android中实现推送方式的基础知识及相关解决方案.推送功能在手机开发中应用的场景是越来起来了,不说别的,就我们手机上的新闻客户端就时不j时的推送过来新的消息,很方便的阅读最新的新闻信息. ...
- 手机 服务器 推送消息推送消息,推送信息到手机的pushover使用方法及sample code
今天给大家介绍一个好东西,用了两年多了,一直没时间给大家推荐.pushover,移动端的信息推送服务API,包括使用.设置以及API实现. 用途 在关键节点放上推送(比如用户注册.举报.评论,系统检测 ...
- uniapp push 推送 个推 安卓Android添加Google 推送服务 FCM 离线推送 Dcloud
项目甲方在国外需要用到google推送服务,看了文档中说明,如果安卓要实现离线推送,需要通过厂商来解决 在google开发者后台添加项目,获取Legancy server key 获取google-s ...
- php mui消息推送,个推透传消息,触发receive后创建本地推送,点击状态栏消息可以打开APP触发不了click事件...
大佬们帮忙看看代码 //消息推送 mui.plusReady(function() { // 监听点击消息事件 plus.push.addEventListener( "click" ...
- uniapp之unipush安卓app信息推送
第一步,uniapp 官网查找推送 uni-app官网 介绍业务.开通流程,请务必仔细阅读 UniPush使用指南 - DCloud问答 第二步,unipush相关链接 开通的unipush是封装了个 ...
- uni app push 集成小米
重新设置 厂商推送设置 后,需要重新制作自定义基座,包括添加和修改 厂商推送设置 用自定义的基座打包好测试包,安装到手机上. 先测试小米后台是否能推送成功 推送后,手机就能接受到消息了 再看java代 ...
- uni-app unipush + 个推 实现推送服务全过程(干货)
背景 说明文档这个事情官方应该提供出来,可惜官方觉得是多余的,免费的东西凭啥给你做好.于是我在这里叙述一下实现消息通知推送的步骤. uni-app官方文档入口 https://uniapp.dclou ...
最新文章
- 小型职工工作量c语言,计算机c语言职工工作量统计系统.doc
- Zookeeper ZAB协议原理浅析
- 声音对比处理_厨房垃圾处理器 | 厨余垃圾分类的正确打开姿势
- Java 基本数据类型
- 让mysql返回的结果按照传入的id的顺序排序
- QT与openCV,与PCL结合!
- 2020新时尚之都指数报告
- 使用.htaccess文件为站点文件夹设置密码保护
- linux单网卡多拨Adsl,秋明 | 边缘计算-使用多adsl账号做捆绑上网[单网卡多账号多拨]...
- 习题:Dual Matrices(思路题/分治)
- java 对象嵌套_java如何把嵌套的对象装入集合?
- Android Listview设置每条信息的间距
- 同时启动两个android模拟器
- Android9输入法留白配置,拇指于键盘间游离 2015安卓输入法横评
- Linux之ubuntu离线安装软件包
- java 中PATH, -classpath, -Djava.library.path 的功能和区别
- FFmpeg数据结构AVFrame
- Jquery字符UrlEncode 编码、解码 --C#UrlEncode
- java 外文翻译_计算机 java 外文翻译 外文文献 英文文献
- Microsoft Excel 直方图