最近在寫一個小程序,其中使用到了wx.agentConfig獲取“l(fā)aunchMiniprogram”,打開小程序頁面。
然后在安卓中可以正常打開,在蘋果手機中打不開。
期間更換了n次引入的js,頭大最后發(fā)現(xiàn)是授權(quán)的url在蘋果手機和安卓中獲取的不一樣,導(dǎo)致頁面授權(quán)簽名報錯40093
{"errMsg": "agentConfig:invalid signature more info at https://open.work.weixin.qq.com/devtool/query?e=40093"}
以下為簡略代碼
第一部,引入的wx鏈接
<script src="https://res.wx.qq.com/wwopen/js/jsapi/jweixin-1.0.0.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
第二部授權(quán)url,問題就出現(xiàn)在這 login_url 的最后 #wechat_redirect文章來源:http://www.zghlxwxcb.cn/news/detail-741495.html
methods: {
redirect() {
// 當(dāng)前企業(yè)的 corp_id
const corp_id = 'xxxxxxxxx';
// 重定向 URL
const redirect_uri = encodeURI('http://xxxx.xxxxx-xxxxx.cn/#/wxGoApplet');
// 授權(quán)鏈接 URL
const login_url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${corp_id}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
// 向授權(quán)鏈接 URL 跳轉(zhuǎn)
window.location = login_url;
},
}
//第三步,在/wxGoApplet頁面中跳轉(zhuǎn)小程序文章來源地址http://www.zghlxwxcb.cn/news/detail-741495.html
getOauthUser() {
this.loading = true;
let that = this;
let url = window.location.href;
that.redirect_uri = url.split("#")[0];
let p = url.split("?")[1];
let query = new URLSearchParams(p);
that.code = query.get("code");
// 在這里進行判斷,在蘋果手機中url會出現(xiàn)字符轉(zhuǎn)碼 #wechat_redirect 變 %23#wechat_redirect,查詢?nèi)绻芯瓦M行替換,安卓手機中不會出現(xiàn)#wechat_redirect,故沒有這個問題
if (that.redirect_uri.indexOf("%23") > -1) {
that.redirect_uri = that.redirect_uri.replace("%23", "%2523");
}
// 請求后端接口獲取簽名認證
getWeixinSignature(encodeURIComponent(that.redirect_uri), "app").then(
(res) => {
// this.meg1 = res.data.data;
if (res.data.code === 200) {
that.openDefaultBrowser(res.data.data);
}
}
);
},
openDefaultBrowser(info) {
// 初始化qywx-js-sdk
let that = this;
wx.agentConfig({
corpid: "xxx",
agentid: 000000, // 數(shù)據(jù)格式為number
timestamp: info.timestamp,
nonceStr: info.noncestr,
signature: info.signature,
jsApiList: ["launchMiniprogram"], // 需要使用的JS接口列表
success: function (res) {
wx.invoke(
"launchMiniprogram",
{
appid: "xxxxxxx", // 需跳轉(zhuǎn)的小程序appid
path:
"pages/login/login?page=", // 所需跳轉(zhuǎn)的小程序內(nèi)頁面路徑及參數(shù)。非必填|| page 為需要跳到小程序的頁面路徑
},
(result) => {
that.msg = result;
setTimeout(() => {
// window.close();
wx.closeWindow(); // 關(guān)閉中間的H5頁面
}, 1000);
if (result.err_msg == "openDefaultBrowser:ok") {
// 打開默認瀏覽器成功后的回調(diào)函數(shù)
console.log("打開瀏覽器~~~result", result);
}
}
);
},
fail: function (res) {
// this.meg5 = res;
console.log(res);
that.fail = res;
if (res.errMsg.indexOf("function not exist") > -1) {
alert("版本過低請升級");
}
},
});
},
到了這里,關(guān)于微信小程序在蘋果手機中打不開小程序頁面,wx.agentConfig沒有執(zhí)行的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!