|
|
|
|
@ -57,211 +57,16 @@ export default {
|
|
|
|
|
uni.$on('isGlogin', function (data) {
|
|
|
|
|
console.log('app.vue 接收', data)
|
|
|
|
|
if (uni.getStorageSync('apply-uid')) {
|
|
|
|
|
that.initWyyx()
|
|
|
|
|
// that.initWyyx()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (uni.getStorageSync('apply-token')) {
|
|
|
|
|
console.log('app.vue 是否调用')
|
|
|
|
|
that.initWyyx()
|
|
|
|
|
// that.initWyyx()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onHide: function () {},
|
|
|
|
|
methods: {
|
|
|
|
|
initWyyx() {
|
|
|
|
|
let that = this
|
|
|
|
|
|
|
|
|
|
that.F.wyyxPost(
|
|
|
|
|
that.api.wyyx_getConfig,
|
|
|
|
|
{
|
|
|
|
|
userId: uni.getStorageSync('apply-uid'),
|
|
|
|
|
},
|
|
|
|
|
(res) => {
|
|
|
|
|
console.log('wyyx_getConfig', res)
|
|
|
|
|
let resData = {
|
|
|
|
|
appkey: res.appKey,
|
|
|
|
|
accid: res.accid,
|
|
|
|
|
token: res.token,
|
|
|
|
|
}
|
|
|
|
|
const imOptions = {
|
|
|
|
|
appkey: resData.appkey, // 请填写您的 appkey
|
|
|
|
|
account: resData.accid, // 请填写您的 account
|
|
|
|
|
token: resData.token, // 请填写您的 token
|
|
|
|
|
// appkey: "7e19d679085266aa872a8de12f0c1ae5", // 请填写您的 appkey
|
|
|
|
|
// account: "9", // 请填写您的 account
|
|
|
|
|
// token: "2d4ca36cca6293cf3a81d6ca1b8026f7", // 请填写您的 token
|
|
|
|
|
}
|
|
|
|
|
if (imOptions) {
|
|
|
|
|
this.initNim(imOptions)
|
|
|
|
|
} else {
|
|
|
|
|
// 需要登录, 跳转登录页
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
async initNim(opts) {
|
|
|
|
|
let that = this
|
|
|
|
|
// 初始化 nim sdk
|
|
|
|
|
const nim = (uni.$UIKitNIM = V2NIM.getInstance(
|
|
|
|
|
{
|
|
|
|
|
appkey: opts.appkey,
|
|
|
|
|
needReconnect: true,
|
|
|
|
|
// "reconnectionAttempts": 5,
|
|
|
|
|
debugLevel: 'debug',
|
|
|
|
|
apiVersion: 'v2',
|
|
|
|
|
enableV2CloudConversation: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
V2NIMLoginServiceConfig: {
|
|
|
|
|
lbsUrls: isWxApp ? ['https://lbs.netease.im/lbs/wxwebconf.jsp'] : ['https://lbs.netease.im/lbs/webconf.jsp'],
|
|
|
|
|
linkUrl: isWxApp ? 'wlnimsc0.netease.im' : 'weblink.netease.im',
|
|
|
|
|
/**
|
|
|
|
|
* 使用固定设备 ID,
|
|
|
|
|
*/
|
|
|
|
|
isFixedDeviceId: true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
that.globalData.nim = nim
|
|
|
|
|
|
|
|
|
|
// 初始化 store
|
|
|
|
|
const store = (uni.$UIKitStore = new RootStore(
|
|
|
|
|
nim,
|
|
|
|
|
{
|
|
|
|
|
addFriendNeedVerify: false,
|
|
|
|
|
// 是否需要显示 p2p 消息、p2p 会话列表消息已读未读,默认 false
|
|
|
|
|
p2pMsgReceiptVisible: true,
|
|
|
|
|
// 是否需要显示群组消息已读未读,默认 false
|
|
|
|
|
teamMsgReceiptVisible: true,
|
|
|
|
|
teamAgreeMode: V2NIMConst.V2NIMTeamAgreeMode.V2NIM_TEAM_AGREE_MODE_NO_AUTH,
|
|
|
|
|
sendMsgBefore: async (options: { msg: V2NIMMessage; conversationId: string; serverExtension?: Record<string, unknown> }) => {
|
|
|
|
|
const pushContent = getMsgContentTipByType({
|
|
|
|
|
text: options.msg.text,
|
|
|
|
|
messageType: options.msg.messageType,
|
|
|
|
|
})
|
|
|
|
|
const yxAitMsg = options.serverExtension ? options.serverExtension.yxAitMsg : { forcePushIDsList: '[]', needForcePush: false }
|
|
|
|
|
|
|
|
|
|
// 如果是 at 消息,需要走离线强推
|
|
|
|
|
|
|
|
|
|
const { forcePushIDsList, needForcePush } = yxAitMsg
|
|
|
|
|
? // @ts-ignore
|
|
|
|
|
store.msgStore._formatExtAitToPushInfo(yxAitMsg, options.msg.text)
|
|
|
|
|
: { forcePushIDsList: '[]', needForcePush: false }
|
|
|
|
|
|
|
|
|
|
console.log('forcePushIDsList: ', forcePushIDsList)
|
|
|
|
|
|
|
|
|
|
const { conversationId } = options
|
|
|
|
|
const conversationType = nim.V2NIMConversationIdUtil.parseConversationType(conversationId)
|
|
|
|
|
const targetId = nim.V2NIMConversationIdUtil.parseConversationTargetId(conversationId)
|
|
|
|
|
|
|
|
|
|
const pushPayload = JSON.stringify({
|
|
|
|
|
// oppo
|
|
|
|
|
oppoField: {
|
|
|
|
|
click_action_type: 4, // 参考 oppo 官网
|
|
|
|
|
click_action_activity: '', // 各端不一样 TODO
|
|
|
|
|
action_parameters: {
|
|
|
|
|
sessionId: targetId,
|
|
|
|
|
sessionType: conversationType,
|
|
|
|
|
}, // 自定义
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// vivo
|
|
|
|
|
vivoField: {
|
|
|
|
|
pushMode: 0, //推送模式:0 表示正式推送、1 表示测试推送。不填则默认为 0。
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// huawei
|
|
|
|
|
hwField: {
|
|
|
|
|
click_action: {
|
|
|
|
|
type: 1,
|
|
|
|
|
action: '', // 各端不一样 TODO
|
|
|
|
|
},
|
|
|
|
|
androidConfig: {
|
|
|
|
|
category: 'IM',
|
|
|
|
|
data: JSON.stringify({
|
|
|
|
|
sessionId: targetId,
|
|
|
|
|
sessionType: conversationType,
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 通用
|
|
|
|
|
sessionId: targetId,
|
|
|
|
|
sessionType: conversationType,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const pushConfig: V2NIMMessagePushConfig = {
|
|
|
|
|
pushEnabled: true,
|
|
|
|
|
pushNickEnabled: true,
|
|
|
|
|
forcePush: needForcePush,
|
|
|
|
|
forcePushContent: pushContent,
|
|
|
|
|
forcePushAccountIds: forcePushIDsList,
|
|
|
|
|
pushPayload: '{}',
|
|
|
|
|
pushContent,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { ...options, pushConfig }
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'UniApp'
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
// #ifdef APP-PLUS
|
|
|
|
|
const nimPushPlugin = uni.requireNativePlugin('NIMUniPlugin-PluginModule')
|
|
|
|
|
nim.V2NIMSettingService.setOfflinePushConfig(nimPushPlugin, {
|
|
|
|
|
miPush: {
|
|
|
|
|
appId: '2882303761520397320',
|
|
|
|
|
appKey: '5102039734320',
|
|
|
|
|
certificateName: 'xiaomiCertificateName',
|
|
|
|
|
},
|
|
|
|
|
vivoPush: {
|
|
|
|
|
certificateName: 'vivoCertificateName',
|
|
|
|
|
},
|
|
|
|
|
oppoPush: {
|
|
|
|
|
appId: '32967155',
|
|
|
|
|
appKey: 'b98618cb272944dea324af6421d42a79',
|
|
|
|
|
secret: '0b7ce705a2304a17b78f20011c18890c',
|
|
|
|
|
certificateName: 'opopCertificateName',
|
|
|
|
|
},
|
|
|
|
|
honorPush: {
|
|
|
|
|
certificateName: 'rongyaoCertificateName',
|
|
|
|
|
},
|
|
|
|
|
apns: {
|
|
|
|
|
// certificateName: 'AuthKey_98P8URRXUD_test', //测试用:
|
|
|
|
|
certificateName: 'AuthKey_98P8URRXUD', //正式用
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
console.log('是否执行 推送')
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
nim.V2NIMLoginService.login(opts.account, opts.token).then(() => {})
|
|
|
|
|
|
|
|
|
|
nim.V2NIMConversationService.on('onConversationChanged', function (conversationList: V2NIMConversation[]) {
|
|
|
|
|
console.log('初始化监听会话:', conversationList)
|
|
|
|
|
let _bool = conversationList.filter((item) => {
|
|
|
|
|
return Number(item.unreadCount) > 0
|
|
|
|
|
})
|
|
|
|
|
console.log('初始化监听会话bool:', _bool)
|
|
|
|
|
if (_bool && _bool.length > 0) {
|
|
|
|
|
that.playAudio() // 播放音频
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
playAudio() {
|
|
|
|
|
let that = this
|
|
|
|
|
const innerAudioContext = uni.createInnerAudioContext()
|
|
|
|
|
innerAudioContext.autoplay = true
|
|
|
|
|
innerAudioContext.src = 'https://matripe-cms.oss-cn-beijing.aliyuncs.com/ibocai/tip.mp3'
|
|
|
|
|
innerAudioContext.onPlay(() => {
|
|
|
|
|
console.log('开始播放')
|
|
|
|
|
})
|
|
|
|
|
uni.vibrateShort()
|
|
|
|
|
|
|
|
|
|
innerAudioContext.onError((res) => {
|
|
|
|
|
console.log(res.errMsg)
|
|
|
|
|
console.log(res.errCode)
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
checkNum() {
|
|
|
|
|
let that = this
|
|
|
|
|
if (uni.getStorageSync('apply-token')) {
|
|
|
|
|
|