|
@@ -1,5 +1,6 @@
|
1
|
1
|
import axios from './axios';
|
2
|
2
|
import { getQueryString } from './common'
|
|
3
|
+
|
3
|
4
|
function getAuthInfo(cb?: any, redirect_url?: any) {//jsapi通用授权数据
|
4
|
5
|
axios.post('/api/h5/auth/commonAuthData', {
|
5
|
6
|
corpid: getQueryString('corpid'),
|
|
@@ -10,7 +11,14 @@ function getAuthInfo(cb?: any, redirect_url?: any) {//jsapi通用授权数据
|
10
|
11
|
redirect_url(res.rst)
|
11
|
12
|
}
|
12
|
13
|
if (cb) {
|
13
|
|
- initQYConfig(res.rst, cb);
|
|
14
|
+ //在企业微信内部 并企业微信的版本号大约或等于3.0.24时,无须先调用wx.config,可直接wx.agentConfig.
|
|
15
|
+ //文档说明于 https://developer.work.weixin.qq.com/document/path/94313
|
|
16
|
+ if (isWxwork() && isWxwork() != 'false' && compareVersion(isWxwork(), '3.0.24') != -1) {
|
|
17
|
+ alert('无须先调用wx.config,可直接wx.agentConfig')
|
|
18
|
+ initYYConfig(res.rst, cb);//
|
|
19
|
+ } else {
|
|
20
|
+ initQYConfig(res.rst, cb);
|
|
21
|
+ }
|
14
|
22
|
}
|
15
|
23
|
}).catch((err) => {
|
16
|
24
|
console.log(err, 'err')
|
|
@@ -25,10 +33,10 @@ function initQYConfig(authInfo, cb) { // 企业
|
25
|
33
|
timestamp: authInfo.timestamp, // 必填,生成签名的时间戳
|
26
|
34
|
nonceStr: authInfo.nonce_str, // 必填,生成签名的随机串
|
27
|
35
|
signature: authInfo.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法 企业签名
|
28
|
|
- jsApiList: ['getCurExternalContact','sendChatMessage'] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
|
|
36
|
+ jsApiList: ['getCurExternalContact', 'sendChatMessage'] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
|
29
|
37
|
})
|
30
|
38
|
wx.ready(function (res) {
|
31
|
|
- console.log( res,'QYready')
|
|
39
|
+ console.log(res, 'QYready')
|
32
|
40
|
initYYConfig(authInfo, cb)
|
33
|
41
|
})
|
34
|
42
|
wx.error(function (res) {
|
|
@@ -45,9 +53,9 @@ function initYYConfig(authInfo, cb) { // 应用
|
45
|
53
|
timestamp: authInfo.timestamp, // 必填,生成签名的时间戳
|
46
|
54
|
nonceStr: authInfo.nonce_str, // 必填,生成签名的随机串
|
47
|
55
|
signature: authInfo.app_signature, // 必填,签名,见附录-JS-SDK使用权限签名算法 应用签名
|
48
|
|
- jsApiList: ['getCurExternalContact','sendChatMessage'], // 必填,传入需要使用的接口名称
|
|
56
|
+ jsApiList: ['getCurExternalContact', 'sendChatMessage'], // 必填,传入需要使用的接口名称
|
49
|
57
|
success: function (res) {
|
50
|
|
- console.log( res,'YYready')
|
|
58
|
+ console.log(res, 'YYready')
|
51
|
59
|
cb ? cb(authInfo) : ''
|
52
|
60
|
},
|
53
|
61
|
fail: function (res) {
|
|
@@ -57,6 +65,38 @@ function initYYConfig(authInfo, cb) { // 应用
|
57
|
65
|
}
|
58
|
66
|
})
|
59
|
67
|
}
|
|
68
|
+function isWxwork() {//判断是否为企业微信,并获取企业微信版本号
|
|
69
|
+ let arr1 = navigator.userAgent.split('wxwork/');
|
|
70
|
+ if (arr1.length > 1) {//是在企业微信内
|
|
71
|
+ return arr1[1].split(' ')[0]
|
|
72
|
+ } else {
|
|
73
|
+ return false
|
|
74
|
+ }
|
|
75
|
+}
|
60
|
76
|
|
|
77
|
+function compareVersion(v1, v2) {//判断两个版本号的大小 (v1 > v2 时返回1; v1 = v2 时返回0; v1 < v2 时返回 -1)
|
|
78
|
+ if (v1 == v2) {
|
|
79
|
+ return 0;
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ const vs1 = v1.split(".").map(a => parseInt(a));
|
|
83
|
+ const vs2 = v2.split(".").map(a => parseInt(a));
|
|
84
|
+
|
|
85
|
+ const length = Math.min(vs1.length, vs2.length);
|
|
86
|
+ for (let i = 0; i < length; i++) {
|
|
87
|
+ if (vs1[i] > vs2[i]) {
|
|
88
|
+ return 1;
|
|
89
|
+ } else if (vs1[i] < vs2[i]) {
|
|
90
|
+ return -1;
|
|
91
|
+ }
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ if (length == vs1.length) {
|
|
95
|
+ return -1;
|
|
96
|
+ } else {
|
|
97
|
+ return 1;
|
|
98
|
+ }
|
|
99
|
+}
|
61
|
100
|
|
62
|
101
|
export default getAuthInfo
|
|
102
|
+
|