本文主要是介绍JAVA调用微信token返回系统繁忙_微信授权登录用java获取code后再获取token出现40163,code bean used...,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
但是又没出错,我点击链接
https://open.weixin.qq.com/co...://39.108.80.19:8080/wxtest/callBackServlet&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect
进入然后显示这样
然后再点击继续访问就去到回调页面中显示那段话40163。。。的
我的代码如下:
package servlet;
import Utils.AuthUtil;
import org.json.JSONObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
Created by asus on 2017/8/2.
*/
public class CallBackServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
//private static int i = 0;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String code =req.getParameter("code");
String url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + AuthUtil.APPID+
"&secret=" +AuthUtil.APPSECRET+
"&code=" +code+
"&grant_type=authorization_code";
JSONObject jsonObject= AuthUtil.doGetJson(url);
PrintWriter writer = resp.getWriter();
writer.print(jsonObject.toString()+"--666--"+code);
}
}
///
package Utils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import java.io.IOException;
public class AuthUtil {
public static final String APPID="wx084fd8c55cc18287";
public static final String APPSECRET="335f95212c63591d2b3d4404424c9492";
public static JSONObject doGetJson(String url) throws IOException {
JSONObject jsonObject=null;
DefaultHttpClient defaultHttpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(url);
HttpResponse httpResponse = defaultHttpClient.execute(httpGet);
HttpEntity httpEntity=httpResponse.getEntity();
if(httpEntity!=null){
String result= EntityUtils.toString(httpEntity,"UTF-8");
jsonObject=new JSONObject(result);
//System.out.println("jsonObject: "+jsonObject);
}
httpGet.releaseConnection();
return jsonObject;
}
}
试了很多种方法都是提示这样
这篇关于JAVA调用微信token返回系统繁忙_微信授权登录用java获取code后再获取token出现40163,code bean used...的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!