这里因为业务需要使用推送功能 uni 里面前端集成了个推 所以选择了个推来做推送.

个推的官方文档地址: http://docs.getui.com/getui/server/php/start/

在个推官方没有找到 composer 包

只能手动的将 sdk 放到了项目中

sdk下载地址:http://www.getui.com/download/docs/getui/server/GETUI_PHP_SDK_4.1.0.0.zip (官方文档里有建议从官方文档下载)

这里的用的是tp5框架 laravel yii 和 ci 中需要用到的朋友 可以根据各自的框架调整下 自行加载到这个类调整下配置读取即可

下载解压 把它放到 项目根路径\extend 文件夹内即可

这里 个推的demo 都是 以函数的方式 呈现的 这里我自己将他整理成了一个类 GeTui.php

<?php
namespace getui; class GeTui
{
private $host = 'http://sdk.open.api.igexin.com/apiex.htm';
//测试
private $appkey = '';
private $appid = '';
private $mastersecret = ''; private function init()
{
// header("Content-Type: text/html; charset=utf-8");
$this->appid = config('getui.appid');
$this->appkey = config('getui.appkey');
$this->mastersecret = config('getui.mastersecret');
$this->host = config('getui.host'); } public function __construct()
{
$this->init();
$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');
} //服务端推送接口,支持三个接口推送
//1.PushMessageToSingle接口:支持对单个用户进行推送
//2.PushMessageToList接口:支持对多个用户进行推送,建议为50个用户
//3.pushMessageToApp接口:对单个应用下的所有用户进行推送,可根据省份,标签,机型过滤推送
//单推接口案例
function pushMessageToSingle($cid){
$igt = new \IGeTui($this->host,$this->appkey,$this->mastersecret); //消息模版:
// 通知栏消息模板
$template = $this->IGtNotificationTemplateDemo();
// 穿透消息模板
// $template = $this->IGtTransmissionTemplateDemo(); //定义"SingleMessage"
$message = new \IGtSingleMessage(); $message->set_isOffline(true);//是否离线
$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);
// $target->set_alias(Alias); try {
$rep = $igt->pushMessageToSingle($message, $target);
var_dump($rep);
echo ("<br><br>"); }catch(RequestException $e){
$requstId =e.getRequestId();
//失败时重发
$rep = $igt->pushMessageToSingle($message, $target,$requstId);
var_dump($rep);
echo ("<br><br>");
}
} //穿透消息模板
public function IGtTransmissionTemplateDemo(){
$template = new \IGtTransmissionTemplate();
$template->set_appId($this->appid); //应用appid
$template->set_appkey($this->appkey); //应用appkey
//透传消息类型
$template->set_transmissionType(2);
$payload = [
'title' => '测试',
'content' => '1111',
'payload' => '测试参数'
];
//透传内容
$template->set_transmissionContent(json_encode($payload));
// $template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息
//这是老方法,新方法参见iOS模板说明(PHP)*/
//$template->set_pushInfo("actionLocKey","badge","message",
//"sound","payload","locKey","locArgs","launchImage"); // APN高级推送
// $apn = new \IGtAPNPayload();
// $alertmsg=new \DictionaryAlertMsg();
// $alertmsg->body="body";
// $alertmsg->actionLocKey="ActionLockey";
// $alertmsg->locKey="LocKey";
// $alertmsg->locArgs=array("locargs");
// $alertmsg->launchImage="launchimage";
return $template;
} //通知栏消息 (通知栏显示 点击启动应用)
function IGtNotificationTemplateDemo(){
$template = new \IGtNotificationTemplate();
$template->set_appId($this->appid); //应用appid
$template->set_appkey($this->appkey); //应用appkey
$template->set_transmissionType(1);//透传消息类型
$template->set_transmissionContent("测试离线");//透传内容
$template->set_title("呵呵");//通知栏标题
$template->set_text("呵呵最新版点击下载");//通知栏内容
$template->set_logo("http://wwww.igetui.com/logo.png");//通知栏logo
$template->set_isRing(true);//是否响铃
$template->set_isVibrate(true);//是否震动
$template->set_isClearable(true);//通知栏是否可清除
//$template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息
return $template;
} //群推接口案例
public function pushMessageToApp(){
$igt = new \IGeTui($this->host,$this->appkey,$this->mastersecret); $template = $this->IGtNotificationTemplateDemo();
//个推信息体
//基于应用消息体
$message = new \IGtAppMessage();
$message->set_isOffline(true);
$message->set_offlineExpireTime(10 * 60 * 1000);//离线时间单位为毫秒,例,两个小时离线为3600*1000*2
$message->set_data($template);
// $message->setPushTime("201808011537");
$appIdList=array($this->appid);
$phoneTypeList=array('ANDROID');
$provinceList=array('上海');
$tagList=array('中文');
$age = array("0000", "0010"); //推送条件
// $cdt = new \AppConditions();
// 手机类型
// $cdt->addCondition(\AppConditions::PHONE_TYPE, $phoneTypeList);
// 地区
// $cdt->addCondition(\AppConditions::REGION, $provinceList);
// 标签
// $cdt->addCondition(\AppConditions::TAG, $tagList);
// 年龄?
// $cdt->addCondition("age", $age);
// $message->set_conditions($cdt); $message->set_appIdList($appIdList); $rep = $igt->pushMessageToApp($message); var_dump($rep);
echo ("<br><br>");
} //通知栏显示 点击跳转url
function IGtLinkTemplateDemo(){
$template = new \IGtLinkTemplate();
$template ->set_appId($this->appid);//应用appid
$template ->set_appkey($this->appkey);//应用appkey
$template ->set_title("测试群发消息");//通知栏标题
$template ->set_text("点击就送66个老铁666");//通知栏内容
$template ->set_logo("http://wwww.igetui.com/logo.png");//通知栏logo
$template ->set_isRing(true);//是否响铃
$template ->set_isVibrate(true);//是否震动
$template ->set_isClearable(true);//通知栏是否可清除
$template ->set_url("http://www.igetui.com/");//打开连接地址
//$template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息
return $template;
} }

