帖子
帖子
用户
博客
课程
显示全部楼层
216
帖子
5
勋章
5893
Y币

txPush模块(移动推送 TPNS)demo示例

[复制链接]
发表于 2021-7-3 09:56:59


移动推送 TPNS (Tencent Push Notification Service) 为您提供稳定、快速、高抵达的 App 推送服务。其接入方便快捷,拥有业内领先的技术实力,稳定可靠的消息推送通道,特有的智能推送通道策略,能有效提升消息抵达率;系统每分钟可容纳1800万推送消息,消息能秒级到达(支撑王者荣耀等腾讯内应用推送工具);此外,其具备精准用户标签能力,有效助力 App 的精细化运营。

  1. <!DOCTYPE html>
  2. <html>

  3. <head>
  4.         <title>Module Develop</title>
  5.         <meta charset="utf-8">
  6.         <meta name="viewport"
  7.                 content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  8.         <style type="text/css">
  9.                 html,
  10.                 body {
  11.                         height: 100%
  12.                 }

  13.                 body {
  14.                         background-color: #fff;
  15.                         margin: 0;
  16.                 }

  17.                 #wrap {
  18.                         height: 100%;
  19.                         position: relative;
  20.                 }

  21.                 #header {
  22.                         padding-top: 20px;
  23.                         background-color: #5082c2;
  24.                         height: 44px;
  25.                         position: relative;
  26.                 }

  27.                 #header h1 {
  28.                         font-size: 20px;
  29.                         height: 44px;
  30.                         line-height: 44px;
  31.                         margin: 0em;
  32.                         color: #fff;
  33.                         margin-left: 100px;
  34.                         margin-right: 100px;
  35.                         text-align: center;
  36.                 }

  37.                 #main {
  38.                         display: -webkit-box;
  39.                         -webkit-box-orient: vertical;
  40.                         -webkit-box-pack: center;
  41.                 }

  42.                 a.button {
  43.                         display: -webkit-box;
  44.                         -webkit-box-orient: vertical;
  45.                         -webkit-box-pack: center;
  46.                         -webkit-box-align: center;
  47.                         height: 32px;
  48.                         margin: 8px;
  49.                         background-color: rgba(240, 240, 240, 1.0);
  50.                         border-color: rgba(220, 220, 220, 1.0);
  51.                         border-width: 2px;
  52.                         border-style: solid;
  53.                 }

  54.                 a.active {
  55.                         background-color: rgba(240, 240, 240, 0.7);
  56.                 }
  57.         </style>
  58. </head>

  59. <body>
  60.         <div id="wrap">
  61.                 <div id="main">
  62.                         <br />
  63.                         <a class="button" tapmode="active" onclick="addNotifaction()">添加推送事件</a>
  64.                         <a class="button" tapmode="active" onclick="removeNotifaction()">移除推送事件</a>
  65.                         <a class="button" tapmode="active" onclick="registerPush()">注册推送</a>
  66.                         <a class="button" tapmode="active" onclick="isRegisterPush()">是否注册推送</a>
  67.                         <a class="button" tapmode="active" onclick="getToken()">获取Token</a>
  68.                         <a class="button" tapmode="active" onclick="unregisterPush()">反注册推送</a>
  69.                         <br />
  70.                 </div>
  71.         </div>
  72. </body>
  73. <script type="text/javascript">
  74.         var demo = null;
  75.         apiready = function () {
  76.                 demo = api.require('txPush');
  77.                 if (!demo) {
  78.                         alert("请添加模块后编译");
  79.                         return;
  80.                 }
  81.         }

  82.         function addNotifaction() {
  83.                 demo.addNotifaction(function (ret, err) {
  84.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  85.                 });
  86.         }

  87.         function removeNotifaction() {
  88.                 demo.removeNotifaction(function (ret, err) {
  89.                         //alert(JSON.stringify(ret) +"  "+JSON.stringify(err));
  90.                 });
  91.         }

  92.         function registerPush() {
  93.                 demo.registerPush({
  94.                         AccessId_Android: 1500005758,
  95.                         AccessKey_Android: 'ASDX2TBIOG5G',
  96.                         AccessId_iOS: 1600005759,
  97.                         AccessKey_iOS: 'IKDH5JF7DTKE',
  98.                 }, function (ret, err) {
  99.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  100.                 });
  101.         }

  102.         function getToken() {
  103.                 var ret = demo.getToken();
  104.                 alert(JSON.stringify(ret));
  105.         }

  106.         function isRegisterPush() {
  107.                 demo.isRegisterPush(function (ret, err) {
  108.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  109.                 });
  110.         }

  111.         function unregisterPush() {
  112.                 demo.unregisterPush(function (ret, err) {
  113.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  114.                 });
  115.         }
  116. </script>

  117. </html>
复制代码


1682
帖子
10
勋章
5893
Y币
感谢分享
您需要登录后才可以回帖 登录

本版积分规则