|
@@ -9,42 +9,44 @@ import { setLocal, getLocal } from './storage'
|
9
|
9
|
*/
|
10
|
10
|
function getAuthInfo(cb?: any, redirect_url?: any) {
|
11
|
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
|
|
- axios.post('/api/h5/auth/commonAuthData', {
|
17
|
|
- corpid: getQueryString('corpid'),
|
18
|
|
- url: location.href.split('#')[0],
|
19
|
|
- }).then((res: any) => {
|
20
|
|
- //构造网页授权链接回调 保存返回信息
|
21
|
|
- if (redirect_url) {
|
22
|
|
- // setLocal('authInfo', JSON.stringify(res.rst))
|
23
|
|
- redirect_url(res.rst)
|
24
|
|
- }
|
25
|
|
- if (cb) {
|
26
|
|
- initEvent(res.rst, cb)
|
27
|
|
- }
|
28
|
|
- }).catch((err) => {
|
29
|
|
- console.log(err, 'err')
|
30
|
|
- })
|
31
|
|
- // }
|
|
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
|
+ axios.post('/api/h5/auth/commonAuthData', {
|
|
17
|
+ corpid: getQueryString('corpid'),
|
|
18
|
+ url: location.href.split('#')[0],
|
|
19
|
+ }).then((res: any) => {
|
|
20
|
+ //构造网页授权链接回调 保存返回信息
|
|
21
|
+ if (redirect_url) {
|
|
22
|
+ setLocal('authInfo', JSON.stringify(res.rst))
|
|
23
|
+ redirect_url(res.rst)
|
|
24
|
+ }
|
|
25
|
+ if (cb) {
|
|
26
|
+ initEvent(res.rst, cb)
|
|
27
|
+ }
|
|
28
|
+ }).catch((err) => {
|
|
29
|
+ console.log(err, 'err')
|
|
30
|
+ })
|
|
31
|
+ }
|
32
|
32
|
}
|
33
|
33
|
|
34
|
34
|
function initEvent(authInfo: any, cb) {
|
35
|
35
|
//在企业微信内部 并企业微信的版本号大约或等于3.0.24时,无须先调用wx.config,可直接wx.agentConfig.
|
36
|
36
|
//文档说明于 https://developer.work.weixin.qq.com/document/path/94313
|
37
|
|
- // if (isWxwork() && isWxwork() != 'false' && compareVersion(isWxwork(), '3.0.24') != -1) {
|
38
|
|
- // initYYConfig(authInfo, cb);//
|
39
|
|
- // } else {
|
40
|
|
- initQYConfig(authInfo, cb);
|
41
|
|
- // }
|
|
37
|
+ if (isWxwork() && isWxwork() != 'false' && compareVersion(isWxwork(), '3.0.24') != -1) {
|
|
38
|
+ alert('不')
|
|
39
|
+ initYYConfig(authInfo, cb);
|
|
40
|
+ } else {
|
|
41
|
+ alert('是')
|
|
42
|
+ initQYConfig(authInfo, cb);
|
|
43
|
+ }
|
42
|
44
|
}
|
43
|
45
|
|
44
|
46
|
function initQYConfig(authInfo, cb) { // 企业
|
45
|
47
|
wx.config({
|
46
|
48
|
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
47
|
|
- debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
49
|
+ debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
48
|
50
|
appId: authInfo.corpid, // 必填,企业微信的corpID
|
49
|
51
|
timestamp: authInfo.timestamp, // 必填,生成签名的时间戳
|
50
|
52
|
nonceStr: authInfo.nonce_str, // 必填,生成签名的随机串
|
|
@@ -63,7 +65,7 @@ function initQYConfig(authInfo, cb) { // 企业
|
63
|
65
|
|
64
|
66
|
function initYYConfig(authInfo, cb) { // 应用
|
65
|
67
|
wx.agentConfig({
|
66
|
|
- debug: false,
|
|
68
|
+ debug: true,
|
67
|
69
|
corpid: authInfo.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
|
68
|
70
|
agentid: authInfo.agent_id, // 必填,企业微信的应用id (e.g. 1000247)
|
69
|
71
|
timestamp: authInfo.timestamp, // 必填,生成签名的时间戳
|