首页 > 其他 > 详细

小程序获取openid 出现null,{"errcode":40163,"errmsg":"code been used, hints: [ req_id: WNUzlA0105th41 ]"}

时间:2018-05-13 14:19:59      阅读:1972      评论:0      收藏:0      [点我收藏+]
//根据微信提供的接口,请求得到openid和session_id
public class UserInfoUtils {
 
  public String getKey(String appid, String secret, String code) {
    getKeyURL=String.format(getKeyURL,appid,secret,code);
    String respone = MyHttpsUtil.httpsRequest(getKeyURL, "GET", null);
    return respone;
  }
}
 
相同code,在请求微信接口时,只能请求一次,再次请求就会返回openid为null的错误:{"errcode":40163,"errmsg":"code been used, hints: [ req_id: WNUzlA0105th41 ]"}
 
测试时在微信开发工具上清除缓存后,重新请求就可以了。
 
 
但是测试时还有一个问题:
public class UserInfoUtils {
 
  public  static String getKey(String appid, String secret, String code) {
  getKeyURL=String.format(getKeyURL,appid,secret,code);
  String respone = MyHttpsUtil.httpsRequest(getKeyURL, "GET", null);
  return respone;
  }
}
 
就是我在URL和方法上都加了static关键字,调用静态方法时,就算清除了缓存,code也不一样了,但还是会报错:{"errcode":40163,"errmsg":"code been used, hints: [ req_id: WNUzlA0105th41 ]"}。
 
解决方法:将static关键字去掉就ok了,因为静态变量会保存getKeyURL,之后调用方法获得的值是上次转换后的值,%s被转换成具体的值,之后调用format方法就不能给URL赋值了。
 

小程序获取openid 出现null,{"errcode":40163,"errmsg":"code been used, hints: [ req_id: WNUzlA0105th41 ]"}

原文:https://www.cnblogs.com/dingxu/p/9032004.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!