Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xiaomai-cloud-class-web
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaomai-cloud-class
xiaomai-cloud-class-web
Commits
bc24ba05
Commit
bc24ba05
authored
Aug 12, 2021
by
zhujian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
80d0e654
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
105 deletions
+61
-105
src/common/js/wechatApi.js
+61
-105
No files found.
src/common/js/wechatApi.js
View file @
bc24ba05
...
...
@@ -15,121 +15,77 @@ import Service from '@/common/js/service';
export
default
class
WechatApi
{
static
async
initConfig
(
params
=
{
isAgentConfig
:
false
,
url
:
''
})
{
if
(
Platform
.
isWorkWx
())
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
Service
.
Hades
(
'anon/hades/getWxCorpJSAPISignature'
,
{
storeId
:
User
.
getStoreId
(),
url
:
window
.
location
.
href
.
split
(
'#'
)[
0
],
}).
then
((
result
)
=>
{
const
res
=
result
.
result
;
wx
.
config
({
beta
:
true
,
// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug
:
false
,
// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId
:
res
.
appId
,
// 必填,企业微信的corpID
timestamp
:
res
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
res
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
res
.
signature
,
// 必填,签名,见 附录-JS-SDK使用权限签名算法
jsApiList
:
[
'chooseImage'
],
})
wx
.
error
((
err
)
=>
{
console
.
log
(
'getWxCorpJSAPISignatureErr'
,
err
)
});
wx
.
ready
(()
=>
{
console
.
log
(
'微信注册成功'
)
Service
.
Hades
(
'anon/hades/getWxWorkJSAPISignature'
,
{
storeId
:
User
.
getStoreId
(),
url
:
window
.
location
.
href
.
split
(
'#'
)[
0
],
}).
then
((
result2
)
=>
{
const
res2
=
result2
.
result
;
console
.
log
(
'开始注册agent'
)
wx
.
agentConfig
({
corpid
:
res2
.
corpid
,
// 必填,企业微信的corpid,必须与当前登录的企业一致
agentid
:
res2
.
agentid
,
// 必填,企业微信的应用id (e.g. 1000247)
timestamp
:
res2
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
res2
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
res2
.
signature
,
// 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList
:
[
'selectExternalContact'
,
'getCurExternalContact'
,
'getContext'
,
'shareToExternalContact'
,
'sendChatMessage'
,
'shareToExternalChat'
,
'startLiving'
,
'replayLiving'
],
success
:
(
res
)
=>
{
console
.
log
(
res
,
'res-agentconfig'
);
console
.
info
(
'window.WWOpenData'
,
window
.
WWOpenData
);
resolve
(
res
);
},
fail
:
(
err
)
=>
{
console
.
log
(
1213545344545
)
console
.
log
(
err
,
'err-agentconfig'
);
reject
(
err
);
},
});
});
})
Service
.
Hades
(
'anon/hades/getWxCorpJSAPISignature'
,
{
storeId
:
User
.
getStoreId
(),
url
:
window
.
location
.
href
.
split
(
'#'
)[
0
],
}).
then
((
result
)
=>
{
const
res
=
result
.
result
;
wx
.
config
({
beta
:
true
,
// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug
:
false
,
// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId
:
res
.
appId
,
// 必填,企业微信的corpID
timestamp
:
res
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
res
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
res
.
signature
,
// 必填,签名,见 附录-JS-SDK使用权限签名算法
jsApiList
:
[
'scanQRCode'
],
});
})
wx
.
ready
(()
=>
{
Service
.
Hades
(
'anon/hades/getWxWorkJSAPISignature'
,
{
storeId
:
User
.
getStoreId
(),
url
:
window
.
location
.
href
.
split
(
'#'
)[
0
],
}).
then
((
result2
)
=>
{
const
res2
=
result2
.
result
;
wx
.
agentConfig
({
corpid
:
res2
.
corpid
,
// 必填,企业微信的corpid,必须与当前登录的企业一致
agentid
:
res2
.
agentid
,
// 必填,企业微信的应用id (e.g. 1000247)
timestamp
:
res2
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
res2
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
res2
.
signature
,
// 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList
:
[
'selectExternalContact'
,
'getCurExternalContact'
,
'getContext'
,
'shareToExternalContact'
,
'sendChatMessage'
,
'shareToExternalChat'
,
'startLiving'
,
'replayLiving'
],
success
:
(
res
)
=>
{
console
.
log
(
res
,
'agentConfig 成功'
,
'res-agentconfig'
);
resolve
(
res
);
},
fail
:
(
err
)
=>
{
console
.
log
(
1213545344545
)
console
.
log
(
err
,
'err-agentconfig'
);
}
else
{
if
(
params
.
isAgentConfig
)
{
console
.
log
(
32132132
,
'cesgu'
)
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
Service
.
Hades
(
'anon/hades/getWxWorkJSAPISignature'
,
{
storeId
:
User
.
getStoreId
(),
url
:
params
.
url
,
}).
then
((
result2
)
=>
{
const
res2
=
result2
.
result
;
this
.
agentConfig
({
corpid
:
res2
.
corpid
,
// 必填,企业微信的corpid,必须与当前登录的企业一致
agentid
:
res2
.
agentid
,
// 必填,企业微信的应用id (e.g. 1000247)
timestamp
:
res2
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
res2
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
res2
.
signature
,
// 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList
:
[
'selectExternalContact'
,
'getCurExternalContact'
,
'getContext'
,
'shareToExternalContact'
,
'sendChatMessage'
,
'shareToExternalChat'
,
'startLiving'
,
'replayLiving'
],
success
:
(
res
)
=>
{
console
.
log
(
res
,
'res-agentconfig'
);
console
.
info
(
'window.WWOpenData'
,
window
.
WWOpenData
);
resolve
(
res
);
},
fail
:
(
err
)
=>
{
console
.
log
(
1213545344545
)
console
.
log
(
err
,
'err-agentconfig'
);
reject
(
err
);
},
});
},
});
});
}
}
}
static
async
config
(
config
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
wx
.
config
(
config
);
wx
.
ready
(
resolve
);
wx
.
error
(
reject
);
})
}
static
async
agentConfig
(
config
)
{
wx
.
agentConfig
({
...
config
});
}
});
wx
.
error
((
err
)
=>
{
console
.
log
(
'getWxCorpJSAPISignature'
,
err
)
});
}
else
{
Service
.
Hades
(
'anon/hades/getWxWorkJSAPISignature'
,
{
storeId
:
User
.
getStoreId
(),
url
:
window
.
location
.
href
.
split
(
'#'
)[
0
],
}).
then
((
result2
)
=>
{
const
res2
=
result2
.
result
;
wx
.
agentConfig
({
corpid
:
res2
.
corpid
,
// 必填,企业微信的corpid,必须与当前登录的企业一致
agentid
:
res2
.
agentid
,
// 必填,企业微信的应用id (e.g. 1000247)
timestamp
:
res2
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
res2
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
res2
.
signature
,
// 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList
:
[
'selectExternalContact'
,
'getCurExternalContact'
,
'getContext'
,
'shareToExternalContact'
,
'sendChatMessage'
,
'shareToExternalChat'
,
'startLiving'
,
'replayLiving'
],
success
:
(
res
)
=>
{
console
.
log
(
res
,
'agentConfig 成功'
,
'res-agentconfig'
);
resolve
(
res
);
},
fail
:
(
err
)
=>
{
console
.
log
(
1213545344545
)
console
.
log
(
err
,
'err-agentconfig'
);
static
getCurExternalContact
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
wx
.
ready
(()
=>
{
wx
.
invoke
(
'getCurExternalContact'
,
{},
function
(
res
)
{
if
(
res
.
err_msg
==
'getCurExternalContact:ok'
)
{
resolve
(
res
.
userId
);
//返回当前外部联系人userId
}
else
{
reject
(
res
.
err_msg
);
//错误处理
}
},
});
});
}
);
}
}
static
getContext
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
wx
.
ready
(()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment