该博客参考于微信开放平台:
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419317853&token=&lang=zh_CN
第一步,获取code,上述链接中有iOS平台和Android平台获取code的示例,暂不做描述
第二步,通过code获取access_token和openid
private static final String WEIXIN_AUTH_LOGIN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token"; // 授权登录url
private static final String XEIXIN_USERINFO_URL = "https://api.weixin.qq.com/sns/userinfo"; // 获取微信用户信息url
private static final String WEIXIN_APPID = "xxx"; // 应用唯一标识 在微信开放平台提交应用审核通过后获得
private static final String WEIXIN_SECRET = "xxx"; // 应用密钥AppSecret 在微信开放平台提交应用审核通过后获得
// 获取access_token和openid
StringBuffer sbOauth = new StringBuffer();
sbOauth.append(WEIXIN_AUTH_LOGIN_URL)
.append("?appid