在政务微信的H5页面调用wx.config没响应?
相同的代码,我通过手机微信浏览器打开,会提示我签名失效,但是在政务微信了里面就任何反应都没有,这个现象和我在Pc端使用chrome一致,但是打印userAgent有看不出来不是 我手机上的微信 [图片] 政务微信 [图片] import CryptoJS from 'crypto-js'
import wxApi from '@/api/wxApi'
import { showFailToast } from 'vant'
export default function (onSuccess = () => {}) {
return {
onStart() {
try {
console.log(window.navigator.userAgent)
console.log(window.location.href)
let isWxAuthSuccess = ref(false)
let signature = ref(null)
let noncestr = ref('')
let timestamp = ref('')
let queryParams = ref('')
let jsapi_ticket
function randomString(len) {
len = len || 32
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
var maxPos = $chars.length
var pwd = ''
for (let i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos))
}
return pwd
}
// 生成签名
function createSignature() {
noncestr.value = randomString(16)
timestamp.value = Date.now()
queryParams.value = randomString(32).toLowerCase()
let str = `jsapi_ticket=${jsapi_ticket}&noncestr=${noncestr.value}×tamp=${timestamp.value}&url=${window.location.href}`
console.log(str)
signature.value = CryptoJS.SHA1(str).toString()
}
wxApi.getJsapiTicket().then((rsp) => {
console.log(rsp.result)
if (rsp.success) {
jsapi_ticket = rsp.result
createSignature()
console.log('调用read方法')
wx.ready(function () {
console.log('微信鉴权成功')
isWxAuthSuccess.value = true
wx.getLocation({
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
console.log(res)
onSuccess(res)
},
})
})
wx.error(function (res) {
console.error('wx', res)
})
let configParams = {
beta: false,
debug: true,
appId: 'wwc20afc2f93482ccb',
timestamp: timestamp.value,
nonceStr: noncestr.value,
signature: signature.value,
jsApiList: ['getLocation'],
}
wx.config(configParams)
console.log('config方法调用成功')
}
})
} catch (error) {
console.error(error)
}
},
}
}