@@ -26,6 +26,8 @@ const nimCallKit = (uni.$UIKitCallKit =
26
26
uni .requireNativePlugin (" netease-CallKit" ));
27
27
// #endif
28
28
29
+ let startByNotificationId = " " ;
30
+
29
31
export default {
30
32
onLaunch() {
31
33
// #ifdef APP-PLUS
@@ -45,6 +47,7 @@ export default {
45
47
) {
46
48
return ;
47
49
}
50
+
48
51
const imOptions = uni .getStorageSync (STORAGE_KEY );
49
52
if (imOptions ) {
50
53
this .initNim (imOptions );
@@ -59,11 +62,26 @@ export default {
59
62
// #ifdef APP-PLUS
60
63
uni ?.$UIKitNIM ?.V2NIMSettingService ?.setAppBackground (false );
61
64
// #endif
65
+
66
+ // 点击通知栏推送监听
67
+ nimPushPlugin .addOpenNotificationListener ((res : any ) => {
68
+ if (typeof res == " object" && res ?.sessionId && res ?.sessionType ) {
69
+ // 当前登录账号id 具体获取根据您的业务逻辑调整
70
+ const imOptions = uni .getStorageSync (STORAGE_KEY );
71
+ // 会话类型
72
+ const type = res ?.sessionType ;
73
+ // 拼装会话ID
74
+ startByNotificationId = ` ${imOptions .account }|${type }|${res ?.sessionId } ` ;
75
+ }
76
+ });
62
77
},
63
78
onHide() {
64
79
// #ifdef APP-PLUS
65
80
uni ?.$UIKitNIM ?.V2NIMSettingService ?.setAppBackground (true );
66
81
// #endif
82
+
83
+ // 重置推送 startByNotificationId
84
+ startByNotificationId = " " ;
67
85
},
68
86
methods: {
69
87
initNim(opts : { account: string ; token: string }) {
@@ -105,20 +123,23 @@ export default {
105
123
));
106
124
107
125
/** 初始化 im store */
126
+ // @ts-ignore
108
127
const store = (uni .$UIKitStore = new RootStore (
109
- // @ts-ignore
110
128
nim ,
111
129
{
112
130
// 添加好友是否需要验证
113
- addFriendNeedVerify: false ,
131
+ addFriendNeedVerify: true ,
114
132
// 是否需要显示 p2p 消息、p2p会话列表消息已读未读,默认 false
115
133
p2pMsgReceiptVisible: true ,
116
134
// 是否需要显示群组消息已读未读,默认 false
117
135
teamMsgReceiptVisible: true ,
136
+ // 是否显示在线离线
137
+ loginStateVisible: true ,
118
138
// 群组被邀请模式,默认需要验证
119
139
teamAgreeMode:
120
140
V2NIMConst .V2NIMTeamAgreeMode .V2NIM_TEAM_AGREE_MODE_NO_AUTH ,
121
141
// 发送消息前回调, 可对消息体进行修改,添加自定义参数
142
+ // @ts-ignore
122
143
sendMsgBefore : async (options : any ) => {
123
144
const pushContent = getMsgContentTipByType ({
124
145
text: options .msg .text ,
@@ -129,7 +150,7 @@ export default {
129
150
: { forcePushIDsList: " []" , needForcePush: false };
130
151
131
152
// 如果是 at 消息,需要走离线强推
132
-
153
+ // @ts-ignore
133
154
const { forcePushIDsList, needForcePush } = yxAitMsg
134
155
? // @ts-ignore
135
156
store .msgStore ._formatExtAitToPushInfo (
@@ -138,8 +159,6 @@ export default {
138
159
)
139
160
: { forcePushIDsList: " []" , needForcePush: false };
140
161
141
- console .log (" forcePushIDsList: " , forcePushIDsList );
142
-
143
162
const { conversationId } = options ;
144
163
const conversationType =
145
164
nim .V2NIMConversationIdUtil .parseConversationType (conversationId );
@@ -148,49 +167,82 @@ export default {
148
167
conversationId
149
168
);
150
169
170
+ // 设置离线强推,厂商相关推送在此处配置
171
+ // 具体参考文档 https://doc.yunxin.163.com/messaging2/guide/zc4MTg5MDY?platform=client#%E7%AC%AC%E4%B8%80%E6%AD%A5%E4%B8%8A%E4%BC%A0%E6%8E%A8%E9%80%81%E8%AF%81%E4%B9%A6
151
172
const pushPayload = JSON .stringify ({
152
- // oppo
153
- oppoField: {
154
- click_action_type: 4 , // 参考 oppo 官网
155
- click_action_activity: " " , // 各端不一样 TODO
156
- action_parameters: {
157
- sessionId: targetId ,
158
- sessionType: conversationType ,
159
- }, // 自定义
160
- },
161
-
162
- // vivo
163
- vivoField: {
164
- pushMode: 0 , // 推送模式 0:正式推送;1:测试推送,不填默认为0
165
- },
166
-
167
- // huawei
173
+ pushTitle: " " , // 必填,推送消息标题
174
+ notify_effect: " 2" , // 可选项,预定义通知栏消息的点击行为。1:通知栏点击后打开app的Launcher Activity,2:通知栏点击后打开app的任一Activity(开发者还需要传入intent_uri),3:通知栏点击后打开网页(开发者还需要传入web_uri)
175
+ intent_uri:
176
+ " intent:#Intent;action=com.netease.nimlib.uniapp.push.NotificationClickActivity;component=com.netease.nim.demo/com.netease.nimlib.uniapp.push.NotificationClickActivity;launchFlags=0x04000000;i.sessionType=0;S.sessionId=cs1;end" , // 可选项,打开当前app的任一组件。
168
177
hwField: {
169
178
click_action: {
170
- type: 1 ,
171
- action: " " , // 各端不一样 TODO
179
+ // 必填,消息点击行为
180
+ type: 1 , // 必填,消息点击行为类型,取值如下:1:打开应用自定义页面 2:点击后打开特定URL 3:点击后打开应用
181
+ // 自定义页面中intent的实现,请参见指定intent参数。当type为1时,字段intent和action至少二选一。scheme方式和指定activity方式都可以
182
+ intent:
183
+ " intent:#Intent;action=com.netease.nimlib.uniapp.push.NotificationClickActivity;component=com.netease.nim.demo/com.netease.nimlib.uniapp.push.NotificationClickActivity;launchFlags=0x04000000;i.sessionType=0;S.sessionId=cs1;end" ,
172
184
},
173
185
androidConfig: {
174
- category: " IM" ,
175
- data: JSON .stringify ({
176
- sessionId: targetId ,
177
- sessionType: conversationType ,
178
- }),
186
+ category: " IM" , // 可选项,标识消息类型,用于标识高优先级透传场景,详见官方文档 AndroidConfig.category
187
+ },
188
+ },
189
+ honorField: {
190
+ notification: {
191
+ // AndroidNotification
192
+ clickAction: {
193
+ // 必填,消息点击行为
194
+ type: 1 , // 必填,消息点击行为类型,取值如下:1:打开应用自定义页面 2:点击后打开特定URL 3:点击后打开应用
195
+ // 自定义页面中intent的实现,请参见指定intent参数。当type为1时,字段intent和action至少二选一。
196
+ intent: " " ,
197
+ },
198
+ importance: " NORMAL" , // 可选项,Android通知消息分类,决定用户设备消息通知行为,取值如下:LOW:资讯营销类消息 NORMAL:服务与通讯类消息
199
+ },
200
+ },
201
+ vivoField: {
202
+ skipType: " 4" , // 必填,点击跳转类型 1:打开APP首页 2:打开链接 3:自定义 4:打开app内指定页面,默认为1
203
+ skipContent: " " ,
204
+ classification: " 1" , // 可选项,消息类型 0:运营类消息,1:系统类消息。默认为0
205
+ category: " IM" , // 可选项,二级分类
206
+ },
207
+ oppoField: {
208
+ channel_id: " " , // 可选项,指定下发的通道ID
209
+ category: " IM" , // 可选项,通道类别名
210
+ notify_level: 2 , // 通知栏消息提醒等级,1-通知栏;2-通知栏+锁屏;16-通知栏+锁屏+横幅+震动+铃声
211
+ click_action_type: " 1" , // 点击通知栏后触发的动作类型。0(默认0.启动应用;1.跳转指定应用内页(action标签名);2.跳转网页;4.跳转指定应用内页(全路径类名);5.跳转Intent scheme URL: "",
212
+ click_action_activity: " " ,
213
+ action_parameters: " " ,
214
+ },
215
+ fcmFieldV1: {
216
+ message: {
217
+ android: {
218
+ priority: " " ,
219
+ data: {
220
+ sessionType: " 0" ,
221
+ sessionId: " cs1" ,
222
+ },
223
+ notification: {
224
+ click_action: " " ,
225
+ },
226
+ },
179
227
},
180
228
},
181
229
182
- // 通用
183
- sessionId: targetId ,
230
+ // IOS apns
231
+ sessionId:
232
+ conversationType == 1
233
+ ? uni .$UIKitStore .userStore .myUserInfo .accountId
234
+ : targetId ,
184
235
sessionType: conversationType ,
185
236
});
186
237
238
+ // @ts-ignore
187
239
const pushConfig = {
188
240
pushEnabled: true ,
189
241
pushNickEnabled: true ,
190
242
forcePush: needForcePush ,
191
243
forcePushContent: pushContent ,
192
244
forcePushAccountIds: forcePushIDsList ,
193
- pushPayload: " {} " ,
245
+ pushPayload ,
194
246
pushContent ,
195
247
};
196
248
@@ -199,50 +251,52 @@ export default {
199
251
},
200
252
" UniApp"
201
253
));
254
+
202
255
// #ifdef APP-PLUS
203
256
/** 注册推送 */
204
257
nim .V2NIMSettingService .setOfflinePushConfig (nimPushPlugin , {
205
258
miPush: {
206
- appId: " " ,
207
- appKey: " " ,
208
- certificateName: " " ,
259
+ appId: " 2882303761517864366 " ,
260
+ appKey: " 5991786427366 " ,
261
+ certificateName: " KIT_UNIAPP_MI_PUSH " ,
209
262
},
210
263
211
264
hwPush: {
212
- appId: " " ,
213
- certificateName: " " ,
265
+ appId: " 109540237 " ,
266
+ certificateName: " KIT_UNIAPP_HW_PUSH " ,
214
267
},
215
268
216
269
oppoPush: {
217
- appId: " " ,
218
- appKey: " " ,
219
- certificateName: " " ,
220
- secret: " " ,
270
+ appId: " 30795055 " ,
271
+ appKey: " 6ffe2c1198c5448e84b75f3b78b711ce " ,
272
+ certificateName: " KIT_OPPO_PUSH " ,
273
+ secret: " f55d519d05a04360a8ba3404a24594a0 " ,
221
274
},
222
275
223
276
vivoPush: {
224
- appId: " " ,
225
- appKey: " " ,
226
- certificateName: " " ,
277
+ appId: " 105693306 " ,
278
+ appKey: " c8ccf661e2aa7895c1a46b3631d5a163 " ,
279
+ certificateName: " KIT_UNIAPP_VIVO_PUSH " ,
227
280
},
228
281
229
282
fcmPush: {
230
- certificateName: " " ,
283
+ certificateName: " KIT_UNIAPP_FCM_PUSH " ,
231
284
},
232
285
233
286
mzPush: {
234
- appId: " " ,
235
- appKey: " " ,
236
- certificateName: " " ,
287
+ appId: " 148192 " ,
288
+ appKey: " 6068c5a8323542deaf83ad5b6d3ca9e2 " ,
289
+ certificateName: " KIT_MEIZU_PUSH " ,
237
290
},
238
291
239
292
apns: {
240
- certificateName: " " ,
293
+ certificateName: " dis_im " ,
241
294
},
242
295
});
243
296
// #endif
297
+
244
298
/** nim sdk 登录 */
245
- nim .V2NIMLoginService .login (opts .account , opts .token ).then (() => {
299
+ nim .V2NIMLoginService .login (opts .account , opts .token ).then (async () => {
246
300
// #ifdef APP-PLUS
247
301
/** 初始化音视频通话插件*/
248
302
nimCallKit .initConfig (
@@ -273,10 +327,25 @@ export default {
273
327
}
274
328
}
275
329
);
330
+
276
331
// #endif
277
- customSwitchTab ({
278
- url: " /pages/Conversation/index" ,
279
- });
332
+ // 判断时手动点击唤起 还是 点击推送通知栏唤起,点击通知栏唤起直接跳转到聊天页面
333
+ if (! startByNotificationId ) {
334
+ customSwitchTab ({
335
+ url: " /pages/Conversation/index" ,
336
+ });
337
+ } else {
338
+ if (startByNotificationId ) {
339
+ await uni .$UIKitStore .uiStore .selectConversation (
340
+ startByNotificationId
341
+ );
342
+
343
+ uni .navigateTo ({
344
+ url: ` /pages/Chat/index?conversationId=${startByNotificationId } ` ,
345
+ });
346
+ startByNotificationId = " " ;
347
+ }
348
+ }
280
349
});
281
350
},
282
351
logout() {
0 commit comments