import { $pushInfoRegister } from '@/http/apiManager.js' import storageManage from '@/commons/utils/storageManage.js' // 默认导出 方法 注册 push连接 export default async function() { let cid1 = undefined // unipush1.0 客户端CID let cid2 = undefined // unipush2.0 客户端CID let orgCid = undefined // 原始cid如果获取的cid和新的cid不相同赋值原始cid后端会根据原始cid更新 let cidType = undefined //传递类型 是 app 还是 微信 // #ifdef APP-PLUS cidType = 'app_plus' // #endif // #ifdef MP-WEIXIN cidType = 'mp_weixin' // #endif // #ifdef APP-PLUS if (!plus) { cid1 = plus.push.getClientInfo().clientid } // #endif const data = await uni.getPushClientId() console.log('客户端推送标识:', data.cid) cid2 = data.cid // 如果不存 cid 本地存储 写入 cid if (!storageManage.uniPush2Cid()) { storageManage.uniPush2Cid(data.cid) } else if (cid2 !== storageManage.uniPush2Cid()) { // 否则进行 cid 对比 判断 是否相等 不相等 赋值 orgCid orgCid = storageManage.uniPush2Cid() //赋值原始cid storageManage.uniPush2Cid(data.cid) //重新写入 cid } if (cid1) { pushInfoRegister(cid1) } else { pushInfoRegister(cid1, cid2, orgCid, cidType) } function pushInfoRegister(cid1 = '', cid2 = '', org = '', cidType = '') { $pushInfoRegister({ cid1, cid2, orgCid: org, cidType }).then(res => { orgCid = '' //重置 数据 }) } }