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

//根据微信提供的接口,请求得到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赋值了。
 

转载于:https://www.cnblogs.com/dingxu/p/9032004.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值