1.manifest.json ---模塊化中開啟unipush
2.uniapp開發后台配置項目包名簽名等---具體獲取---打包信息---微信開放平台
ps:簽名為特殊格式,需在java環境下查看證書密鑰文件獲取----
3.app.vue文件中配置監聽信息:
例子:
// 監聽信息 var info = plus.push.getClientInfo() // 使用5+App的方式進行監聽消息推送 plus.push.addEventListener("click", function(msg) { console.log("click:" + JSON.stringify(msg)); console.log(msg.payload); console.log(JSON.stringify(msg)); // onLaunch 生命周期里,頁面跳轉有問題,跳不過去 // 應該是頁面還沒加載,加上定時后,就可以了; setTimeout(() => { uni.navigateTo({ url: 'pages/index/index' }) }, 1000) }, false); // 監聽在線消息事件 plus.push.addEventListener("receive", function(msg) { //業務代碼 console.log("recevice:" + JSON.stringify(msg)) }, false);
4.登陸時獲取設備clientId發送后端
uni.getProvider({ service: 'push', success: e => { that.provider = e.provider; uni.subscribePush({ provider: that.provider[0], success: function(res) { var inf = plus.push.getClientInfo(); if (uni.getSystemInfoSync().platform == 'android') { that.clientId1 = inf.clientid; that.tokenType = 'android'; console.log(that.clientId1) } else if (uni.getSystemInfoSync().platform == 'ios') { that.clientId = inf.token; that.tokenType = 'ios'; } uni.onPush({ provider: that.provider[0], success: e => {}, callback: e => {} }); }, fail: function(err) { uni.onPush({ provider: that.provider[0], success: e => {}, callback: e => {} }); } }); }, fail: e => { uni.subscribePush({ provider: that.provider[0], success: function(res) { uni.onPush({ provider: that.provider[0], success: e => {}, callback: e => {} }); }, fail: function(err) { uni.onPush({ provider: that.provider[0], success: e => {}, callback: e => {} }); } }); } });
5.uni開發后台unipush配置中的"APPKEY", "APPID","MASTERSECRET",交予后端