消息推送和第三方接收后台搭建,未测试
This commit is contained in:
@@ -142,7 +142,7 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import { AkReq } from '@/uni_modules/ak-req/index.uts'
|
||||
import { IS_TEST_MODE } from '@/ak/config.uts'
|
||||
import { IS_TEST_MODE, PUSH_SERVER_URL } from '@/ak/config.uts'
|
||||
import { getCurrentUser, logout, setIsLoggedIn, setUserProfile } from '@/utils/store.uts'
|
||||
import { UserProfile } from '@/pages/user/types.uts'
|
||||
|
||||
@@ -351,24 +351,26 @@ const handleLogin = async () => {
|
||||
console.log('用户ID已保存到本地存储:', uid)
|
||||
// 获取并上报推送 CID(若可用)
|
||||
try {
|
||||
uni.getPushClientId({
|
||||
uni.getPushClientId({
|
||||
success: async (res: any) => {
|
||||
const cid = (res && (res.clientid || res.cid)) ? (res.clientid || res.cid) : (typeof res === 'string' ? res : null)
|
||||
if (cid != null && cid !== '') {
|
||||
try {
|
||||
uni.setStorageSync('uni_push2_cid', cid)
|
||||
} catch (e) {}
|
||||
try {
|
||||
await AkReq.request({
|
||||
url: '/api/v1/push/register',
|
||||
method: 'POST',
|
||||
data: { cid, platform: 'android' },
|
||||
contentType: 'application/json'
|
||||
})
|
||||
console.log('CID 已上报后台:', cid)
|
||||
} catch (e) {
|
||||
console.warn('上报 CID 失败:', e)
|
||||
}
|
||||
try {
|
||||
const uidStored = uni.getStorageSync('user_id') || null
|
||||
const currentUid = uidStored || (currentSession.user ? currentSession.user.getString('id') : null)
|
||||
await AkReq.request({
|
||||
url: `${PUSH_SERVER_URL}/api/v1/push/register`,
|
||||
method: 'POST',
|
||||
data: { cid, platform: 'android', user_id: currentUid },
|
||||
contentType: 'application/json'
|
||||
})
|
||||
console.log('CID 已上报后台:', cid, 'user_id:', currentUid)
|
||||
} catch (e) {
|
||||
console.warn('上报 CID 失败:', e)
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: (err: any) => {
|
||||
|
||||
@@ -95,6 +95,7 @@
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import { ensureUserProfile } from '@/utils/sapi.uts'
|
||||
import { AkReq } from '@/uni_modules/ak-req/index.uts'
|
||||
import { PUSH_SERVER_URL } from '@/ak/config.uts'
|
||||
|
||||
// 响应式数据
|
||||
const email = ref<string>('')
|
||||
@@ -302,10 +303,13 @@
|
||||
if (cid != null && cid !== '') {
|
||||
try { uni.setStorageSync('uni_push2_cid', cid) } catch (e) {}
|
||||
try {
|
||||
const uidStored = uni.getStorageSync('user_id') || null
|
||||
const currentSession = supa.getSession()
|
||||
const currentUid = uidStored || (currentSession && currentSession.user ? currentSession.user.getString('id') : null)
|
||||
await AkReq.request({
|
||||
url: '/api/v1/push/register',
|
||||
url: `${PUSH_SERVER_URL}/api/v1/push/register`,
|
||||
method: 'POST',
|
||||
data: { cid, platform: 'android' },
|
||||
data: { cid, platform: 'android', user_id: currentUid },
|
||||
contentType: 'application/json'
|
||||
})
|
||||
console.log('CID 已上报后台:', cid)
|
||||
|
||||
Reference in New Issue
Block a user