将他放到 demo.php 同级目录

个推的相关配置 我是写在了

tp5项目\application\extra\getui.php

可以看到我在 GeTui.php 这个类文件里 初始化的时候 进行了读取 和 加载相关文件

<?php

return [
// +---------------------------------
// 个推相关配置
// +--------------------------------- //AppID:由IGetui管理页面生成,是您的应用与SDK通信的标识之一,每个应用都对应一个唯一的AppID。
'appid' => 'XXX', //AppSecret:第三方客户端个推集成鉴权码,用于验证第三方合法性。在客户端集成SDK时需要提供。
'AppSecret' => 'XXX', //AppKey:预先分配的第三方应用对应的Key,是您的应用与SDK通信的标识之一。
'appkey' => 'XXX', //MasterSecret:个推服务端API鉴权码,用于验证调用方合法性。在调用个推服务端API时需要提供。(请妥善保管,避免通道被盗用)。
'mastersecret' => "XX", //
'host' => "http://sdk.open.api.igexin.com/apiex.htm", ];

将其替换成自己的即可

后面在需要调用的地方使用

    //个推案例接口
public function getui()
{
//实例化之前写的类
$getui = new \getui\GeTui();
//单发测试 $cid 客户端id 前端获取
// $getui->pushMessageToSingle($cid);
// 群发测试
$getui->pushMessageToApp();
// dump($getui);die;
}

下载个推注册时 生成的app 即可后端调试

到了这里基本就可以 开心的测试接口了

//这个是我案例中 单发接口调用的模板 群发我这里用的也是这个模板
//相关的其他模板可以在demo 中 找一下 根据自己需求调整
$template = $this->IGtNotificationTemplateDemo();

这里的是生成了一个模板 影响到 消息推送到后的 下一步动作 根据自己的业务需求编辑和选择即可

这里放其他使用其他模板的案例

//通知栏显示 点击跳转url
$template = $this->IGtLinkTemplateDemo()

安卓 推送通知 和 穿透消息都能接收到

ios 只能接收到 穿透消息

