首页 > 代码库 > 获取微信公众号openid
获取微信公众号openid
@Controller public class GetOpenId { private static String appid = ""; private static String appscript = ""; private static String redirect_uri = "...../getCode"; @RequestMapping("/getopenid") @ResponseBody public void getopenid( HttpServletResponse response) { String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + redirect_uri + "&response_type=code&scope=snsapi_userinfo&state=1234#wechat_redirect"; try { response.sendRedirect(url); //重定向跳转到url } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @RequestMapping("/getCode") @ResponseBody public void getCode(String code, String state, HttpServletResponse response) { String path = "https://api.weixin.qq.com/sns/oauth2/access_token?"; String params = "appid=" + appid + "&secret=" + appscript + "&code=" + code + "&grant_type=authorization_code"; String parm = Utils.sendPost(path, params); JSONObject json = JSONObject.fromObject(parm); String openid = json.getString("openid"); String accessToken = json.getString("access_token"); }
获取微信公众号openid
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。