https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html
直接看下面这个api
第二步:通过code换取网页授权access_token
报错信息:
{return_msg=mch_id参数格式错误, return_code=FAIL}
下面是源码:
p.s.刚开始用GET请求,结果报错要求要POST
另外这个代码是专门拿出来测试用的,code用了常量,仅为测试为何会报mch_id参数格式错误。maps便是上面的报错内容。
String url = MyWXPayConfig.getQueryOrderUrl()+"?appid="+wxPayAppConfig.getJsapiAppID()+"&secret="+wxPayAppConfig.getAppSecret()+"&code=0515Nvll2cbJg74a94nl2fTtIQ15NvlN&grant_type=authorization_code";
String result;
Map<String,String> mapJson = new HashMap<>();
mapJson.put("appid",wxPayAppConfig.getJsapiAppID());
mapJson.put("secret",wxPayAppConfig.getAppSecret());
mapJson.put("code","0515Nvll2cbJg74a94nl2fTtIQ15NvlN");
mapJson.put("grant_type","grant_type");
String json = "";
try {
json = WXPayUtils.mapToXml(mapJson);
} catch (Exception e) {
e.printStackTrace();
baseEntity.setStatus(2);
baseEntity.setMessage("获取open_id请求入参转码时异常");
return baseEntity;
}
try {
result = HttpClient.sendPostDataByJson(url,json);
} catch (IOException e) {
e.printStackTrace();
baseEntity.setStatus(2);
baseEntity.setMessage("获取open_id请求时异常:异常原因:"+e.getMessage());
return baseEntity;
}
Map maps ;
try {
maps = WXPayUtils.xmlToMap(result);;
}catch (Exception e){
e.printStackTrace();
baseEntity.setStatus(2);
baseEntity.setMessage("获取open_id请求时异常:异常原因:"+e.getMessage());
return baseEntity;
}
看来错误很明显了哈
亮代码
报错信息呢?