From 9e31151a962f6a400d4f83d71197391e347023eb Mon Sep 17 00:00:00 2001 From: DCloud_JSON Date: Fri, 21 Jun 2024 17:51:58 +0800 Subject: [PATCH] Update uni-im.md --- docs/uni-im.md | 82 ++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/docs/uni-im.md b/docs/uni-im.md index 8cd0ce1..00fffff 100644 --- a/docs/uni-im.md +++ b/docs/uni-im.md @@ -166,45 +166,49 @@ uni-app生态下绝大部分项目的架构与uni-im相同,所以不需要考 需要在传统服务器端,通过[uni-id的外部系统联登](./uni-id/cloud-object.md#external)同步你项目的账号数据到uni-im用户体系并获得uni-id的token,按如下示例代码完成登录。 ```js - import {mutations as uniIdMutations} from '@/uni_modules/uni-id-pages/common/store.js'; - uni.request({ - url: 'https://www.example.com/login', //仅为示例,并非真实接口地址。 - data: { - username: 'test', - password: '123456' - }, - success:async (res) => { - console.log(res.data); - // 得到你自己项目的token和uni-id的token - let {token,uniIdToken} = res.data - // 存储你自己项目的token到storage(仅供参考,根据你自己的登录逻辑而定) - uni.setStorageSync('token',token) - - // 存储uni-id的token和token过期时间到storage(必须按以下格式存储) - uni.setStorageSync('uni_id_token_expired',uniIdToken.tokenExpired) - uni.setStorageSync('uni_id_token',uniIdToken.token) - // 获取push的ClientId同步到uni-id - uni.getPushClientId({ - success: async function(e) { - // console.log(e) - let pushClientId = e.cid - // console.log(pushClientId); - let res = await uniIdCo.setPushCid({ - pushClientId - }) - // console.log('getPushClientId', res); - }, - fail(e) { - console.log(e) - } - }) - // 更新本地用户信息 - await uniIdMutations.updateUserInfo() - // 通知其他模块登录成功 - uni.$emit('uni-id-pages-login-success') - } - }); - +import { + mutations as uniIdMutations +} from '@/uni_modules/uni-id-pages/common/store.js'; +uni.request({ + url: 'https://www.example.com/login', //仅为示例,并非真实接口地址。 + data: { + username: 'test', + password: '123456' + }, + success: async (res) => { + console.log(res.data); + // 得到你自己项目的token和uni-id的token + let { + token, + uniIdToken + } = res.data + // 存储你自己项目的token到storage(仅供参考,根据你自己的登录逻辑而定) + uni.setStorageSync('token', token) + + // 存储uni-id的token和token过期时间到storage(必须按以下格式存储) + uni.setStorageSync('uni_id_token_expired', uniIdToken.tokenExpired) + uni.setStorageSync('uni_id_token', uniIdToken.token) + // 获取push的ClientId同步到uni-id + uni.getPushClientId({ + success: async function(e) { + // console.log(e) + let pushClientId = e.cid + // console.log(pushClientId); + let res = await uniIdCo.setPushCid({ + pushClientId + }) + // console.log('getPushClientId', res); + }, + fail(e) { + console.log(e) + } + }) + // 更新本地用户信息 + await uniIdMutations.updateUserInfo() + // 通知其他模块登录成功 + uni.$emit('uni-id-pages-login-success') + } +}); ``` 其他情况: -- GitLab