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.
104 lines
4.0 KiB
104 lines
4.0 KiB
2 years ago
|
//package com.ynxbd.wx.servlet;
|
||
|
//
|
||
|
//import com.ynxbd.common.bean.Patient;
|
||
|
//import com.ynxbd.common.bean.User;
|
||
|
//import com.ynxbd.wx.wxfactory.WxCacheHelper;
|
||
|
//import com.ynxbd.wx.config.WeChatConfig;
|
||
|
//import com.ynxbd.common.dao.PatientDao;
|
||
|
//import com.ynxbd.common.helper.common.Base64Helper;
|
||
|
//import com.ynxbd.common.helper.common.HttpHelper;
|
||
|
//import lombok.extern.slf4j.Slf4j;
|
||
|
//import org.ehcache.Cache;
|
||
|
//import org.slf4j.MDC;
|
||
|
//import weixin.popular.api.SnsAPI;
|
||
|
//import weixin.popular.bean.sns.SnsToken;
|
||
|
//
|
||
|
//import javax.servlet.ServletException;
|
||
|
//import javax.servlet.annotation.WebServlet;
|
||
|
//import javax.servlet.http.HttpServlet;
|
||
|
//import javax.servlet.http.HttpServletRequest;
|
||
|
//import javax.servlet.http.HttpServletResponse;
|
||
|
//import java.io.IOException;
|
||
|
//import java.io.UnsupportedEncodingException;
|
||
|
//import java.net.URLDecoder;
|
||
|
//import java.util.List;
|
||
|
//
|
||
|
///**
|
||
|
// * 微信认证回调处理
|
||
|
// *
|
||
|
// * @author antgan
|
||
|
// */
|
||
|
//@Slf4j
|
||
|
//@WebServlet("/auth")
|
||
|
//public class WxAuthServlet extends HttpServlet {
|
||
|
//
|
||
|
// protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||
|
// MDC.remove("ip");
|
||
|
// MDC.put("ip", HttpHelper.getIpAddress(request));
|
||
|
// String code = request.getParameter("code");
|
||
|
// String state = request.getParameter("state");
|
||
|
// String hash = request.getParameter("hash");
|
||
|
// try {
|
||
|
// if (hash == null) {
|
||
|
// hash = "";
|
||
|
// } else {
|
||
|
// hash = Base64Helper.decode(hash);
|
||
|
// hash = URLDecoder.decode(hash, "UTF-8");
|
||
|
// }
|
||
|
// } catch (UnsupportedEncodingException e) {
|
||
|
// e.printStackTrace();
|
||
|
// }
|
||
|
//
|
||
|
// SnsToken snsToken = SnsAPI.oauth2AccessToken(WeChatConfig.APP_ID, WeChatConfig.APP_SECRET, code);
|
||
|
// if (snsToken != null) {
|
||
|
// String openid = snsToken.getOpenid();
|
||
|
// if (openid != null) {
|
||
|
// request.getSession().setAttribute("openid", openid);
|
||
|
//
|
||
|
// Cache<String, User> cache = WxCacheHelper.getUserCache();
|
||
|
// if (!cache.containsKey(openid)) {
|
||
|
// weixin.popular.bean.user.User wxUser = SnsAPI.userinfo(snsToken.getAccess_token(), openid, "zh_CN", 3);
|
||
|
// if (wxUser != null) {
|
||
|
// String unionId = snsToken.getUnionid();
|
||
|
// User user = new User();
|
||
|
// user.setOpenid(wxUser.getOpenid());
|
||
|
// user.setUnionId(unionId);
|
||
|
// user.setCountry((wxUser.getCountry() == null ? "" : wxUser.getCountry()));
|
||
|
// user.setAvatar(wxUser.getHeadimgurl());
|
||
|
// user.setNickName(wxUser.getNickname_emoji());
|
||
|
// user.setProvince(wxUser.getProvince());
|
||
|
// Integer sex = wxUser.getSex();
|
||
|
// if (sex != null) {
|
||
|
// user.setGender(sex == 1 ? "男" : "女");
|
||
|
// }
|
||
|
// user.setCity(wxUser.getCity());
|
||
|
// user.setLanguage(wxUser.getLanguage());
|
||
|
//
|
||
|
// List<Patient> patients = new PatientDao().selectListByToken(openid, unionId);
|
||
|
// user.setPatientList(patients);
|
||
|
//
|
||
|
// cache.put(openid, user);
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
//
|
||
|
// if (hash == null) hash = "";
|
||
|
// if (state == null) state = "";
|
||
|
//
|
||
|
// if (state.contains(".html")) {
|
||
|
// response.sendRedirect(state + hash);
|
||
|
// } else {
|
||
|
// String baseUrl = WeChatConfig.getBaseUrl();
|
||
|
// if (baseUrl != null && state.contains(baseUrl)) {
|
||
|
// response.sendRedirect(state + hash);
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
//
|
||
|
// protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||
|
// doGet(request, response);
|
||
|
// }
|
||
|
//
|
||
|
//}
|