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

aliPush模块封装了阿里移动推送sdk

[复制链接]
发表于 2022-9-27 11:31:57
本帖最后由 52yaoer 于 2022-10-14 20:11 编辑

aliPush模块封装了阿里移动推送sdk,阿里移动推送(Alibaba Cloud Mobile Push)是基于大数据的移动智能推送服务,帮助App快速集成移动推送的功能,在实现高效、精确、实时的移动推送的同时,极大地降低了开发成本。让开发者最有效地与用户保持连接,从而提高用户活跃度、提高应用的留存率。
开发者在使用aliPush模块时,需要开发者自行到阿里云注册账号,并开通移动推送功能。本模块与其它阿里相关或者集成了小米推送相关模块会存在冲突的可能,请大家使用时注意。

点击进入模块详情

关于安卓8.0以上的推送显示问题请看:https://community.apicloud.com/bbs/thread-114028-1-1.html

第三方推送配套插件获取地址:https://gitee.com/tyousan_admin/aliPushThirdParty.git



  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.                         <a class="button" tapmode="active" onclick="registerPush()">阿里推送注册</a>
  63.                         <a class="button" tapmode="active" onclick="setAutoRegister()">设置是否在app启动是自动注册推送</a>
  64.                         <a class="button" tapmode="active" onclick="getAutoRegister()">获取是否在app启动是自动注册推送</a>
  65.                         <a class="button" tapmode="active" onclick="isRegister()">是否注册成功</a>
  66.                         <a class="button" tapmode="active" onclick="getDeviceId()">获取设备ID</a>
  67.                         <a class="button" tapmode="active" onclick="onAppStart()">启动app统计(仅安卓有效)</a>
  68.                         <a class="button" tapmode="active" onclick="addTag()">添加标签</a>
  69.                         <a class="button" tapmode="active" onclick="removeTag()">删除标签</a>
  70.                         <a class="button" tapmode="active" onclick="listTags()">查询标签</a>
  71.                         <a class="button" tapmode="active" onclick="addAlias()">添加别名</a>
  72.                         <a class="button" tapmode="active" onclick="removeAlias()">删除别名</a>
  73.                         <a class="button" tapmode="active" onclick="listAliases()">查询别名</a>
  74.                         <a class="button" tapmode="active" onclick="bindAccount()">绑定账号</a>
  75.                         <a class="button" tapmode="active" onclick="unbindAccount()">解除绑定</a>
  76.                         <a class="button" tapmode="active" onclick="setDoNotDisturb()">设置免打扰时间段(仅安卓有效)</a>
  77.                         <a class="button" tapmode="active" onclick="closeDoNotDisturbMode()">取消免打扰(仅安卓有效)</a>
  78.                         <a class="button" tapmode="active" onclick="clearNotifications()">删除所有通知(仅安卓有效)</a>
  79.                         <a class="button" tapmode="active" onclick="bindPhoneNumber()">绑定电话号码(仅安卓有效)</a>
  80.                         <a class="button" tapmode="active" onclick="unbindPhoneNumber()">解绑电话号码(仅安卓有效)</a>
  81.                         <a class="button" tapmode="active" onclick="setNotificationSoundFilePath()">设置推送通知声音(仅安卓有效)</a>
  82.                 </div>
  83.         </div>
  84. </body>
  85. <script type="text/javascript">
  86.         var aliPush = null;
  87.         apiready = function () {
  88.                 aliPush = api.require('aliPush');
  89.                 if (!aliPush) {
  90.                         alert("请添加模块后编译");
  91.                         return;
  92.                 }
  93.                 //isRegister();
  94.                 aliPush.addEventListener({
  95.                         name: 'onMessage'
  96.                 }, function (ret, err) {
  97.                         alert("onMessage>>>addEventListener>>>>" + JSON.stringify(ret));
  98.                 });
  99.                 aliPush.addEventListener({
  100.                         name: 'onNotification'
  101.                 }, function (ret, err) {
  102.                         alert("onNotification>>>addEventListener>>>>" + JSON.stringify(ret));
  103.                 });
  104.                 aliPush.addEventListener({
  105.                         name: 'onNotificationOpened'
  106.                 }, function (ret, err) {
  107.                         alert("onNotificationOpened>>>addEventListener>>>>" + JSON.stringify(ret));
  108.                 });
  109.                 aliPush.addEventListener({
  110.                         name: 'onNotificationRemoved'
  111.                 }, function (ret, err) {
  112.                         alert("onNotificationRemoved>>>addEventListener>>>>" + JSON.stringify(ret));
  113.                 });

  114.                 api.addEventListener({
  115.                         name: 'noticeclicked'
  116.                 }, function (ret, err) {
  117.                         alert("noticeclicked>>>" + JSON.stringify(ret.value));
  118.                 });

  119.                 // var fs = api.require('fs');
  120.                 // var ret = fs.copyToSync({
  121.                 //     oldPath: 'widget://res/alicloud_notification_sound.mp3',
  122.                 //     newPath: 'fs://'
  123.                 // });
  124.                 // if (ret.status) {
  125.                 //     alert('拷贝成功!');
  126.                 //                 setNotificationSoundFilePath();
  127.                 // } else {
  128.                 //     alert('拷贝失败!');
  129.                 // }

  130.                 //setAdvCusNotif();
  131.         }

  132.         function registerPush() {
  133.                 aliPush.registerPush(function (ret, err) {
  134.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  135.                         //getDeviceId();
  136.                 });
  137.         }

  138.         function setAutoRegister() {
  139.                 var ret = aliPush.setAutoRegister({ isAutoRegister: true });
  140.                 alert(JSON.stringify(ret));
  141.         }

  142.         function getAutoRegister() {
  143.                 var ret = aliPush.getAutoRegister();
  144.                 alert(JSON.stringify(ret));
  145.         }

  146.         function getDeviceId() {
  147.                 aliPush.getDeviceId(function (ret, err) {
  148.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  149.                         console.log(JSON.stringify(ret));
  150.                 });
  151.         }

  152.         function isRegister() {
  153.                 aliPush.isRegister(function (ret, err) {
  154.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  155.                         //getDeviceId();
  156.                 });
  157.         }

  158.         function onAppStart() {
  159.                 aliPush.onAppStart(function (ret, err) {
  160.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  161.                 });
  162.         }

  163.         function addTag() {
  164.                 aliPush.addTag({
  165.                         target: 3,
  166.                         tag: "apicloud1 apicloud2",
  167.                         alias: 'aliasname'
  168.                 }, function (ret, err) {
  169.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  170.                 });
  171.         }

  172.         function removeTag() {
  173.                 aliPush.removeTag({
  174.                         target: 3,
  175.                         tag: "apicloud1 apicloud2",
  176.                         alias: 'aliasname'
  177.                 }, function (ret, err) {
  178.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  179.                 });
  180.         }

  181.         function listTags() {
  182.                 aliPush.listTags(function (ret, err) {
  183.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  184.                 });
  185.         }


  186.         function addAlias() {
  187.                 aliPush.addAlias({
  188.                         alias: 'test01'
  189.                 }, function (ret, err) {
  190.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  191.                 });
  192.         }

  193.         function removeAlias() {
  194.                 aliPush.removeAlias({
  195.                         alias: 'test01'
  196.                 }, function (ret, err) {
  197.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  198.                 });
  199.         }

  200.         function listAliases() {
  201.                 aliPush.listAliases(function (ret, err) {
  202.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  203.                 });
  204.         }

  205.         function bindAccount() {
  206.                 aliPush.bindAccount({
  207.                         account: "apicloudaccount"
  208.                 }, function (ret, err) {
  209.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  210.                 });
  211.         }

  212.         function unbindAccount() {
  213.                 aliPush.unbindAccount(function (ret, err) {
  214.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  215.                 });
  216.         }

  217.         function setDoNotDisturb() {
  218.                 aliPush.setDoNotDisturb({
  219.                         startHour: 23,
  220.                         startMinute: 0,
  221.                         endHour: 8,
  222.                         endMinute: 0
  223.                 }, function (ret, err) {
  224.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  225.                 });
  226.         }

  227.         function closeDoNotDisturbMode() {
  228.                 aliPush.closeDoNotDisturbMode(function (ret, err) {
  229.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  230.                 });
  231.         }

  232.         function clearNotifications() {
  233.                 aliPush.clearNotifications(function (ret, err) {
  234.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  235.                 });
  236.         }

  237.         function bindPhoneNumber() {
  238.                 aliPush.bindPhoneNumber({
  239.                         phoneNumber: "1300000000"
  240.                 }, function (ret, err) {
  241.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  242.                 });
  243.         }

  244.         function unbindPhoneNumber() {
  245.                 aliPush.unbindPhoneNumber(function (ret, err) {
  246.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  247.                 });
  248.         }

  249.         function setNotificationSoundFilePath() {
  250.                 aliPush.setNotificationSoundFilePath({
  251.                         filePath: "fs://alicloud_notification_sound.mp3"
  252.                 }, function (ret, err) {
  253.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  254.                 });
  255.         }




  256.         function turnOnPushChannel() {
  257.                 aliPush.turnOnPushChannel(function (ret, err) {
  258.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  259.                 });
  260.         }

  261.         function turnOffPushChannel() {
  262.                 aliPush.turnOffPushChannel(function (ret, err) {
  263.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  264.                 });
  265.         }

  266.         function checkPushChannelStatus() {
  267.                 aliPush.checkPushChannelStatus(function (ret, err) {
  268.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  269.                 });
  270.         }


  271.         function setAdvCusNotif() {
  272.                 aliPush.setAdvCusNotif({
  273.                         remindType: 2, //0:静默 1:震动 2:声音 3:声音+震动
  274.                         notificationId: 2,//默认2 范围:1-100
  275.                         serverOptionFirst: false,
  276.                         appInForeground: true //设置当推送到达时如果应用处于前台不创建通知: true : 创建 | false: 不创建
  277.                 }, function (ret, err) {
  278.                         setNotificationSoundFilePath();
  279.                         alert(JSON.stringify(ret));
  280.                 });
  281.         }
  282. </script>

  283. </html>
复制代码



130
帖子
7
勋章
5万+
Y币
点赞
92
帖子
2
勋章
718
Y币
你可以封装模块吗?
216
帖子
5
勋章
5909
Y币
yhbhpu · 2022-12-10 15:44你可以封装模块吗?

什么需求?
92
帖子
2
勋章
718
Y币

就是一个摄像头硬件,自带WIFI信号,手机连接这个WIFI之后与这个硬件连接,实现监控、拍照保存。模块实现连接硬件,监控、拍照和保存照片就可以了,功能很简单,有SDK
216
帖子
5
勋章
5909
Y币
yhbhpu · 2022-12-10 15:57就是一个摄像头硬件,自带WIFI信号,手机连接这个WIFI之后与这个硬件连接,实现监控、拍照保存。模块实现连接硬件,监控、拍照和保存照片就可以了,功能很简单,有SDK ...

可以把sdk发来我评估下工期和费用。
QQ: 1 7 6 1 4 2 9 9 8
216
帖子
5
勋章
5909
Y币
yhbhpu · 2022-12-10 15:57就是一个摄像头硬件,自带WIFI信号,手机连接这个WIFI之后与这个硬件连接,实现监控、拍照保存。模块实现连接硬件,监控、拍照和保存照片就可以了,功能很简单,有SDK ...

可以把sdk发来看看。
企  鹅: 1 7 6 1 4 2 9 9 8
216
帖子
5
勋章
5909
Y币
yhbhpu · 2022-12-10 15:57就是一个摄像头硬件,自带WIFI信号,手机连接这个WIFI之后与这个硬件连接,实现监控、拍照保存。模块实现连接硬件,监控、拍照和保存照片就可以了,功能很简单,有SDK ...

可以把sdk发来我评估下工期和费用。
企鹅:1,7,6,1,4,2,9,9,8,
216
帖子
5
勋章
5909
Y币
yhbhpu · 2022-12-10 15:57就是一个摄像头硬件,自带WIFI信号,手机连接这个WIFI之后与这个硬件连接,实现监控、拍照保存。模块实现连接硬件,监控、拍照和保存照片就可以了,功能很简单,有SDK ...

可以把sdk发来我评估下工期和费用。
企鹅:一,七,六,一,四,二,九,九,八,
216
帖子
5
勋章
5909
Y币
yhbhpu · 2022-12-10 15:57就是一个摄像头硬件,自带WIFI信号,手机连接这个WIFI之后与这个硬件连接,实现监控、拍照保存。模块实现连接硬件,监控、拍照和保存照片就可以了,功能很简单,有SDK ...

可以把sdk发来我评估下工期和费用。
1,7,6,1,4,2,9,9,8,
您需要登录后才可以回帖 登录

本版积分规则