慕盖茨1413546
2018-08-10 15:16
出现了Exception in thread "main" net.sf.json.JSONException: JSONObject["expires_in"] not found.这个问题
public static AccessToken getAccessToken() throws Exception {
// TODO code application logic here
AccessToken token = new AccessToken();
String url = ACCESS_TOKEN_URL.replace("APPID", APPID).replace("APPSECRET", APPSECRET);
WeixinUtil wx=new WeixinUtil();
System.out.println(url);
while(true){
JSONObject jsonObject =wx.httpsRequest(url,"GET",null);
if(null != jsonObject){
token.setToken(jsonObject.getString("access_token"));
token.setExpiresIn(jsonObject.getInt("expires_in"));
// 获取到的access_tocken值可以写入到文本文件中供其他业务逻辑调用,实例中只打印了没有保存到文件
System.out.println("获取成功"+token.getToken()+"||expires_in="+token.getExpiresIn());
}
//休眠1小时57分钟,提前3分钟获取新的access_token
sleep((7200-7000)*1000);
}
Java微信公众号开发进阶
87739 学习 · 343 问题
相似问题