You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					74 lines
				
				2.7 KiB
			
		
		
			
		
	
	
					74 lines
				
				2.7 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								//package com.ynxbd.wx.servlet;
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//import com.ynxbd.common.bean.User;
							 | 
						||
| 
								 | 
							
								//import com.ynxbd.wx.wxfactory.WxCacheHelper;
							 | 
						||
| 
								 | 
							
								//import com.ynxbd.wx.config.WeChatConfig;
							 | 
						||
| 
								 | 
							
								//import com.ynxbd.common.helper.common.Base64Helper;
							 | 
						||
| 
								 | 
							
								//import com.ynxbd.common.result.Result;
							 | 
						||
| 
								 | 
							
								//import lombok.extern.slf4j.Slf4j;
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//import javax.servlet.annotation.WebServlet;
							 | 
						||
| 
								 | 
							
								//import javax.servlet.http.HttpServletRequest;
							 | 
						||
| 
								 | 
							
								//import javax.servlet.http.HttpServletResponse;
							 | 
						||
| 
								 | 
							
								//import javax.servlet.http.HttpSession;
							 | 
						||
| 
								 | 
							
								//import java.util.Date;
							 | 
						||
| 
								 | 
							
								//import java.util.HashMap;
							 | 
						||
| 
								 | 
							
								//import java.util.Map;
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								///**
							 | 
						||
| 
								 | 
							
								// * 微信认证信息
							 | 
						||
| 
								 | 
							
								// *
							 | 
						||
| 
								 | 
							
								// * @author antgan
							 | 
						||
| 
								 | 
							
								// */
							 | 
						||
| 
								 | 
							
								//@Slf4j
							 | 
						||
| 
								 | 
							
								//@WebServlet("/wxAuthInfo")
							 | 
						||
| 
								 | 
							
								//public class WxAuthInfoServlet extends BaseServlet {
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//    @Override
							 | 
						||
| 
								 | 
							
								//    protected Result requestMapping(HttpServletRequest request, HttpServletResponse resp) {
							 | 
						||
| 
								 | 
							
								//        HttpSession session = request.getSession();
							 | 
						||
| 
								 | 
							
								//        Object openid = session.getAttribute("openid");
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//        if (openid != null) {
							 | 
						||
| 
								 | 
							
								//            User user = WxCacheHelper.getCacheUser((String) openid);
							 | 
						||
| 
								 | 
							
								//            if (user == null) {
							 | 
						||
| 
								 | 
							
								//                return Result.success(webAuth(request));
							 | 
						||
| 
								 | 
							
								//            }
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//            Map<String, Object> map = new HashMap<>();
							 | 
						||
| 
								 | 
							
								//            map.put("openid", openid);
							 | 
						||
| 
								 | 
							
								//            map.put("unionId", user.getUnionId());
							 | 
						||
| 
								 | 
							
								//            map.put("date", new Date());
							 | 
						||
| 
								 | 
							
								//            map.put("avatar", user.getAvatar());
							 | 
						||
| 
								 | 
							
								//            map.put("nickName", user.getNickName());
							 | 
						||
| 
								 | 
							
								//            map.put("patients", user.getPatientList());
							 | 
						||
| 
								 | 
							
								//            map.put("hash", request.getParameter("hash"));
							 | 
						||
| 
								 | 
							
								//            return Result.success(map);
							 | 
						||
| 
								 | 
							
								//        }
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//        return Result.success(webAuth(request));
							 | 
						||
| 
								 | 
							
								//    }
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//    private String webAuth(HttpServletRequest request) {
							 | 
						||
| 
								 | 
							
								//        StringBuffer url = request.getRequestURL();
							 | 
						||
| 
								 | 
							
								//        String baseUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append("/").toString();
							 | 
						||
| 
								 | 
							
								//        String state = request.getParameter("state");
							 | 
						||
| 
								 | 
							
								//        String hash = request.getParameter("hash");
							 | 
						||
| 
								 | 
							
								//        if (hash == null) {
							 | 
						||
| 
								 | 
							
								//            hash = "";
							 | 
						||
| 
								 | 
							
								//        }
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//        if (state != null) {
							 | 
						||
| 
								 | 
							
								//            String decode = Base64Helper.decode(state);
							 | 
						||
| 
								 | 
							
								//            if (!decode.contains(".html") && !decode.contains(".jsp")) {
							 | 
						||
| 
								 | 
							
								//                decode = "my-info.html";
							 | 
						||
| 
								 | 
							
								//            }
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//            state = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WeChatConfig.APP_ID + "&redirect_uri=" + baseUrl + "auth" + "?hash=" + hash + "&response_type=code&scope=snsapi_userinfo&state=" + decode + "#wechat_redirect";
							 | 
						||
| 
								 | 
							
								//            state = Base64Helper.encode(state);
							 | 
						||
| 
								 | 
							
								//        }
							 | 
						||
| 
								 | 
							
								//        return state;
							 | 
						||
| 
								 | 
							
								//    }
							 | 
						||
| 
								 | 
							
								//}
							 |