java后台-解决小程序的{"errcode":40013,"errmsg":"invalid appid, hints: [ req_id: qECcC0yFe-_ ]"}
出现40013的可能分析:
1、排除访问的连接是否有问题。下面是api中的链接
GET https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
2、链接中的的参数一定是放在url中。
3、参数中的appid secret 一定要前后台保持一致,且正确。
4、小程序-小程序的代码一定是需要发布审核通过后的。
5、https的访问方式是否正确,get请求,https访问。
下面针对的java后台,https的访问方式不正确的解决方法。
调用的小程序接口wx.login --auth.code2Session
对应的api:https://developers.weixin.qq.com/miniprogram/dev/api-backend/auth.code2Session.html
在这个接口中,访问的url:https://api.weixin.qq.com/sns/jscode2session?appid=wxa3da2ea23b3abe82&secret=f620b3db6c6824f5f90eff67af4707d4&js_code=0618MwUE0fuo8d2u9gTE0IkyUE08MwUJ&grant_type=authorization_code
出现报错:
@@[2019-05-06 10:33:16.125] [13] [qtp142638629-13] [INFO ] [com.hualife.insuranceassist.wechat.service.impl.LoginServiceImpl] [com.hualife.insuranceassist.wechat.service.impl.LoginServiceImpl.sendGetReq(LoginServiceImpl.java:97)] 通过微信服务器端返回的接过参数{"errcode":40013,"errmsg":"invalid appid, hints: [ req_id: qECcC0yFe-_ ]"}
错误在于https的get调用出现了问题--
经过一番尝试,终于使用下面的连接中的方法解决了问题。
详情见链接:https://blog.csdn.net/zhoumengshun/article/details/79100053
public static void main(String[] args) {
try {
//请求地址(我这里测试使用淘宝提供的手机号码信息查询的接口)
String address = "https://api.weixin.qq.com/sns/jscode2session?appid=wxa3da2ea23b3abe82&secret=f620b3db6c6824f5f90eff67af4707d4&js_code=0618MwUE0fuo8d2u9gTE0IkyUE08MwUJ&grant_type=authorization_code";
//请求参数
// Map<String, String> params = new HashMap<String, String>();
// params.put("tel", "13777777777");//这是该接口需要的参数
// 调用 get 请求
String res = proxyHttpRequest(address, "GET", null,null);
System.out.println(res);//打印返回参数
res = res.substring(res.indexOf("{"));//截取
JSONObject result = JSONObject.parseObject(res);//转JSON
System.out.println(result.toString());//打印
} catch (Exception e) { // TODO 异常
e.printStackTrace();
}
}