日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

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

發(fā)布時間:2024/9/19 php 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 uniapp连接php,thinkphp5 对接手机uni-app的unipush推送(个推) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

PHP對接unipush(推送)也是要按照個推的文檔進行對接(其實unipush用的服務就是個推的,前者應該是和個推談了合作,個推的廠商推送服務免費開放給uni的開發(fā)人員)

放入項目的extend文件夾(第三方擴展),并在getui的demo文件同級創(chuàng)建一個GeTui.php文件,用來實例化并調用,class代碼貼在圖片后面

因為需求問題,我項目只有用到單用戶的推送,所以這邊只貼我測試并通過的代碼,沒有多推的示例

這里需要注意的是:消息內容決定了系統(tǒng)的通知欄的通知等級,如果通知欄一直沒有消息,可以去查一下各自手機廠商的消息等級,對應修改文字

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);//設置是否根據(jù)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();

//失敗時重發(fā)

$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=的值為推送消息的數(shù)據(jù),對應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=數(shù)據(jù);end';

$notify = new \IGtNotify();

$notify->set_title('通知');

$notify->set_content('你有一條新消息');

$notify->set_intent($intent);

$notify->set_type(NotifyInfo_type::_intent);

$template->set3rdNotifyInfo($notify);

//下面這些是蘋果需要設置的,只要是ios系統(tǒng)的,都要設置這個,不然離線收不到

//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);

//單發(fā)測試 $cid 客戶端id 前端獲取

$getui->pushMessageToSingle($cid);

}

來源:https://www.cnblogs.com/j-jian/p/13061118.html

總結

以上是生活随笔為你收集整理的uniapp连接php,thinkphp5 对接手机uni-app的unipush推送(个推)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。