本文主要是关于微信公众号开发过程中获取code、openID的方法
1.首先获取code的方式有两种,一是直接后端通过微信公众号的菜单按钮中配置接口,后端直接获取code值。
在微信公众号的自定义菜单中新增一个按钮,跳转网页地址找中填写
https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=http://xxxxxxx/getCode&response_type=code&scope=snsapi_base&connect_redirect=1#wechat_redirect
appid 每个微信公众号不一样,已这种方式后台接口 getCode
@RequestMapping(value = "/getCode", method = {RequestMethod.GET, RequestMethod.POST})
public String getCode(String code) {
System.out.println("获取微信code" + code);
return "redirect:跳转至指定页面";
}
2.第二种方式是直接在自定以中跳转至前端页面,由前端截取code值,返回给后端
https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=http://xxxx/wechat/test.html&response_type=code&scope=snsapi_base&connect_redirect=1#wech