java 获取微信公众号code为空
失败的原因是没将回调方法encode转换
/**
* URL编码(utf-8)
*
* @param source
* @return
*/
public static String urlEncodeUTF8(String source) {
String result = source;
try {
result = java.net.URLEncoder.encode(source, "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid
+ "&redirect_uri="+urlEncodeUTF8(wx_ip)+"&response_type=code&scope=snsapi_base&state=1#wechat_redirect";