tp5 整合 个推的更多相关文章

  1. TP5整合 WorkerMan 以及 GatewayWorker

    TP5整合GatewayWorker Windows版安装 a)使用composer create-project topthink/think testTG,来安装thinkphp5. b)进入t ...

  2. Java整合极光推送 ( 简单 )

    Java 整合极光推送官方文档:https://github.com/jpush/jpush-api-java-client 这里记录一下简单的使用步骤:创建一个普通的 Maven 工程然后添加依赖 ...

  3. SpringMVC整合极光推送报错ClassNotFound

    问题: 今天在做后台和极光整合的过程中,将极光部分代码整合到Dao层,在启动项目的过程中总是报错,classNotFund cn/jpush/api/push/xxxx 极光官方文档: http:// ...

  4. Thinkphp5.0整合个推例子

    最近做一个后台发送消息推送到app(android和ios)的功能,该功能采用的是个推接口,基于php的,我用TP5来实现这个推送流程.先看官方demo吧.可以先参考官方给到的例子来看http://d ...

  5. ThinkPHP框架整合极光推送DEMO

    极光推送(JPush)是独立的第三方云推送平台,致力于为全球移动应用开发者提供专业.高效的移动消息推送服务. 本篇博文讲述如何在将极光推送DEMO整合到ThinkPHP框架中,我使用的是极光推送PHP ...

  6. Ionic5整合极光推送JPush ( 简单 )

    项目初始化 1. 安装项目依赖: # 安装cordova插件 ionic cordova plugin add jpush-phonegap-plugin --variable APP_KEY=&qu ...

  7. TP5整合的阿里云短信接口

    现阶段,短信的应用主要就是用来验证下手机号是不是正常的手机号.只要涉及到用户手机号的问题的时候,都会做短信验证码来验证下改手机号是否是正常手机号.接下来就是操作步骤. 首先要在阿里云账号上开通短信功能 ...

  8. TP5整合的导出Excel中没有图片和包含图片两种方法

    之前做了个项目需要导出Excel文件 ,我在网上查了许多资料,最后终于搞定了 ,现在把代码贴到下面 先导入库文件:将文件phpoffice放在根目录的vendor下.获取文件点击:链接:https:/ ...

  9. 基于TP5使用Websocket框架之GatewayWorker开发电商平台买家与卖家实时通讯

    https://www.cnblogs.com/wt645631686/p/7366924.html 前段时间公司提了一个新的需求,在商品的详情页要实现站内买家和商品卖家实时通讯的功能以方便沟通促成交 ...

随机推荐

  1. Consul1-window安装consul

    转自  https://blog.csdn.net/j903829182/article/details/80960802 consul下载地址: https://www.consul.io/down ...

  2. 制作OpenStack使用的windows镜像

    1 安装vmware14 2 创建ubuntu-desktop-16.04虚拟机 选择自定义安装 选择ubuntu-16.04-desktop.iso 内存要大于2G,推荐4G. 磁盘要大于50G 关 ...

  3. 浅谈 JSP & Servlet

    body { text-align: center; } div.develon { background-color: #cccccc; font-size: 20px; } 背景 相信大家都见过这 ...

  4. 爬虫框架Scrapy 之(一) --- scrapy初识

    Scrapy框架简介 scrapy是基于Twisted的一个第三方爬虫框架,许多功能已经被封装好,方便提取结构性的数据.其可以应用在数据挖掘,信息处理等方面.提供了许多的爬虫的基类,帮我们更简便使用爬 ...

  5. java连接jdbc

    package com.dy.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLE ...

  6. python基础1之 由来、种类、优缺点、安装环境

    python基础1之由来.种类.优缺点.安装环境 一.前世今生 Python的创始人是吉多·范罗苏姆(Guido van Rossum),在1989年开发.今年最新的编程语言排行榜中,python名列 ...

  7. MATLAB cftool工具数据拟合结果好坏判断

    SSE和RMSE比较小 拟合度R接近于1较好 * 统计参数模型的拟合优度 1.误差平方和(SSE) 2. R-Square(复相关系数或复测定系数) 3. Adjusted R-Square(调整自由 ...

  8. Standford NLP study

    Homepage https://stanfordnlp.github.io/CoreNLP/index.html Source Code: https://github.com/stanfordnl ...

  9. 2018-2019-2 网络对抗技术 20165325 Exp3 免杀原理与实践

    2018-2019-2 网络对抗技术 20165325 Exp3 免杀原理与实践 实验内容(概要) 一.正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasion,自己 ...

  10. day08 文件操作

    1.三种字符串: (1)u'' 普通字符串 ---> u'abc' ---> 默认的文本方式,以字符作为文本的输出方式 (2)b'' 二进制字符串 ---> b'ASCII码' -- ...