diff --git a/App.vue b/App.vue index 38a9c64..a33f264 100644 --- a/App.vue +++ b/App.vue @@ -20,6 +20,7 @@ history } from '@/api/public.js' import Routine from './libs/routine.js'; + var jpushModule = uni.requireNativePlugin("JG-JPush"); export default { globalData: { spid: 0, @@ -123,24 +124,24 @@ jpushModule.initJPushService() jpushModule.addConnectEventListener(result=>{ let connectEnable = result.connectEnable - console.log("jpush连接", connectEnable) + // console.log("jpush连接", connectEnable) }) - jpushModule.initJPushService(); + // 设置别名 - jpushModule.setAlias({ - 'alias': uni.getStorageSync('userId'), - 'sequence': 1 - }) + // jpushModule.setAlias({ + // 'alias': uni.getStorageSync('userId'), + // 'sequence': 1 + // }) // - jpushModule.addTagAliasListener(result => { - let code = result.code - let sequence = result.sequence - let tags = result.tags - let tag = result.tag - let tagEnable = result.tagEnable - let alias = result.alias - console.log(alias, '别名') - }) + // jpushModule.addTagAliasListener(result => { + // let code = result.code + // let sequence = result.sequence + // let tags = result.tags + // let tag = result.tag + // let tagEnable = result.tagEnable + // let alias = result.alias + // console.log(alias, '别名') + // }) // 通知事件回调 jpushModule.addNotificationListener(result => { let notificationEventType = result.notificationEventType @@ -148,31 +149,27 @@ let title = result.title let content = result.content let extras = result.extras - console.log("通知", result.extras.userinfo) + + console.log("通知", result) // 点击事件 if (notificationEventType == 'notificationOpened') { - if(result.extras.userinfo){ - uni.navigateTo({ - url: result.extras.userinfo - }) - } - + uni.navigateTo({ + url: result.extras.route + }) } }) - jpushModule.getRegistrationID(result => { - console.log("注册ID", result.registerID) - if (result.registerID) { - uni.setStorageSync("register_id", result.registerID) - } - }) - jpushModule.addCustomMessageListener(result => { - let messageID = result.messageID - let content = result.content - let extras = result.extras - console.log("自定义消息", result) - }) + + // jpushModule.addCustomMessageListener(result => { + // let messageID = result.messageID + // let content = result.content + // let extras = result.extras + // console.log("自定义消息", result) + // }) //#endif + + + }, onShow() { let that = this diff --git a/api/public.js b/api/public.js index e69a849..250bb47 100644 --- a/api/public.js +++ b/api/public.js @@ -74,6 +74,16 @@ export function bindMp(data) { noAuth: true }); } +/** + * 绑定极光id + * @param data object 小程序用户登陆信息 + */ +export function bindJG(data) { + return request.post("auth/bindJg", data, { + noAuth: true + }); +} + /** * 分享 * @returns {*} diff --git a/manifest.json b/manifest.json index 94267e9..0784e56 100644 --- a/manifest.json +++ b/manifest.json @@ -284,6 +284,7 @@ } } } + } } }, @@ -305,6 +306,7 @@ }, "requiredPrivateInfos" : [ "getLocation", "chooseAddress" ], "usingComponents" : true + }, "mp-alipay" : { "usingComponents" : true @@ -333,5 +335,6 @@ }, "title" : "加载中...", "template" : "template.h5.html" + } } diff --git a/pages/index/index.vue b/pages/index/index.vue index 741c27f..478e22c 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -108,6 +108,17 @@ this.getGoods() this.selfLocation() this.Area() + uni.$on('connectstatusChange',(connectstatus) =>{ + var connectstr = '' + if (connectstatus == true) { + connectstr ='已连接' + this.getRegistrationID() + }else{ + connectstr ='未连接' + } + this.connectstatus = connectStr + }) + }, onShow() {}, onReachBottom() { diff --git a/pages/users/login/login_copy.vue b/pages/users/login/login_copy.vue index 83defb3..59ce9c5 100644 --- a/pages/users/login/login_copy.vue +++ b/pages/users/login/login_copy.vue @@ -280,7 +280,8 @@ getLogo, getconfig, getVersion, - bindMp + bindMp, + bindJG } from "@/api/public"; // import cookie from "@/utils/store/cookie"; import { @@ -295,6 +296,7 @@ mapGetters } from "vuex"; import Verify from '@/components/verify/verify.vue'; + var jpushModule = uni.requireNativePlugin("JG-JPush"); const BACK_URL = "login_back_url"; export default { @@ -920,8 +922,7 @@ code: res.code, iv: iv, encryptedData: encryptedData, - phone: that - .account + phone: that.account }).then(res => { // console.log(res); }) @@ -936,6 +937,15 @@ } }) } + jpushModule.initJPushService() + jpushModule.getRegistrationID(result => { + if (result.registerID) { + bindJG({ + phone: this.account, + jg_register_id: result.registerID + }) + } + }) } } };