Commit a73416598b7b00da2ea6fdfa9385d3c628259324
1 parent
6a6746b2
极光推送 和 后端接口调用
Showing
3 changed files
with
24 additions
and
13 deletions
project-wl-kuaidiyuan-uniapp-vue3/src/api/jpush.js
| @@ -3,10 +3,15 @@ import { | @@ -3,10 +3,15 @@ import { | ||
| 3 | request | 3 | request |
| 4 | } from "@/utils/request.js" | 4 | } from "@/utils/request.js" |
| 5 | 5 | ||
| 6 | -// 计算运费 | ||
| 7 | -export const updateJpush = (params) => | 6 | +/** |
| 7 | + * | ||
| 8 | + * @param {*} params.userId | ||
| 9 | + * @param {*} params.deviceId registerId | ||
| 10 | + * @returns | ||
| 11 | + */ | ||
| 12 | +export const jpushSaveDevice = (params) => | ||
| 8 | request({ | 13 | request({ |
| 9 | - url: '/sys/user/updateJpushInfo', | 14 | + url: '/jpush/saveDevice', |
| 10 | method: 'post', | 15 | method: 'post', |
| 11 | params | 16 | params |
| 12 | }) | 17 | }) |
| 13 | \ No newline at end of file | 18 | \ No newline at end of file |
project-wl-kuaidiyuan-uniapp-vue3/src/composable/jpush.js
| 1 | -import { updateJpush } from '@/api/jpush' | 1 | +import { jpushSaveDevice } from '@/api/jpush' |
| 2 | import { platform } from '@/config/index' | 2 | import { platform } from '@/config/index' |
| 3 | import { ref, reactive, onMounted } from 'vue'; | 3 | import { ref, reactive, onMounted } from 'vue'; |
| 4 | export function useJPush() { | 4 | export function useJPush() { |
| 5 | //饮用JPush | 5 | //饮用JPush |
| 6 | const JPushModule = uni.requireNativePlugin('JG-JPush') | 6 | const JPushModule = uni.requireNativePlugin('JG-JPush') |
| 7 | - console.log('jpushModule', JPushModule) | 7 | + // console.log('jpushModule', JPushModule) |
| 8 | const isRegistrationPushed = ref(false) | 8 | const isRegistrationPushed = ref(false) |
| 9 | const registerID = ref(null) | 9 | const registerID = ref(null) |
| 10 | 10 | ||
| 11 | + const handleNotificationClick = (params) => { | ||
| 12 | + console.log(params) | ||
| 13 | + uni.navigateTo({ | ||
| 14 | + url:'/src/pages/my/index' | ||
| 15 | + }) | ||
| 16 | + } | ||
| 17 | + | ||
| 11 | const eventRegister = () => { | 18 | const eventRegister = () => { |
| 12 | if(JPushModule) { | 19 | if(JPushModule) { |
| 13 | JPushModule.addNotificationListener(result => { | 20 | JPushModule.addNotificationListener(result => { |
| @@ -46,16 +53,16 @@ export function useJPush() { | @@ -46,16 +53,16 @@ export function useJPush() { | ||
| 46 | 53 | ||
| 47 | const startUploadJpush = () => { | 54 | const startUploadJpush = () => { |
| 48 | if (registerID.value) { | 55 | if (registerID.value) { |
| 49 | - console.log(`推送注册成功222222${registerID.value}`) | ||
| 50 | - isRegistrationPushed.value = true | 56 | + console.log(`registerId: ${registerID.value}`) |
| 57 | + isRegistrationPushed.value = false | ||
| 51 | 58 | ||
| 52 | // JPushModule.initJPushService() | 59 | // JPushModule.initJPushService() |
| 53 | // 监听通知点击事件 - 这是关键 | 60 | // 监听通知点击事件 - 这是关键 |
| 54 | eventRegister() | 61 | eventRegister() |
| 55 | - | ||
| 56 | - updateJpush({ registrationId: registerID.value, platform: platform() }) | 62 | + const userInfo = uni.getStorageSync("userInfo"); |
| 63 | + jpushSaveDevice({ deviceId: registerID.value, userId: userInfo.id }) | ||
| 57 | .then(() => { | 64 | .then(() => { |
| 58 | - console.warn('推送注册成功') | 65 | + console.log('推送注册成功') |
| 59 | // tip.showToast(`推送注册成功${registerID.value}`) | 66 | // tip.showToast(`推送注册成功${registerID.value}`) |
| 60 | isRegistrationPushed.value = true | 67 | isRegistrationPushed.value = true |
| 61 | }) | 68 | }) |
project-wl-kuaidiyuan-uniapp-vue3/src/utils/env.js
| 1 | 1 | ||
| 2 | // 测试环境 | 2 | // 测试环境 |
| 3 | -// export const baseUrl = 'https://tms-gateway.zrpfsc.com/courier' | ||
| 4 | -// export const baseUrl ='http://10.30.110.163:9527/courier' | 3 | +export const baseUrl = 'https://sl-gateway.nong12.com/courier' |
| 5 | // 线上环境 | 4 | // 线上环境 |
| 6 | -export const baseUrl = 'https://tms-gateway.zrpfsc.com/courier' | ||
| 7 | \ No newline at end of file | 5 | \ No newline at end of file |
| 6 | +// export const baseUrl = 'https://tms-gateway.zrpfsc.com/courier' | ||
| 8 | \ No newline at end of file | 7 | \ No newline at end of file |