java对接微信登录
授权登录(授权登录在用户访问时会提示用户登录才可以获取到用户openid)
1.获取Code
2.获取用户信息
1.获取code
3.工具类
public class AuthUtil { public static final String APPID="你的appid"; public static final String APPSECRET="你的APPSECRET"; 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; }