场景: 我方作为平台 ,公众号下接入了10家商户支付 ,登陆时用的是我的appid获取code,正常
在生成订单,支付时,根据商户不同,调取不同的appid去获取code,再传值给后台,后台返回给我openid
这个时候出现, 不管我怎么换appid ,我获取的code都是同一个,就会导致code重复被使用出现报错
vue项目 , 想问一下是不是我获取的时候哪里写错了,还是要如何处理?
CommonMethod.js页
getUrlKey: function(name) {
//TODO 取url参数
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null;
},
PublicApproach.js页
//获取微信code
getCode: function(appId) { // 静默授权,第一次有弹框
this.code='';
var local = window.location.href; // 获取页面url
this.code=CommonMethod.getUrlKey("code"); //截取code
if (this.code == null || this.code === '') { // 如果没有code,则去请求
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.userInfo.appId}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_base&state=${this.userInfo.accessOrgId}#wechat_redirect`
} else {
//拿到code后根据状态不同去调用后端openid的接口
if (this.userInfo.discernId==1){
this.getOpenid(this.code); //获取本机构openid
}else if(this.userInfo.discernId==2){
this.getPayOpenId(this.code); //获取商户openid
}
}
},
以我个人的经验,别说不同appid,同一个appid,不同时间code都绝对不会一样
请仔细检查相关程序代码