hh-doctor-sdk 0.8.8 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/consultation/detail/consultation-detail-page.js +2 -0
- package/components/consultation/list/consultation-list-page.js +7 -2
- package/components/hh-doctor.js +25 -1
- package/components/public/app-config.js +1 -5
- package/components/public/cache-data.js +40 -2
- package/components/public/doctor-loader.js +15 -0
- package/components/public/login-guard.js +36 -0
- package/components/utils/httpUtils.js +32 -12
- package/components/utils/orderSession.js +113 -0
- package/package.json +5 -2
- package/docs//345/256/277/344/270/273/345/260/217/347/250/213/345/272/217-/350/205/276/350/256/257IM/345/237/237/345/220/215/351/205/215/347/275/256.md +0 -129
|
@@ -4,6 +4,7 @@ var currentPlayIndex = -1
|
|
|
4
4
|
var audioAnimationInterval
|
|
5
5
|
|
|
6
6
|
const hhNavigation = require('../../hh-navigation')
|
|
7
|
+
const hhDoctor = require('../../hh-doctor')
|
|
7
8
|
const doctorLoader = require('../../public/doctor-loader')
|
|
8
9
|
const permission = require('../../utils/permission-utils')
|
|
9
10
|
const imManager = require('../../public/im-manager')
|
|
@@ -20,6 +21,7 @@ Page({
|
|
|
20
21
|
onLoad(options) {
|
|
21
22
|
this._detailAlive = true
|
|
22
23
|
wx.statLog.sendStatLog(options.orderId, '打开咨询单详情界面')
|
|
24
|
+
hhDoctor.absorbEntryOptions(options)
|
|
23
25
|
const doctorId = options.doctorId
|
|
24
26
|
doctorLoader.loadDoctor({
|
|
25
27
|
doctorId: doctorId,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const doctorLoader = require('../../public/doctor-loader')
|
|
2
2
|
const cache = require('../../public/cache-data')
|
|
3
|
+
const hhDoctor = require('../../hh-doctor')
|
|
3
4
|
|
|
4
5
|
Page({
|
|
5
6
|
|
|
@@ -19,7 +20,12 @@ Page({
|
|
|
19
20
|
* 生命周期函数--监听页面加载
|
|
20
21
|
*/
|
|
21
22
|
onLoad(options) {
|
|
22
|
-
|
|
23
|
+
// 短链直达列表页时,链接里的 doctorId / userToken 要落下来,否则 onShow 只读 storage 会取空
|
|
24
|
+
const doctorId = options && options.doctorId ? String(options.doctorId).trim() : ''
|
|
25
|
+
if (doctorId) {
|
|
26
|
+
wx.setStorageSync('doctorId', doctorId)
|
|
27
|
+
}
|
|
28
|
+
hhDoctor.absorbEntryOptions(options)
|
|
23
29
|
},
|
|
24
30
|
|
|
25
31
|
/**
|
|
@@ -51,7 +57,6 @@ Page({
|
|
|
51
57
|
if (judgeLogin) {
|
|
52
58
|
wx.statLog.sendStatLog(null, '打开咨询单列表界面')
|
|
53
59
|
const doctorId = wx.getStorageSync('doctorId') || ''
|
|
54
|
-
// console.error(`doctorId => ${doctorId}`)
|
|
55
60
|
cache.cache({
|
|
56
61
|
doctorId: doctorId
|
|
57
62
|
})
|
package/components/hh-doctor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const api = require('./apis/order-app-api')
|
|
2
|
-
const
|
|
2
|
+
const cache = require('./public/cache-data')
|
|
3
3
|
|
|
4
4
|
function initEventBus() {
|
|
5
5
|
if (wx.eventBus) {
|
|
@@ -37,6 +37,28 @@ function setLoginCheck(judgeLogin, directLogin) {
|
|
|
37
37
|
wx.loginConfig.directLogin = directLogin
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/** 宿主在拉医生信息前写入 userToken,order 请求和换 session 都读这份 */
|
|
41
|
+
function setUserToken(userToken) {
|
|
42
|
+
const token = (userToken || '').trim()
|
|
43
|
+
cache.setUserToken(token)
|
|
44
|
+
if (token) {
|
|
45
|
+
wx.setStorageSync('userToken', token)
|
|
46
|
+
} else {
|
|
47
|
+
wx.removeStorageSync('userToken')
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 短链直达页面时,把 onLoad(options) 里的 userToken 落地,后续页面和请求直接复用 */
|
|
52
|
+
function absorbEntryOptions(options) {
|
|
53
|
+
if (!options) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
const token = (options.userToken || options.hhusertoken || '').trim()
|
|
57
|
+
if (token) {
|
|
58
|
+
setUserToken(token)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
40
62
|
/**
|
|
41
63
|
* 检测医生信息是否认证完成
|
|
42
64
|
* @param {*} doctorId 医生Id
|
|
@@ -86,6 +108,8 @@ module.exports = {
|
|
|
86
108
|
initTim,
|
|
87
109
|
initStatLog,
|
|
88
110
|
setLoginCheck,
|
|
111
|
+
setUserToken,
|
|
112
|
+
absorbEntryOptions,
|
|
89
113
|
enterForground,
|
|
90
114
|
enterBackground,
|
|
91
115
|
isDoctorAuth
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/** 发版 npm 时与 package.json version 保持一致 */
|
|
2
|
-
const sdkVersion = '0.
|
|
2
|
+
const sdkVersion = '0.9.1'
|
|
3
3
|
|
|
4
4
|
const appVersion = '7.1.6'
|
|
5
5
|
const appID = '10423'
|
|
6
6
|
const appKey = ''
|
|
7
7
|
const appSecret = 'N0e7293NSF8nBZjO'
|
|
8
|
-
const sessionId = '1776843236242882600'
|
|
9
|
-
const sessionIdProd = '1792831747042312418'
|
|
10
8
|
|
|
11
9
|
module.exports = {
|
|
12
10
|
sdkVersion,
|
|
@@ -14,6 +12,4 @@ module.exports = {
|
|
|
14
12
|
appID,
|
|
15
13
|
appKey,
|
|
16
14
|
appSecret,
|
|
17
|
-
sessionId,
|
|
18
|
-
sessionIdProd,
|
|
19
15
|
}
|
|
@@ -84,12 +84,49 @@ function uuid() {
|
|
|
84
84
|
return null
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
function setUserToken(token) {
|
|
88
|
+
cache({
|
|
89
|
+
userToken: token || ''
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* userToken 由宿主通过 hhDoctor.setUserToken 传入(同时写内存和 storage)。
|
|
95
|
+
* 顺序:内存 > 医生信息 > storage > 本次进入的链接参数。
|
|
96
|
+
* 最后一级给「专家从微信消息短链直接进入」用:短链里的 userToken 落在 enter/launch options 的 query 上,
|
|
97
|
+
* 与 App 拼 H5 链接的传参方式一致(userToken / hhusertoken 两个 key 都认)。
|
|
98
|
+
*/
|
|
87
99
|
function userToken() {
|
|
100
|
+
const preset = getValue('userToken')
|
|
101
|
+
if (preset) {
|
|
102
|
+
return preset
|
|
103
|
+
}
|
|
88
104
|
const doctorInfo = doctor()
|
|
89
|
-
if (doctorInfo) {
|
|
105
|
+
if (doctorInfo && doctorInfo.userToken) {
|
|
90
106
|
return doctorInfo.userToken
|
|
91
107
|
}
|
|
92
|
-
return null
|
|
108
|
+
return storedUserToken() || linkUserToken() || null
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function storedUserToken() {
|
|
112
|
+
try {
|
|
113
|
+
return wx.getStorageSync('userToken') || ''
|
|
114
|
+
} catch (e) {
|
|
115
|
+
return ''
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function linkUserToken() {
|
|
120
|
+
const pick = (options) => {
|
|
121
|
+
const query = (options && options.query) || {}
|
|
122
|
+
return query.userToken || query.hhusertoken || ''
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const enter = wx.getEnterOptionsSync && wx.getEnterOptionsSync()
|
|
126
|
+
return pick(enter) || pick(wx.getLaunchOptionsSync && wx.getLaunchOptionsSync())
|
|
127
|
+
} catch (e) {
|
|
128
|
+
return ''
|
|
129
|
+
}
|
|
93
130
|
}
|
|
94
131
|
|
|
95
132
|
function videoToken() {
|
|
@@ -134,5 +171,6 @@ module.exports = {
|
|
|
134
171
|
getLogId,
|
|
135
172
|
clearLogId,
|
|
136
173
|
isRequest,
|
|
174
|
+
setUserToken,
|
|
137
175
|
userToken,
|
|
138
176
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const api = require('../apis/order-app-api')
|
|
2
2
|
const cache = require('./cache-data')
|
|
3
|
+
const loginGuard = require('./login-guard')
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* 获取登录医生的数据
|
|
@@ -14,6 +15,20 @@ function loadDoctor(options, callback) {
|
|
|
14
15
|
})
|
|
15
16
|
return
|
|
16
17
|
}
|
|
18
|
+
// 没有登录态时后面每个请求都会被鉴权挡掉,直接转登录,别再发注定 402 的请求
|
|
19
|
+
if (!loginGuard.isLoggedIn()) {
|
|
20
|
+
wx.statLog.sendStatLog(null, `场景:${options.scence || '未知'} 未登录,转登录页`)
|
|
21
|
+
if (!loginGuard.redirectToLogin()) {
|
|
22
|
+
wx.showToast({
|
|
23
|
+
title: '请先登录',
|
|
24
|
+
icon: 'none',
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
if (callback) {
|
|
28
|
+
callback(false)
|
|
29
|
+
}
|
|
30
|
+
return
|
|
31
|
+
}
|
|
17
32
|
// 由于后续所有联网请求都需要doctorId所以在此缓存doctorId在联网公共参数会用到
|
|
18
33
|
if (doctorId === cache.doctorId() && cache.doctor() !== null) {
|
|
19
34
|
// 如果传入的doctorId和以前已经加载过的doctorId一致并且doctor数据不为空可以不再次加载doctor数据
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const cache = require('./cache-data')
|
|
2
|
+
|
|
3
|
+
let redirectingAt = 0
|
|
4
|
+
|
|
5
|
+
/** 是否已登录:宿主注册的 judgeLogin 优先,没注册就按有没有 userToken 判断 */
|
|
6
|
+
function isLoggedIn() {
|
|
7
|
+
const config = wx.loginConfig
|
|
8
|
+
if (config && typeof config.judgeLogin === 'function') {
|
|
9
|
+
return !!config.judgeLogin()
|
|
10
|
+
}
|
|
11
|
+
return !!cache.userToken()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 跳宿主登录页。
|
|
16
|
+
* 返回 false 表示宿主没注册 directLogin,调用方自己决定怎么提示。
|
|
17
|
+
* 3 秒内只跳一次,避免返回后 onShow 再触发、页面栈叠一摞登录页。
|
|
18
|
+
*/
|
|
19
|
+
function redirectToLogin() {
|
|
20
|
+
const config = wx.loginConfig || {}
|
|
21
|
+
if (typeof config.directLogin !== 'function') {
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
const now = Date.now()
|
|
25
|
+
if (now - redirectingAt < 3000) {
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
redirectingAt = now
|
|
29
|
+
config.directLogin(true)
|
|
30
|
+
return true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
isLoggedIn,
|
|
35
|
+
redirectToLogin,
|
|
36
|
+
}
|
|
@@ -2,6 +2,7 @@ const sha1 = require('./checksumUtils')
|
|
|
2
2
|
const cache = require('../public/cache-data')
|
|
3
3
|
const appConfig = require('../public/app-config')
|
|
4
4
|
const hostDefine = require('../apis/api-host-define')
|
|
5
|
+
const orderSession = require('./orderSession')
|
|
5
6
|
|
|
6
7
|
var cookie = ''
|
|
7
8
|
|
|
@@ -26,6 +27,33 @@ function httpGet(request, params, data) {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
function _request(request, method, params, data) {
|
|
30
|
+
if (request.hostType !== hostDefine.hostTypes.order) {
|
|
31
|
+
return _send(request, method, params, data, '')
|
|
32
|
+
}
|
|
33
|
+
return _sendWithSession(request, method, params, data, false)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 会话被拒绝时清掉并换一次重试;换不到不阻断,交给服务端按 402 返回
|
|
37
|
+
function _sendWithSession(request, method, params, data, retried) {
|
|
38
|
+
return orderSession.ensure()
|
|
39
|
+
.catch((err) => {
|
|
40
|
+
console.warn('orderapp session 换取失败,按无会话继续', {
|
|
41
|
+
doctorId: cache.doctorId(),
|
|
42
|
+
err: err && err.message
|
|
43
|
+
})
|
|
44
|
+
return ''
|
|
45
|
+
})
|
|
46
|
+
.then((sessionId) => _send(request, method, params, data, sessionId))
|
|
47
|
+
.catch((err) => {
|
|
48
|
+
if (!retried && orderSession.rejected(err)) {
|
|
49
|
+
orderSession.clear('status=' + err.status)
|
|
50
|
+
return _sendWithSession(request, method, params, data, true)
|
|
51
|
+
}
|
|
52
|
+
return Promise.reject(err)
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function _send(request, method, params, data, sessionId) {
|
|
29
57
|
return new Promise((resolve, reject) => {
|
|
30
58
|
let host = hostDefine.host(request.hostType)
|
|
31
59
|
let url = `${host}${request.path}`
|
|
@@ -39,6 +67,9 @@ function _request(request, method, params, data) {
|
|
|
39
67
|
fullParams.app_version = appConfig.appVersion
|
|
40
68
|
fullParams.actionSource = 'wxdoctor'
|
|
41
69
|
fullParams.device_token = ''
|
|
70
|
+
if (sessionId) {
|
|
71
|
+
fullParams.session_id = sessionId
|
|
72
|
+
}
|
|
42
73
|
if (doctorId) {
|
|
43
74
|
fullParams.doctor_id = doctorId
|
|
44
75
|
fullParams.user_id = doctorId
|
|
@@ -49,17 +80,6 @@ function _request(request, method, params, data) {
|
|
|
49
80
|
if (userToken) {
|
|
50
81
|
fullParams.userToken = userToken
|
|
51
82
|
}
|
|
52
|
-
// 安全获取环境配置
|
|
53
|
-
let profileName = 'prod'
|
|
54
|
-
try {
|
|
55
|
-
const app = getApp()
|
|
56
|
-
if (app && app.globalData && app.globalData.profileName) {
|
|
57
|
-
profileName = app.globalData.profileName
|
|
58
|
-
}
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.warn('获取环境配置失败,使用默认生产环境:', error)
|
|
61
|
-
}
|
|
62
|
-
fullParams.session_id = (profileName === 'test') ? appConfig.sessionId : appConfig.sessionIdProd
|
|
63
83
|
fullParams.random = new Date().getTime()
|
|
64
84
|
|
|
65
85
|
for (let [key, value] of Object.entries(fullParams)) {
|
|
@@ -143,4 +163,4 @@ function setCookie(value) {
|
|
|
143
163
|
module.exports = {
|
|
144
164
|
post: httpPost,
|
|
145
165
|
get: httpGet,
|
|
146
|
-
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const cache = require('../public/cache-data')
|
|
2
|
+
const hostDefine = require('../apis/api-host-define')
|
|
3
|
+
|
|
4
|
+
// 服务端 90 分钟滑动过期;客户端提前换,避免踩着过期点发请求
|
|
5
|
+
const CACHE_KEY = 'hh_doctor_order_session'
|
|
6
|
+
const TTL_MILLIS = 80 * 60 * 1000
|
|
7
|
+
const LOGIN_PATH = '/login/loginByUUIDWithWX'
|
|
8
|
+
|
|
9
|
+
let pending = null
|
|
10
|
+
|
|
11
|
+
function doctorId() {
|
|
12
|
+
return cache.doctorId() || ''
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function read() {
|
|
16
|
+
try {
|
|
17
|
+
const cached = wx.getStorageSync(CACHE_KEY)
|
|
18
|
+
if (cached && cached.expireAt > Date.now() && cached.userId === doctorId()) {
|
|
19
|
+
return cached.sessionId
|
|
20
|
+
}
|
|
21
|
+
} catch (e) {
|
|
22
|
+
console.warn('orderapp session 读取失败', { doctorId: doctorId(), err: e && e.message })
|
|
23
|
+
}
|
|
24
|
+
return ''
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function clear(reason) {
|
|
28
|
+
try {
|
|
29
|
+
wx.removeStorageSync(CACHE_KEY)
|
|
30
|
+
} catch (e) {
|
|
31
|
+
console.warn('orderapp session 清理失败', { doctorId: doctorId(), err: e && e.message })
|
|
32
|
+
}
|
|
33
|
+
if (reason) {
|
|
34
|
+
console.warn('orderapp session 已失效', { reason: reason, doctorId: doctorId() })
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function ensure() {
|
|
39
|
+
const cached = read()
|
|
40
|
+
return cached ? Promise.resolve(cached) : exchange()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 同一医生的并发请求共用一次换取;换到的 session 只记在发起时的医生名下
|
|
44
|
+
function exchange() {
|
|
45
|
+
const currentDoctorId = doctorId()
|
|
46
|
+
const userToken = cache.userToken()
|
|
47
|
+
if (!userToken) {
|
|
48
|
+
console.warn('orderapp session 未换取: 缺少 userToken', { doctorId: currentDoctorId })
|
|
49
|
+
return Promise.reject(new Error('缺少 userToken'))
|
|
50
|
+
}
|
|
51
|
+
if (pending && pending.doctorId === currentDoctorId) {
|
|
52
|
+
return pending.promise
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const started = Date.now()
|
|
56
|
+
const url = `${hostDefine.host(hostDefine.hostTypes.order)}${LOGIN_PATH}?userToken=${encodeURIComponent(userToken)}`
|
|
57
|
+
const promise = new Promise((resolve, reject) => {
|
|
58
|
+
wx.request({
|
|
59
|
+
url: url,
|
|
60
|
+
method: 'POST',
|
|
61
|
+
data: {},
|
|
62
|
+
header: { 'content-type': 'application/json', 'APPTYPE': 'pc' },
|
|
63
|
+
success: function (res) {
|
|
64
|
+
const body = res.data || {}
|
|
65
|
+
// sessionId 是 19 位 Long,JS 解析会丢精度,必须取字符串字段 sSessionId
|
|
66
|
+
const sessionId = body.data && body.data.sSessionId
|
|
67
|
+
if (body.status == 200 && sessionId) {
|
|
68
|
+
wx.setStorageSync(CACHE_KEY, {
|
|
69
|
+
sessionId: sessionId,
|
|
70
|
+
userId: currentDoctorId,
|
|
71
|
+
expireAt: Date.now() + TTL_MILLIS
|
|
72
|
+
})
|
|
73
|
+
console.info('orderapp session 已换取', {
|
|
74
|
+
doctorId: currentDoctorId,
|
|
75
|
+
elapsed_ms: Date.now() - started
|
|
76
|
+
})
|
|
77
|
+
resolve(sessionId)
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
reject(new Error(body.error_msg || '换取 orderapp session 失败'))
|
|
81
|
+
},
|
|
82
|
+
fail: function (err) {
|
|
83
|
+
console.warn('orderapp session 换取失败', {
|
|
84
|
+
doctorId: currentDoctorId,
|
|
85
|
+
err: err && err.errMsg,
|
|
86
|
+
elapsed_ms: Date.now() - started
|
|
87
|
+
})
|
|
88
|
+
reject(err)
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
promise.then(function () {
|
|
93
|
+
if (pending && pending.promise === promise) {
|
|
94
|
+
pending = null
|
|
95
|
+
}
|
|
96
|
+
}, function () {
|
|
97
|
+
if (pending && pending.promise === promise) {
|
|
98
|
+
pending = null
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
pending = { doctorId: currentDoctorId, promise: promise }
|
|
102
|
+
return promise
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function rejected(body) {
|
|
106
|
+
return !!(body && (body.status == 402 || body.status == 600))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
module.exports = {
|
|
110
|
+
ensure,
|
|
111
|
+
clear,
|
|
112
|
+
rejected,
|
|
113
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hh-doctor-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "和缓名医小程序SDK",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"test": "
|
|
6
|
+
"test": "node test/sdk-check.js"
|
|
7
7
|
},
|
|
8
8
|
"keywords": [
|
|
9
9
|
"和缓名医小程序SDK"
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"author": "liumingming",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"miniprogram": "components",
|
|
14
|
+
"files": [
|
|
15
|
+
"components"
|
|
16
|
+
],
|
|
14
17
|
"dependencies": {
|
|
15
18
|
}
|
|
16
19
|
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
# 宿主小程序 · 腾讯云即时通信 IM 服务器域名配置
|
|
2
|
-
|
|
3
|
-
> 发给运维/小程序管理员,在 **宿主小程序**(接入 `hh-doctor-sdk` 的小程序)公众平台配置。
|
|
4
|
-
> **不是**和缓业务 API 域名(如 `sec.hh-medic.com`),本文仅覆盖 **腾讯 IM**。
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## 1. 背景与依据
|
|
9
|
-
|
|
10
|
-
| 项 | 说明 |
|
|
11
|
-
|----|------|
|
|
12
|
-
| SDK 形态 | 内置 `tim-wx.js`(等同 npm **`tim-wx-sdk@2.27.6`**) |
|
|
13
|
-
| IM SDKAppID | **`1400073238`**(与 `hh-doctor-sdk` 内 `im-manager.js` 一致) |
|
|
14
|
-
| 配置入口 | [微信公众平台](https://mp.weixin.qq.com) → **开发 → 开发管理 → 开发设置 → 服务器域名** |
|
|
15
|
-
| 官方域名表 | [即时通信 IM - 小程序域名配置](https://cloud.tencent.com/document/product/269/117335)(与 2.x 小程序 TIM 通用;V4 文档表最全) |
|
|
16
|
-
| 典型现象 | 体验版 **关闭调试** 后 IM 推送不生效、医助回复不刷新;**开启调试** 正常 → 多为 **socket 合法域名未配** |
|
|
17
|
-
|
|
18
|
-
说明:体验版/正式版 **不会** 像开发者工具那样「不校验合法域名」,必须配齐下列白名单。
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## 2. 配置优先级
|
|
23
|
-
|
|
24
|
-
| 优先级 | 类型 | 用途 |
|
|
25
|
-
|--------|------|------|
|
|
26
|
-
| **P0 必配** | **socket 合法域名** | IM 长连接 WebSocket,收自定义消息(如 `doctorReply`) |
|
|
27
|
-
| **P0 必配** | **request 合法域名** | IM 登录、拉配置、上报等 HTTPS |
|
|
28
|
-
| P1 按需 | uploadFile 合法域名 | IM 内发送图片/文件/语音等 |
|
|
29
|
-
| P1 按需 | downloadFile 合法域名 | IM 内下载媒体资源 |
|
|
30
|
-
|
|
31
|
-
当前名医 SDK 场景:**医助回复刷新** 至少完成 **P0(socket + request)**。
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## 3. socket 合法域名(P0,共 5 个)
|
|
36
|
-
|
|
37
|
-
在「**socket 合法域名**」中新增(保留原有业务域名,勿删):
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
wss://wss.im.tencent.cn
|
|
41
|
-
wss://wssv6.im.qcloud.com
|
|
42
|
-
wss://wss.tim.qq.com
|
|
43
|
-
wss://wss.im.qcloud.com
|
|
44
|
-
wss://1400073238w4c.my-imcloud.com
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
> 最后一条为 SDKAppID **1400073238** 的 IM 独立域名(文档:`wss://${SDKAppID}w4c.my-imcloud.com`)。
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
## 4. request 合法域名(P0,共 12 个)
|
|
52
|
-
|
|
53
|
-
在「**request 合法域名**」中新增:
|
|
54
|
-
|
|
55
|
-
```
|
|
56
|
-
https://web.sdk.qcloud.com
|
|
57
|
-
https://boce-cdn.my-imcloud.com
|
|
58
|
-
https://api.im.qcloud.com
|
|
59
|
-
https://events.im.qcloud.com
|
|
60
|
-
https://webim.tim.qq.com
|
|
61
|
-
https://wss.im.qcloud.com
|
|
62
|
-
https://wssv6.im.qcloud.com
|
|
63
|
-
https://wss.tim.qq.com
|
|
64
|
-
https://web.sdk.cloud.tencent.cn
|
|
65
|
-
https://web.sdk.tencent.cn
|
|
66
|
-
https://wss.im.tencent.cn
|
|
67
|
-
https://1400073238w4c.my-imcloud.com
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
> 最后一条为 SDKAppID **1400073238** 的 IM 独立 HTTPS 域名。
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
## 5. uploadFile 合法域名(P1,IM 发图/文件时需要)
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
https://cnv6.rich.my-imcloud.com
|
|
78
|
-
https://1400073238-cn.rich.my-imcloud.com
|
|
79
|
-
https://cn.rich.my-imcloud.com
|
|
80
|
-
https://cn.imrich.qcloud.com
|
|
81
|
-
https://cos.ap-shanghai.myqcloud.com
|
|
82
|
-
https://cos.ap-shanghai.tencentcos.cn
|
|
83
|
-
https://cos.ap-guangzhou.myqcloud.com
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
## 6. downloadFile 合法域名(P1,IM 下载媒体时需要)
|
|
89
|
-
|
|
90
|
-
```
|
|
91
|
-
https://cnv6.rich.my-imcloud.com
|
|
92
|
-
https://1400073238-cn.rich.my-imcloud.com
|
|
93
|
-
https://cn.rich.my-imcloud.com
|
|
94
|
-
https://cn.imrich.qcloud.com
|
|
95
|
-
https://cos.ap-shanghai.myqcloud.com
|
|
96
|
-
https://cos.ap-shanghai.tencentcos.cn
|
|
97
|
-
https://cos.ap-guangzhou.myqcloud.com
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## 7. 操作注意
|
|
103
|
-
|
|
104
|
-
1. **配置对象**:必须是 **宿主小程序** AppID,不是和缓名医 SDK 演示工程。
|
|
105
|
-
2. **保存后**:等待约 **5~10 分钟** 再测;体验版请 **关闭「打开调试」** 验证。
|
|
106
|
-
3. **第三方代发布**:若小程序由第三方平台发版,域名可能以 **第三方平台账号下登记的域名** 为准,需在第三方侧同步添加上述域名。
|
|
107
|
-
4. **额度**:服务器域名每月修改次数有限(微信规则),建议一次性按上表合并提交。
|
|
108
|
-
5. **格式**:按腾讯文档填写 **带协议** 的完整域名(`https://` / `wss://`);`wss` 域名 **无需** 配置端口。
|
|
109
|
-
6. **与业务域名关系**:和缓订单、图片等 **业务 request 域名** 仍需单独保留,本文列表 **追加** 即可。
|
|
110
|
-
|
|
111
|
-
---
|
|
112
|
-
|
|
113
|
-
## 8. 验收建议
|
|
114
|
-
|
|
115
|
-
1. 体验版 **关调试**,进入咨询详情页,等待 IM 登录(可配合实时日志/statLog:`登录腾讯IM完成`、`IM SDK Ready`)。
|
|
116
|
-
2. 医助回复后,详情页应自动刷新信息流(自定义消息 `doctorReply`)。
|
|
117
|
-
3. 若仍失败:在 vConsole/实时日志中查看是否有 **socket / 域名不在合法列表** 类报错。
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
## 9. 参考链接
|
|
122
|
-
|
|
123
|
-
- [腾讯云 IM - 小程序 & uni-app(域名配置章节)](https://cloud.tencent.com/document/product/269/117335)
|
|
124
|
-
- [微信 - 小程序网络与服务器域名](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)
|
|
125
|
-
- [tim-wx-sdk 2.27.6(npm)](https://www.npmjs.com/package/tim-wx-sdk/v/2.27.6)
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
|
-
文档整理:和缓名医小程序 SDK 项目组 · 对应 `hh-doctor-sdk` 内置 TIM **2.27.6**
|