<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.net.URLEncoder"%> <%@ page import="com.geong.util.HttpUtil"%> <%@ page import="com.geong.util.PropertiesUtil"%> <%@ page import="com.geong.util.GetWechatParmas"%> <%@ page import="javax.xml.ws.Response"%> <%@ page import="net.sf.json.JSONObject" %> <% //需要配置跳转地址 String jumpUrl =request.getContextPath()+"/page/story/storyindex.jsp"; //以下为自动处理,不需要更改 String code = request.getParameter("code"); String rpath = PropertiesUtil.getProperty("yu")+request.getRequestURI(); String oauth2Url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+PropertiesUtil.getProperty("appid") +"&redirect_uri="+URLEncoder.encode(rpath,"UTF-8")+"&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"; if(code==null){ response.sendRedirect(oauth2Url); }else{ String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+PropertiesUtil.getProperty("appid") +"&secret="+PropertiesUtil.getProperty("secret")+"&code="+code+"&grant_type=authorization_code"; String openidResult = HttpUtil.get(url,true); JSONObject fromObjectopenid = JSONObject.fromObject(openidResult.toString()); if(fromObjectopenid.toString().indexOf("openid")>-1){ String openid = fromObjectopenid.get("openid").toString(); session.setAttribute("openid",openid); response.sendRedirect(jumpUrl); }else{ response.sendRedirect(oauth2Url); } } %>
微信web开发获取用户openid
- 发表于 2017-09-12 13:18
- 阅读 ( 20554 )
- 分类:Java基础
你可能感兴趣的文章
- Java 添加条码、二维码到PDF文档 134 浏览
- Java 在Excel中添加筛选器并执行筛选 91 浏览
- JAVA + VUE + 简洁UI:分离式软件平台形成之旅 265 浏览
- Java 设置Word中的表格自适应的3种方式 113 浏览
- LeaRun快速开发平台,.net/java项目开发工具简析 142 浏览
- JVM学习笔记之类装载器-ClassLoader 203 浏览
随机文章
- Create binary string in Javascript and convert in C# 192 浏览
- Firebase setPersistenceEnabled(true) what about the downloaded data 181 浏览
- TypeConverters not working for Collections in @Query 189 浏览
- NativeScript Execution failed for task: Error while merging dex archives 870 浏览
- Top Action bar is blocking Cardview 228 浏览
相关问题
- java基础知识提问 1 回答
1 条评论
请先 登录 后评论
发送私信
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!