关于微信公众号开发code获取,一直不成功的问题
菜鸡03号 2016-12-08 03:08:45 1.开发过程中使用的是ngrok做的内网穿透
2.获取code的代码如下
String appID="";
String appsecret="";
String redirect_uri="http://**.ngrok.cc/project/yinda";
String code=null;
//获取code的url
String codeUrl="https://open.weixin.qq.com/connect/oauth2/authorize?"
+ "appid="+appID
+"&redirect_uri="+redirect_uri
+"&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";
String access_tokenUrl="https://api.weixin.qq.com/sns/oauth2/access_token?"
+ "appid="+appID
+ "&secret="+appsecret
+ "&code="+code
+ "&grant_type=authorization_code";
code = request.getParameter("code");
System.out.println(code);
if(code == null || "".equals(code)){
response.sendRedirect(codeUrl);
}else{
response.sendRedirect("http://www.baidu.com");
}
}
3.公众号测试时第一次进入微信公众号获得的code为null,然后执行了response.sendRedirect(codeUrl),之后代码就不执行了,这是因为我使用ngrok的原因还是我本身代码哪里写错了呢,求大神解惑