一、配置
1、uni-push1.0文档
https://uniapp.dcloud.net.cn/unipush-v1.html
2、服务端推送文档
https://docs.getui.com/getui/server/rest_v2/push/
二、示例
//0:站内信,1:消息 $type = isset($type) ? $type : 0; $clickType = 'intent'; $payload = array('type' => 'switchTab', 'page' => $type == 1 ? '/pages/chat/index' : '/pages/message/index'); $url = ""; $data = array( 'cid' => $cid, 'title' => $title, 'content' => $content, 'clickType' => $clickType, 'payload_data' => json_encode($payload), 'url' => $url, 'intent_data' => "intent://io.dcloud.unipush/?#Intent;scheme=unipush;launchFlags=0x4000000;component=包名/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=".urlencode($title).";S.content=".urlencode($content).";S.payload=".json_encode($payload).";end" ); //记录推送数据 write_log(json_encode($data, JSON_UNESCAPED_UNICODE)); pushToSingleByCid($data); /** * 发送透传消息 * @param $data * @return bool */ function pushToSingleByCid($data){ //创建API,APPID等配置参考 环境要求 进行获取 $api = new GTClient(URL,APPKEY, APPID,MS); $setting = new GTSettings(); $setting->setTtl(3600000); //设置推送参数 $push = new GTPushRequest(); $push->setRequestId(time()); $message = new GTPushMessage(); $notify = new GTNotification(); $pushChannel = new GTPushChannel(); //配置推送条件 $push->setSettings($setting); //设置个推 $notify->setTitle($data['title']); $notify->setBody($data['content']); $notify->setChannelLevel(3); //点击通知后续动作,目前支持以下后续动作: //1、intent:打开应用内特定页面url:打开网页地址。2、payload:自定义消息内容启动应用。3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作 $notify->setClickType($data['clickType']); if ($data['clickType'] == 'payload') { $notify->setPayload($data['payload_data']); } if ($data['clickType'] == 'url') { $notify->setUrl($data['url']); } if ($data['clickType'] == 'intent') { $notify->setIntent($data['intent_data']); } $message->setNotification($notify); $push->setPushMessage($message); //设置安卓离线厂商通道推送消息体 $androidDTO = new GTAndroid(); $ups = new GTUps(); //消息分类配置 $ups->addOption("VV", "/category", "SUBSCRIPTION"); $ups->addOption("XM", "/extra.channel_id", "通道id"); $ups->addOption("OP", "/channel_id", "通道id"); $notification1 = new GTThirdNotification(); $notification1->setTitle($data['title']); $notification1->setBody($data['content']); $notification1->setClickType($data['clickType']); if ($data['clickType'] == 'payload') { $notification1->setPayload($data['payload_data']); } if ($data['clickType'] == 'url') { $notification1->setUrl($data['url']); } if ($data['clickType'] == 'intent') { $notification1->setIntent($data['intent_data']); } $ups->setNotification($notification1); $androidDTO->setUps($ups); $pushChannel->setAndroid($androidDTO); $push->setPushChannel($pushChannel); //推送苹果离线通知标题内容 $alert = new GTAlert(); $alert->setTitle($data['title']); $alert->setBody($data['content']); $aps = new GTAps(); //1表示静默推送(无通知栏消息),静默推送时不需要填写其他参数。 //苹果建议1小时最多推送3条静默消息 $aps->setContentAvailable(0); $aps->setSound("default"); $aps->setAlert($alert); $iosDto = new GTIos(); $iosDto->setAps($aps); $iosDto->setType("notify"); $iosDto->setAutoBadge(1); $pushChannel = new GTPushChannel(); $pushChannel->setIos($iosDto); $push->setCid($data['cid']); //处理返回结果 $result = $api->pushApi()->pushToSingleByCid($push); write_log(json_encode($result, JSON_UNESCAPED_UNICODE)); write_log('----'); var_dump($result); // if ($result['code'] == 0) { return true; } return false; }
标签:clickType,app,push1.0,notify,new,uni,推送,data,payload From: https://www.cnblogs.com/yang-2018/p/18090831