首页 > 其他分享 >Uni-app 之uni-push1.0服务端推送

Uni-app 之uni-push1.0服务端推送

时间:2024-03-23 10:11:24浏览次数:20  
标签:clickType app push1.0 notify new uni 推送 data payload

一、配置

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

相关文章

  • Uni-app 之APP打开小程序与分享小程序页面
    一、配置1、微信开放平台,创建移动应用与绑定小程序2、manifest.json,填写移动应用的appid二、打开小程序plus.share.getServices(res=>{varis_weixin=res.find(i=>i.id==='weixin');if(is_weixin){is_weixin.launchMiniProgram({id:weixin_id,......
  • app直播源代码,当前用户截止当前时间在本月的连续签到统计
    需求:实现下面接口,统计当前用户截止当前时间在本月的连续签到天数有用户有时间我们就可以组织出对应的key,此时就能找到这个用户截止这天的所有签到记录,再根据这套算法,就能统计出来他连续签到的次数了 代码UserController@GetMapping("/sign/count")publicResults......
  • 直播软件app开发,实现用户签到功能助力用户回流
    直播软件app开发,实现用户签到功能助力用户回流需求:实现签到接口,将当前用户当天签到信息保存到Redis中思路:我们可以把年和月作为bitMap的key,然后保存到一个bitMap中,每次签到就到对应的位上把数字从0变成1,只要对应是1,就表明说明这一天已经签到了,反之则没有签到。我们通过......
  • [附源码]JAVA计算机毕业设计安卓装维助手APP(开题+源码)
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容研究背景随着移动互联网技术的飞速发展,智能手机已经成为人们生活中不可或缺的一部分。在信息化社会的大背景下,各行各业的信息化水平也在不断提升。其中,计算机......
  • [附源码]JAVA计算机毕业设计安卓智能手机个性化定制问卷调查平台app(开题+源码)
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容研究背景随着移动互联网的迅猛发展,智能手机已成为人们日常生活中不可或缺的一部分。在个性化消费趋势的推动下,用户对智能手机的个性化定制需求日益增长。然而......
  • 【Coursera GenAI with LLM】 Week 3 LLM-powered applications Class Notes
    ModeloptimizationstoimproveapplicationperformanceDistillation:usesalargermodel,theteachermodel,totrainasmallermodel,thestudentmodel,wefreezeteacher'sweightsandgeneratecompletions,alsogeneratestudentmodel'scompl......
  • (Unity)Assembly Definition
    简单来说,AssemblyDefinition是一个可以划分代码集合的东西。​ 其核心用途一是减少编译时间,Unity在需要编译的时候会找到对应的csproj文件,然后直接对其进行重编译。默认情况下所有程序集都搁在Assembly-CSharp.csproj一起编译,随着你脚本越来越多,Assembly-CSharp.csproj也越来越......
  • Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately
    VSCode+MSBuild开发过程中出现如下警告:Pleasedefine_WIN32_WINNTor_WIN32_WINDOWSappropriately处理方法为,在c_cpp_properties.json文件中加入"_WIN32_WINNT>=0x0A00"的定义,配置如下:{"configurations":[{"name":"Win32",......
  • unity Mirror网络同步
    我们直接来剖析,上干货在github上的主页代码,稍微修改了下:usingSystem.Collections;usingSystem.Collections.Generic;usingMirror;usingUnityEngine;publicclassPlayer:NetworkBehaviour{//Syncedautomatically//自动同步[SyncVar]publicinthe......
  • NVIDIA的OpenUSD是什么? —— Universal Scene Description (USD)
    正如NVIDIA的老黄在2024年的技术大会上的展示一样,NVIDIA公司或许最准确的定义应该是计算机图形学公司,因为不论是NVIDIA搞GPU还是搞通用计算还是搞软件生态以至于现在搞AI搞机器人搞自动驾驶,其所有业务都是围绕图形图像学这条线来展开的。元宇宙,已经烂大街的一个概念,但是被业界认......