uni app对接php,thinkphp5 对接手机uni-app的unipush推送(个推)

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;

}

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
随着智能手机的快速普及,移动应用对于人们的生活和工作越来越重要。而uni-appthinkphp是目前比较流行的移动应用开发技术。本文将深入探讨如何用uni-appthinkphp实战社区交友类app和小程序的开发。 首先,uni-app是一种跨平台的开发技术,可以通过一套代码编写不同平台的应用程序,包括iOS、Android和Web应用。相比于传统的移动应用开发,uni-app可以更加高效和快速地开发应用程序,同时还具有比较好的用户体验和可扩展性。在实战社区交友类app和小程序的开发中,使用uni-app将更快速地开发出各个平台的应用,省去大量的开发时间和精力。 其次,thinkphp是一种PHP Web应用开发框架,具有高度模块化、可重用性、松耦合等特点,适用于快速开发和快速迭代的Web应用程序。在实战社区交友类app和小程序的开发中,thinkphp可以实现灵活的后台管理系统,为用户提供更加高效和便捷的交友体验,同时还能满足各种需求的排列组合。 最后,社区交友类app和小程序需要注意一些开发难点,例如安全性和用户隐私保护,以及用户体验的提升。在使用uni-appthinkphp开发时,需要注重这些方面,并进行细致的测试和优化,保证应用程序在各种细节场合下都能够得到良好的体验。 综上所述,使用uni-appthinkphp实战社区交友类app和小程序的开发,能够更加高效和快速地实现我们的开发需求,同时也能够提高我们的开发效率和质量,是值得广的新技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值