|
@@ -1,6 +1,5 @@
|
1
|
1
|
import axios from './axios';
|
2
|
2
|
import { getQueryString } from './common'
|
3
|
|
-import { setLocal, getLocal } from './storage'
|
4
|
3
|
|
5
|
4
|
/**
|
6
|
5
|
* jsapi通用授权数据
|
|
@@ -8,45 +7,32 @@ import { setLocal, getLocal } from './storage'
|
8
|
7
|
* @param redirect_url 构造网页授权链接回跳 目的是根据回跳拿到code
|
9
|
8
|
*/
|
10
|
9
|
function getAuthInfo(cb?: any, redirect_url?: any) {
|
11
|
|
- //回跳回来后,拿到本地存储的信息去走授权
|
12
|
|
- // if (getLocal('authInfo') && getQueryString('againJump')) {
|
13
|
|
- // const local_auth_info: string = getLocal('authInfo') || null;
|
14
|
|
- // initEvent(JSON.parse(local_auth_info), cb)
|
15
|
|
- // } else {
|
16
|
10
|
axios.post('/api/h5/auth/commonAuthData', {
|
17
|
11
|
corpid: getQueryString('corpid'),
|
18
|
12
|
url: location.href.split('#')[0],
|
19
|
13
|
}).then((res: any) => {
|
20
|
14
|
//构造网页授权链接回调 保存返回信息
|
21
|
15
|
if (redirect_url) {
|
22
|
|
- setLocal('authInfo', JSON.stringify(res.rst))
|
23
|
16
|
redirect_url(res.rst)
|
24
|
17
|
}
|
25
|
18
|
if (cb) {
|
26
|
|
- initEvent(res.rst, cb)
|
|
19
|
+ //在企业微信内部 并企业微信的版本号大约或等于3.0.24时,无须先调用wx.config,可直接wx.agentConfig.
|
|
20
|
+ //文档说明于 https://developer.work.weixin.qq.com/document/path/94313
|
|
21
|
+ if (isWxwork() && isWxwork() != 'false' && compareVersion(isWxwork(), '3.0.24') != -1) {
|
|
22
|
+ initYYConfig(res.rst, cb);
|
|
23
|
+ } else {
|
|
24
|
+ initQYConfig(res.rst, cb);
|
|
25
|
+ }
|
27
|
26
|
}
|
28
|
27
|
}).catch((err) => {
|
29
|
28
|
console.log(err, 'err')
|
30
|
29
|
})
|
31
|
|
- // }
|
32
|
|
-}
|
33
|
|
-
|
34
|
|
-function initEvent(data, cb) {
|
35
|
|
- //在企业微信内部 并企业微信的版本号大约或等于3.0.24时,无须先调用wx.config,可直接wx.agentConfig.
|
36
|
|
- //文档说明于 https://developer.work.weixin.qq.com/document/path/94313
|
37
|
|
- if (isWxwork() && isWxwork() != 'false' && compareVersion(isWxwork(), '3.0.24') != -1) {
|
38
|
|
- alert('不' + JSON.stringify(data))
|
39
|
|
- initYYConfig(data, cb);
|
40
|
|
- } else {
|
41
|
|
- alert('是')
|
42
|
|
- initQYConfig(data, cb);
|
43
|
|
- }
|
44
|
30
|
}
|
45
|
31
|
|
46
|
32
|
function initQYConfig(authInfo, cb) { // 企业
|
47
|
33
|
wx.config({
|
48
|
34
|
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
49
|
|
- debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
35
|
+ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
50
|
36
|
appId: authInfo.corpid, // 必填,企业微信的corpID
|
51
|
37
|
timestamp: authInfo.timestamp, // 必填,生成签名的时间戳
|
52
|
38
|
nonceStr: authInfo.nonce_str, // 必填,生成签名的随机串
|
|
@@ -64,9 +50,8 @@ function initQYConfig(authInfo, cb) { // 企业
|
64
|
50
|
}
|
65
|
51
|
|
66
|
52
|
function initYYConfig(authInfo, cb) { // 应用
|
67
|
|
- alert('到了')
|
68
|
53
|
wx.agentConfig({
|
69
|
|
- debug: true,
|
|
54
|
+ debug: false,
|
70
|
55
|
corpid: authInfo.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
|
71
|
56
|
agentid: authInfo.agent_id, // 必填,企业微信的应用id (e.g. 1000247)
|
72
|
57
|
timestamp: authInfo.timestamp, // 必填,生成签名的时间戳
|
|
@@ -74,12 +59,10 @@ function initYYConfig(authInfo, cb) { // 应用
|
74
|
59
|
signature: authInfo.app_signature, // 必填,签名,见附录-JS-SDK使用权限签名算法 应用签名
|
75
|
60
|
jsApiList: ['getCurExternalContact', 'sendChatMessage'], // 必填,传入需要使用的接口名称
|
76
|
61
|
success: function (res) {
|
77
|
|
- alert(JSON.stringify(res) + 'success')
|
78
|
62
|
console.log(res, 'YYready')
|
79
|
63
|
cb ? cb(authInfo) : ''
|
80
|
64
|
},
|
81
|
65
|
fail: function (res) {
|
82
|
|
- alert(JSON.stringify(res))
|
83
|
66
|
if (res.errMsg.indexOf('function not exist') > -1) {
|
84
|
67
|
alert('版本过低请升级')
|
85
|
68
|
}
|