Commit aada0365 authored by xd's avatar xd

精准营销token未获取到

parent 4af504e3
......@@ -15,6 +15,6 @@
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<!-- <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> -->
</body>
</html>
This diff is collapsed.
......@@ -18,13 +18,14 @@ async function getXToken() {
corpId: INFO.corpId,
agentId: INFO.agentId,
}
console.log('%c--->getXToken: PD =', 'background: orange;', postData)
await wxRequest('/workWx/auth/oauth2/getAccessToken', qs.stringify(postData),'get').then(res => {
alert('获取token')
await wxRequest('/workWx/auth/oauth2/getAccessToken', postData,'get').then(res => {
if (res.result === 'success') {
alert('token获取成功')
sessionStorage.setItem('XToken', res.data)
console.log('%c--->getXToken: RD =', 'background: limegreen;', res)
} else {
alert('token获取失败')
console.log('%c--->getXToken: N/A. ', 'background: red;')
// this.$message({
......@@ -33,11 +34,13 @@ async function getXToken() {
// })
}
}).catch(err => {
alert('TOKEN失败')
console.log('!==>getXToken: err:', err)
})
}
function isIosOrAndroid() {
alert('isIosOrAndroid')
let u = navigator.userAgent;
let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 // android终端
let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios终端
......@@ -52,15 +55,12 @@ function isIosOrAndroid() {
}
Vue.prototype.getAgentAuth = function () {
zlog('%c--->IN: getAgentAuth: location.href =', 'color: orange;', location.href)
// alert(`--->zCommon.js: IN.`)
let postData = {
// businessId: sessionStorage.getItem('businessId'),
// pageUrl: encodeURIComponent(this.isIosOrAndroid() === 'android' ? location.href.split('#')[0] : window.initUrl)
pageUrl: encodeURIComponent(location.href.split('#')[0])
}
// alert(`--->zCommon.js: postData =${JSON.stringify(postData)}`)
alert(`--->zCommon.js: postData =${JSON.stringify(postData)}`)
let header = {
token: sessionStorage.getItem('XToken'),
......@@ -74,7 +74,7 @@ Vue.prototype.getAgentAuth = function () {
wxRequest('/workWx/auth/base/getJsSdkSignature', qs.stringify(postData), header)
.then(res => {
// alert(`--->zCommon.js: getJsSdkSignature: then.`)
// alert(`--->zCommon.js: getJsSdkSignature: then: res =${JSON.stringify(res)}`)
alert(`--->zCommon.js: getJsSdkSignature: then: res =${JSON.stringify(res)}`)
if (res.result === 'success') {
console.log('%c--->getAgentAuth: getJsSdkSignature: RD =', 'background: limegreen;', res.data)
......@@ -83,29 +83,33 @@ Vue.prototype.getAgentAuth = function () {
let config = res.data
wx.config({
beta: true,
debug: false, //调试的时候可以开启
debug: true, //调试的时候可以开启
appId: config.jsApiSignature.appId, // 必填,公众号的唯一标识
timestamp: config.jsApiSignature.timestamp, // 必填,生成签名的时间戳
nonceStr: config.jsApiSignature.nonceStr, // 必填,生成签名的随机串
signature: config.jsApiSignature.signature, // 必填,签名
// 根据自己的需求,填写 jsapilist 内容
jsApiList: ['agentConfig']
jsApiList: ['agentConfig', 'sendChatMessage'],
success: function(res) {
},
fail: function(err) {
}
})
// alert(`--->zCommon.js: getJsSdkSignature: then: wx.config: end.`)
alert(`--->zCommon.js: getJsSdkSignature: then: wx.config: end.`)
wx.ready(function () {
zlog('%c--->getAgentAuth: getJsSdkSignature: Ready.', 'color: red;')
// alert(`--->zCommon.js: getJsSdkSignature: then: wx.ready: IN.`)
alert(`--->zCommon.js: getJsSdkSignature: then: wx.ready: IN.`)
// JS-SDK配置信息验证失败时会进入此方法
wx.error(function (res) {
// alert("JS-SDK配置信息验证失败 \r\n" + JSON.stringify(res));
alert('sdk配置失败')
})
// 配置成功后验证API接口在当前客户端是否支持:判断当前客户端版本是否支持指定JS接口
wx.checkJsApi(
{
jsApiList: ['agentConfig', 'sendChatMessage'],
jsApiList: ['config', 'agentConfig', 'sendChatMessage'],
success: function (res) {
if (res.errMsg != "checkJsApi:ok") {
// alert("JS-SDK接口检测失败:" + JSON.stringify(res));
......@@ -116,7 +120,7 @@ Vue.prototype.getAgentAuth = function () {
// alert(`!-->zCommon.js: getJsSdkSignature: then: wx.ready: wx.checkJsApi: getAgentJsSdkSignature: res.`)
// alert(`!-->zCommon.js: getJsSdkSignature: then: wx.ready: wx.checkJsApi: getAgentJsSdkSignature: res =${JSON.stringify(res)}`)
// alert('getAgentJsSdkSignature:ok')
alert('getAgentJsSdkSignature:ok')
if (res.result === 'success') {
let agentConfig = res.data
wx.agentConfig({
......@@ -127,6 +131,7 @@ Vue.prototype.getAgentAuth = function () {
signature: agentConfig.agentJsApiSignature.signature,// 必填,签名,agentConfig所以为应用签名
jsApiList: ['sendChatMessage'], //必填
success: function (res) {
alert('agentConfigSuccess')
// alert(`!-->zCommon.js: getJsSdkSignature: then: wx.ready: wx.checkJsApi: getAgentJsSdkSignature: wx.agentConfig: res.`)
// alert(`!-->zCommon.js: getJsSdkSignature: then: wx.ready: wx.checkJsApi: getAgentJsSdkSignature: wx.agentConfig: res =${JSON.stringify(res)}`)
// alert('agentConfig:ok')
......@@ -134,9 +139,10 @@ Vue.prototype.getAgentAuth = function () {
// 回调
//1、发起申请申请时后,审批状态发生变化时
//2、发起申请申请时后,在“审批中”状态,有任意审批人进行审批操作时
// alert('wx.agentConfig 回调'+res.errMsg);
alert('wx.agentConfig 回调'+res.errMsg);
},
fail: function (res) {
alert('agentConfigFailed')
// alert('回调失败:'+res.errMsg)
if (res.errMsg.indexOf('is not a function') > -1) {
alert('<i class="weui-icon-warn">版本过低请升级</i>')
......@@ -185,7 +191,7 @@ function configWx(to) {
let config = res.data
wx.config({
beta: true,
debug: false, //调试的时候可以开启
debug: true, //调试的时候可以开启
appId: config.jsApiSignature.appId, // 必填,公众号的唯一标识
timestamp: config.jsApiSignature.timestamp, // 必填,生成签名的时间戳
nonceStr: config.jsApiSignature.nonceStr, // 必填,生成签名的随机串
......@@ -196,17 +202,16 @@ function configWx(to) {
wx.ready(function () {
// JS-SDK配置信息验证失败时会进入此方法
wx.error(function (res) {
// alert("JS-SDK配置信息验证失败 \r\n" + JSON.stringify(res))
})
// 配置成功后验证API接口在当前客户端是否支持:判断当前客户端版本是否支持指定JS接口
wx.checkJsApi({
jsApiList: ['agentConfig', 'getCurExternalContact'],
success: function (res) {
// alert(`--->wx.checkJsApi: success. res =${JSON.stringify(res)}`);
alert(`--->wx.checkJsApi: success. res =${JSON.stringify(res)}`);
// router.push(to)
if (res.errMsg != "checkJsApi:ok") {
// alert("JS-SDK接口检测失败:" + JSON.stringify(res));
alert("JS-SDK接口检测失败:" + JSON.stringify(res));
return false;
}
}
......@@ -232,7 +237,7 @@ function configWx(to) {
signature: agentConfig.agentJsApiSignature.signature,// 必填,签名,agentConfig所以为应用签名
jsApiList: ['getCurExternalContact'], //必填
success: function (res) {
// alert('agentConfig:ok')
alert('agentConfig:ok')
// alert(`--->configWx/getJsSdkSignature/getAgentJsSdkSignature: then: agentConfig: res =${res}`)
// alert(`--->configWx/getJsSdkSignature/getAgentJsSdkSignature: then: agentConfig: to =${JSON.stringify(to)}`)
sessionStorage.setItem('zConfigWx', 'Pass')
......@@ -245,11 +250,8 @@ function configWx(to) {
// alert('wx.agentConfig 回调'+res.errMsg);
},
fail: function (res) {
// alert(`--->A: err =${res}`)
// alert(`--->A: err =${JSON.stringify(res)}`)
if (res.errMsg.indexOf('is not a function') > -1) {
// alert('<i class="weui-icon-warn">版本过低请升级</i>')
alert('<i class="weui-icon-warn">版本过低请升级</i>')
}
}
})
......
......@@ -42,9 +42,11 @@ export default {
},
mounted() {
this.getAgentAuth()
this.getList()
},
methods: {
getList() {
alert('getList')
wx.invoke('selectExternalContact', {
"filterType": 0,
},
......
......@@ -125,7 +125,7 @@ export default {
},
mounted() {
this.checkNowMenuBar()
// this.zReadyUserId()
this.zReadyUserId()
this.zTestGetNowUrlInfo()
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment