用户授权调整为医共体授权

debug
王绍全 2 months ago
parent 993812dd3e
commit e84f4646ca
  1. 4
      src/main/java/com/ynxbd/ali/helper/AliCacheHelper.java
  2. 2
      src/main/java/com/ynxbd/ali/helper/AliHelper.java
  3. 2
      src/main/java/com/ynxbd/ali/helper/AliUploadHelper.java
  4. 2
      src/main/java/com/ynxbd/bcm/config/BCMHelper.java
  5. 4
      src/main/java/com/ynxbd/common/TestA.java
  6. 2
      src/main/java/com/ynxbd/common/action/AliAction.java
  7. 5
      src/main/java/com/ynxbd/common/action/ApiAction.java
  8. 2
      src/main/java/com/ynxbd/common/action/HealthCodeAction.java
  9. 2
      src/main/java/com/ynxbd/common/action/QRAction.java
  10. 2
      src/main/java/com/ynxbd/common/action/pay/ThirdPartyPayAction.java
  11. 17
      src/main/java/com/ynxbd/common/action/pay/WxAuthAction.java
  12. 5
      src/main/java/com/ynxbd/common/bean/User.java
  13. 3
      src/main/java/com/ynxbd/common/dao/PatientDao.java
  14. 23
      src/main/java/com/ynxbd/common/helper/common/ParamHelper.java
  15. 18
      src/main/java/com/ynxbd/common/helper/common/URLHelper.java
  16. 14
      src/main/java/com/ynxbd/common/result/Result.java
  17. 20
      src/main/java/com/ynxbd/common/service/AIGuidanceService.java
  18. 2
      src/main/java/com/ynxbd/common/service/HCodeService.java
  19. 6
      src/main/java/com/ynxbd/common/service/MedicalService.java
  20. 72
      src/main/java/com/ynxbd/common/service/PatientService.java
  21. 82
      src/main/java/com/ynxbd/wx/config/MessagePushConfig.java
  22. 202
      src/main/java/com/ynxbd/wx/config/WeChatConfig.java
  23. 2
      src/main/java/com/ynxbd/wx/ext/report/TJServlet.java
  24. 3
      src/main/java/com/ynxbd/wx/servlet/QServlet.java
  25. 4
      src/main/java/com/ynxbd/wx/servlet/oldpay/QRPayServlet2.java
  26. 7
      src/main/java/com/ynxbd/wx/wxfactory/AesWxHelper.java
  27. 212
      src/main/java/com/ynxbd/wx/wxfactory/WxAuthHelper.java
  28. 26
      src/main/java/com/ynxbd/wx/wxfactory/WxCacheHelper.java
  29. 11
      src/main/java/com/ynxbd/wx/wxfactory/WxMedHelper.java
  30. 4
      src/main/java/com/ynxbd/wx/wxfactory/WxPayHelper.java
  31. 2
      src/main/java/com/ynxbd/wx/wxfactory/base/auth/Client.java
  32. 30
      src/main/java/com/ynxbd/wx/wxfactory/bean/auth/AuthData.java
  33. 12
      src/main/java/com/ynxbd/wx/wxfactory/utils/WxPassiveReplyHelper.java
  34. 14
      src/main/java/wx_menu/CreateMenu.java
  35. 14
      src/main/java/wx_menu/CreateMenu_md.java
  36. 12
      src/main/java/wx_menu/CreateMenu_normal.java
  37. 16
      src/main/resources/wx-backup.properties
  38. 49
      src/main/resources/wx.properties

@ -67,7 +67,7 @@ public class AliCacheHelper {
if (openid == null) { if (openid == null) {
return null; return null;
} }
Cache<String, User> cache = WxCacheHelper.getUserCache(); Cache<String, User> cache = WxCacheHelper.getUserCacheManager();
User user = cache.get(openid); User user = cache.get(openid);
if (user != null) { if (user != null) {
return user.getAccess_token_hosp_order(); return user.getAccess_token_hosp_order();
@ -83,7 +83,7 @@ public class AliCacheHelper {
if (openid == null) { if (openid == null) {
return null; return null;
} }
Cache<String, User> cache = WxCacheHelper.getUserCache(); Cache<String, User> cache = WxCacheHelper.getUserCacheManager();
User user = cache.get(openid); User user = cache.get(openid);
if (user != null) { if (user != null) {
return user.getAccess_token_energy(); return user.getAccess_token_energy();

@ -234,7 +234,7 @@ public class AliHelper {
AlipayTradeCreateResponse response = Factory.Payment.Common() AlipayTradeCreateResponse response = Factory.Payment.Common()
// 调用asyncNotify扩展方法,可以为每次API调用,设置独立的异步通知地址 此处设置的异步通知地址的优先级高于全局Config中配置的异步通知地址 // 调用asyncNotify扩展方法,可以为每次API调用,设置独立的异步通知地址 此处设置的异步通知地址的优先级高于全局Config中配置的异步通知地址
.asyncNotify(WeChatConfig.getHttpsBaseUrl() + merchantEnum.getNotifyUrl(outTradeNo, notifyType)) .asyncNotify(WeChatConfig.getHttpsBaseURL() + merchantEnum.getNotifyUrl(outTradeNo, notifyType))
.optional("extend_params", extend_params) .optional("extend_params", extend_params)
.create(subject, outTradeNo, totalAmount, buyerId); .create(subject, outTradeNo, totalAmount, buyerId);

@ -45,7 +45,7 @@ public class AliUploadHelper {
hospInfoJson.put("hospital_lat", AliConfig.HOSP_LAT); hospInfoJson.put("hospital_lat", AliConfig.HOSP_LAT);
hospInfoJson.put("hospital_type", AliConfig.HOSP_TYPE); hospInfoJson.put("hospital_type", AliConfig.HOSP_TYPE);
hospInfoJson.put("hospital_grade", AliConfig.HOSP_GRADE); hospInfoJson.put("hospital_grade", AliConfig.HOSP_GRADE);
hospInfoJson.put("hospital_logo", WeChatConfig.getHttpsBaseUrl() + "images/logo.png"); // logo hospInfoJson.put("hospital_logo", WeChatConfig.getHttpsBaseURL() + "images/logo.png"); // logo
hospArr.add(hospInfoJson); hospArr.add(hospInfoJson);
reqJson.put("hospital_list", hospArr); reqJson.put("hospital_list", hospArr);

@ -140,7 +140,7 @@ public class BCMHelper {
// 回调地址 // 回调地址
reqBody.setNotifyUrl(WeChatConfig.getBaseUrl() + merchantEnum.getNotifyUrl(null, notifyType)); reqBody.setNotifyUrl(WeChatConfig.getBaseURL() + merchantEnum.getNotifyUrl(null, notifyType));
reqBody.setPayMerTranNo(outTradeNo); // 商户订单号 reqBody.setPayMerTranNo(outTradeNo); // 商户订单号
reqBody.setTotalAmount(totalFee); // 订单总金额 reqBody.setTotalAmount(totalFee); // 订单总金额
reqBody.setTranContent(title); // 交易内容 reqBody.setTranContent(title); // 交易内容

@ -1,8 +1,10 @@
package com.ynxbd.common; package com.ynxbd.common;
import java.io.UnsupportedEncodingException;
public class TestA { public class TestA {
public static void main(String[] args) {
public static void main(String[] args) throws UnsupportedEncodingException {
} }
} }

@ -56,7 +56,7 @@ public class AliAction extends BaseAction {
return Result.error(ResultEnum.INTERFACE_ALI_INVOKE_ERROR); // 支付宝接口调用失败 return Result.error(ResultEnum.INTERFACE_ALI_INVOKE_ERROR); // 支付宝接口调用失败
} }
Cache<String, User> cache = WxCacheHelper.getUserCache(); Cache<String, User> cache = WxCacheHelper.getUserCacheManager();
User user; User user;
if (cache.containsKey(openid)) { if (cache.containsKey(openid)) {
user = WxCacheHelper.getCacheUser(openid); user = WxCacheHelper.getCacheUser(openid);

@ -135,7 +135,7 @@ public class ApiAction extends BaseAction {
*/ */
@Action("getWebUrl") @Action("getWebUrl")
public Result getWebUrl() { public Result getWebUrl() {
return Result.success(WeChatConfig.getWebUrl()); return Result.success(WeChatConfig.getWebReqURL());
} }
/** /**
@ -195,7 +195,7 @@ public class ApiAction extends BaseAction {
if (cacheUser == null) { if (cacheUser == null) {
return Result.error("没有缓存"); return Result.error("没有缓存");
} }
WxCacheHelper.getUserCache().remove(openid); WxCacheHelper.getUserCacheManager().remove(openid);
return Result.success(); return Result.success();
} }
@ -264,5 +264,4 @@ public class ApiAction extends BaseAction {
} }
} }

@ -358,7 +358,7 @@ public class HealthCodeAction extends BaseAction {
boolean isUpdate = new PatientDao().updateInfo(openid, patientId, idCardNo, healthCardId, name, nation, tel, null, address, null, null); boolean isUpdate = new PatientDao().updateInfo(openid, patientId, idCardNo, healthCardId, name, nation, tel, null, address, null, null);
if (isUpdate) { if (isUpdate) {
Cache<String, User> cache = WxCacheHelper.getUserCache(); Cache<String, User> cache = WxCacheHelper.getUserCacheManager();
cache.remove(openid); cache.remove(openid);
return Result.success(); return Result.success();
} }

@ -34,7 +34,7 @@ public class QRAction extends BaseAction {
String sid = UUID.randomUUID().toString().replace("-", ""); String sid = UUID.randomUUID().toString().replace("-", "");
String base64 = QRCodeHelper.encodeToBase64(baseURL + WeChatConfig.getWebPath(false, true) + String.format("qr-login.html?msgInterface=%s&sid=%s", msgInterface, sid), 140, 140); String base64 = QRCodeHelper.encodeToBase64(WeChatConfig.getWebReqURL() + String.format("qr-login.html?msgInterface=%s&sid=%s", msgInterface, sid), 140, 140);
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();

@ -41,7 +41,7 @@ public class ThirdPartyPayAction extends BaseAction {
map.put("date", date); map.put("date", date);
map.put("enDate", AesWxHelper.encode(date)); map.put("enDate", AesWxHelper.encode(date));
}, true); }, true);
return Result.redirect(WeChatConfig.getWebUrl() + "tpp-qr-reg.html" + params); return Result.redirect(WeChatConfig.getWebReqURL() + "tpp-qr-reg.html" + params);
} }
@Action("qr_reg_pay") @Action("qr_reg_pay")

@ -15,7 +15,7 @@ public class WxAuthAction extends BaseAction {
@Action("is_auth") @Action("is_auth")
public Result is_auth() throws Exception { public Result is_auth() throws Exception {
return WxAuthHelper.isAuth(request); return WxAuthHelper.isAuth(request, false);
} }
@Action("u_auth") @Action("u_auth")
@ -26,7 +26,20 @@ public class WxAuthAction extends BaseAction {
@Action("b_auth") @Action("b_auth")
public Result b_auth() { public Result b_auth() {
String auth = WxAuthHelper.auth(request, response, true); String auth = WxAuthHelper.auth(request, response, false);
return Result.redirect(auth); return Result.redirect(auth);
} }
@Action("is_pay_auth")
public Result is_pay_auth() throws Exception {
// 支付使用普通授权
return WxAuthHelper.isAuth(request, true);
}
// @Action("pay_b_auth")
// public Result pay_b_auth() throws Exception {
// String auth = WxAuthHelper.auth(request, response, true, true);
// return Result.redirect(auth);
// }
} }

@ -42,4 +42,9 @@ public class User implements Serializable {
private Date time; // token过期时间 private Date time; // token过期时间
private List<Patient> patientList; private List<Patient> patientList;
public void setGenderByInt(Integer sex) {
if (sex == null) return;
this.gender = (sex == 1 ? "男" : "女");
}
} }

@ -4,6 +4,7 @@ import com.ynxbd.common.bean.Patient;
import com.ynxbd.common.bean.PatientLink; import com.ynxbd.common.bean.PatientLink;
import com.ynxbd.common.bean.enums.HCardTypeEnum; import com.ynxbd.common.bean.enums.HCardTypeEnum;
import com.ynxbd.common.config.db.DataBase; import com.ynxbd.common.config.db.DataBase;
import org.apache.commons.lang3.ObjectUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -37,7 +38,7 @@ public class PatientDao {
* @return 患者列表 * @return 患者列表
*/ */
public List<Patient> selectListByToken(String openid, String unionId) { public List<Patient> selectListByToken(String openid, String unionId) {
if (unionId == null || "".equals(unionId)) { if (ObjectUtils.isEmpty(unionId)) {
return selectListByOpenid(openid); return selectListByOpenid(openid);
} }
String sql = "select * from patientBase where openid = ? and deletedState = 0 order by isDefault desc"; String sql = "select * from patientBase where openid = ? and deletedState = 0 order by isDefault desc";

@ -335,4 +335,27 @@ public class ParamHelper {
return true; return true;
} }
/**
* 前端参数空值过滤
*
* @param params 参数
* @return str
*/
public static String filterParamNull(String params, String defaultValue) {
if (ObjectUtils.isEmpty(params)) return defaultValue;
if ("null".equals(params) || "undefined".equals(params)) return defaultValue;
return params;
}
public static Boolean paramToBoolean(String params, Boolean defaultValue) {
if (ObjectUtils.isEmpty(params)) return defaultValue;
if ("null".equals(params) || "undefined".equals(params)) return defaultValue;
try {
return Boolean.parseBoolean(params);
} catch (Exception e) {
System.out.println("参数转化失败");
return defaultValue;
}
}
} }

@ -1,5 +1,7 @@
package com.ynxbd.common.helper.common; package com.ynxbd.common.helper.common;
import org.apache.commons.lang3.ObjectUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -35,11 +37,15 @@ public class URLHelper {
} }
public static void main(String[] args) { public static String URLToHttps(String url) {
String s = mapToUrl(map -> { if (ObjectUtils.isEmpty(url)) {
map.put("a", 2); return null;
map.put("b", 1); }
}, true); int index = url.indexOf("http://");
System.out.println(s); if (index == 0) {
return "https://" + url.substring(7);
}
return url;
} }
} }

@ -3,12 +3,14 @@ package com.ynxbd.common.result;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ynxbd.common.helper.common.DateHelper; import com.ynxbd.common.helper.common.DateHelper;
import com.ynxbd.common.helper.common.JsonHelper;
import com.ynxbd.common.result.struts2.BaseResult; import com.ynxbd.common.result.struts2.BaseResult;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
@ -165,6 +167,18 @@ public class Result extends BaseResult {
return new Result(resultEnum.status, resultEnum.message); return new Result(resultEnum.status, resultEnum.message);
} }
public static Result dataToResult(String data, boolean isErrResult) {
if (ObjectUtils.isEmpty(data)) {
if (isErrResult) {
return Result.error();
}
return Result.success();
}
return JsonHelper.parseObject(data, Result.class);
}
private Result(Integer code, String message) { private Result(Integer code, String message) {
this.code = code; this.code = code;
this.message = message; this.message = message;

@ -47,9 +47,9 @@ public class AIGuidanceService {
map.put("hosLevel", AIGuidanceConfig.HOS_LEVEL); map.put("hosLevel", AIGuidanceConfig.HOS_LEVEL);
map.put("hosAddress", AIGuidanceConfig.HOS_ADDRESS); map.put("hosAddress", AIGuidanceConfig.HOS_ADDRESS);
map.put("hosTelephone", AIGuidanceConfig.HOS_TELEPHONE); map.put("hosTelephone", AIGuidanceConfig.HOS_TELEPHONE);
map.put("hosImage", WeChatConfig.getWebUrl() + "images/logo.png"); map.put("hosImage", WeChatConfig.getWebReqURL() + "images/logo.png");
map.put("appId", WeChatConfig.APP_ID); // 公众号appid map.put("appId", WeChatConfig.APP_ID); // 公众号appid
map.put("hosUrl", WeChatConfig.getWebUrl() + "app.html"); // 公众号appid map.put("hosUrl", WeChatConfig.getWebReqURL() + "app.html"); // 公众号appid
map.put("originAppid", ""); // 小程序原始id map.put("originAppid", ""); // 小程序原始id
map.put("location", ""); // 经纬度,逗号分割 map.put("location", ""); // 经纬度,逗号分割
@ -82,11 +82,7 @@ public class AIGuidanceService {
String curDate = DateHelper.getCurDate(); String curDate = DateHelper.getCurDate();
List<Dept> deptList = new HisRegisterDao().getTimeDeptList(curDate, DateHelper.getMoveDate(curDate, 7),""); List<Dept> deptList = new HisRegisterDao().getTimeDeptList(curDate, DateHelper.getMoveDate(curDate, 7),"");
String webUrl = WeChatConfig.getWebUrl(); String webReqURL = WeChatConfig.getWebReqURL(true);
int index = webUrl.indexOf("http://");
if (index == 0) {
webUrl = "https://" + webUrl.substring(index + 7);
}
String deptName; String deptName;
AIDept item; AIDept item;
@ -111,7 +107,7 @@ public class AIGuidanceService {
item.setDeptEmbedAlipayUrl(""); item.setDeptEmbedAlipayUrl("");
try { try {
item.setDeptUrl(webUrl + "reg-reserve.html#/doctor?deptCode=" + dept.getDeptCode() + "&deptName=" + URLEncoder.encode(deptName, "utf-8") + "&hospitalArea="); item.setDeptUrl(webReqURL + "reg-reserve.html#/doctor?deptCode=" + dept.getDeptCode() + "&deptName=" + URLEncoder.encode(deptName, "utf-8") + "&hospitalArea=");
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage()); log.error(e.getMessage());
item.setDeptUrl(""); item.setDeptUrl("");
@ -140,11 +136,7 @@ public class AIGuidanceService {
return Result.success(ResultEnum.AI_SUCCESS, resultList); return Result.success(ResultEnum.AI_SUCCESS, resultList);
} }
String webUrl = WeChatConfig.getWebUrl(); String webReqURL = WeChatConfig.getWebReqURL(true);
int index = webUrl.indexOf("http://");
if (index == 0) {
webUrl = "https://" + webUrl.substring(index + 7);
}
String curDate = DateHelper.getCurDate(); String curDate = DateHelper.getCurDate();
List<Doctor> doctorList = new HisRegisterDao().getTimeDoctorList(deptId, branchId, curDate, DateHelper.getMoveDate(curDate, 7)); List<Doctor> doctorList = new HisRegisterDao().getTimeDoctorList(deptId, branchId, curDate, DateHelper.getMoveDate(curDate, 7));
@ -196,7 +188,7 @@ public class AIGuidanceService {
} }
try { try {
item.setDoctorUrl(webUrl + "reg-reserve.html#/source?deptCode=" + deptCode + "&deptName=" + URLEncoder.encode(deptName, "utf-8") + "&doctName=" + URLEncoder.encode(doctor.getDoctName(), "utf-8") + "&doctCode=" + doctor.getDoctCode() + "&hospitalArea="); item.setDoctorUrl(webReqURL + "reg-reserve.html#/source?deptCode=" + deptCode + "&deptName=" + URLEncoder.encode(deptName, "utf-8") + "&doctName=" + URLEncoder.encode(doctor.getDoctName(), "utf-8") + "&doctCode=" + doctor.getDoctCode() + "&hospitalArea=");
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage()); log.error(e.getMessage());
item.setDoctorUrl(""); item.setDoctorUrl("");

@ -346,7 +346,7 @@ public class HCodeService {
//调用接口 //调用接口
String okURL = WeChatConfig.getWebUrl() + "/health-card-bind.html"; String okURL = WeChatConfig.getWebReqURL() + "/health-card-bind.html";
JSONObject resultJson = new HealthCardServerImpl(H_APP_SECRET).registerUniformVerifyOrder(commonIn, idCardNo, "01", name, wechatCode); JSONObject resultJson = new HealthCardServerImpl(H_APP_SECRET).registerUniformVerifyOrder(commonIn, idCardNo, "01", name, wechatCode);
JSONObject commonOut = resultJson.getJSONObject("commonOut"); JSONObject commonOut = resultJson.getJSONObject("commonOut");

@ -205,8 +205,8 @@ public class MedicalService {
insuranceFee, insuranceFee,
cashFee, cashFee,
orderTitle, orderTitle,
WeChatConfig.getWebUrl() + orderMIEnum.WX_CALL_BACK_URL, WeChatConfig.getWebReqURL() + orderMIEnum.WX_CALL_BACK_URL,
WeChatConfig.getBaseUrl() + merchantEnum.NOTIFY_URL, WeChatConfig.getBaseURL() + merchantEnum.NOTIFY_URL,
notifyType, notifyType,
familyType, familyType,
familyName, familyName,
@ -220,7 +220,7 @@ public class MedicalService {
} }
Order order = hasDBOrder ? AliMedHelper.queryTrade(outTradeNo, null) : new Order(); Order order = hasDBOrder ? AliMedHelper.queryTrade(outTradeNo, null) : new Order();
String notifyUrl = WeChatConfig.getHttpsBaseUrl() + merchantEnum.getNotifyUrl(outTradeNo, notifyType); String notifyUrl = WeChatConfig.getHttpsBaseURL() + merchantEnum.getNotifyUrl(outTradeNo, notifyType);
Map<String, Object> map = AliMedHelper.createOrder(orderMIEnum, Map<String, Object> map = AliMedHelper.createOrder(orderMIEnum,
openid, openid,
outTradeNo, outTradeNo,

@ -12,6 +12,7 @@ import com.ynxbd.common.helper.common.ValidHelper;
import com.ynxbd.common.result.Result; import com.ynxbd.common.result.Result;
import com.ynxbd.common.result.ResultEnum; import com.ynxbd.common.result.ResultEnum;
import com.ynxbd.common.result.ServiceException; import com.ynxbd.common.result.ServiceException;
import com.ynxbd.wx.config.WeChatConfig;
import com.ynxbd.wx.utils.DesEncryptHelper; import com.ynxbd.wx.utils.DesEncryptHelper;
import com.ynxbd.wx.wxfactory.AesWxHelper; import com.ynxbd.wx.wxfactory.AesWxHelper;
import com.ynxbd.wx.wxfactory.WxCacheHelper; import com.ynxbd.wx.wxfactory.WxCacheHelper;
@ -57,31 +58,58 @@ public class PatientService {
return new PatientDao().selectPatientsByOpenId(openId); return new PatientDao().selectPatientsByOpenId(openId);
} }
public List<Patient> queryPatientList(String openid, String unionId, boolean isEnPid) { public List<Patient> enPatientList(List<Patient> patients) {
for (Patient item : patients) {
if (item.getPatientId() != null) {
item.setEnPatientId(AesWxHelper.encode(item.getPatientId()));
}
if (!ObjectUtils.isEmpty(item.getIdCardNo())) {
// 加密数据
item.setEnCardNo(AesWxHelper.encode(item.getIdCardNo()));
item.setEnTel(AesWxHelper.encode(item.getTel()));
// 显示数据----------------------
item.setShowCardNo(ParamHelper.hideIdCardNo(item.getIdCardNo()));
item.setShowTel(ParamHelper.hidTel(item.getTel()));
} else {
// 无证绑定显示数据
item.setFatherIdCardNo(ParamHelper.hideIdCardNo(item.getFatherIdCardNo()));
item.setMotherIdCardNo(ParamHelper.hideIdCardNo(item.getMotherIdCardNo()));
// ------------
item.setFatherTel(ParamHelper.hidTel(item.getFatherTel()));
item.setMotherTel(ParamHelper.hidTel(item.getMotherTel()));
}
}
return patients;
}
/**
* 查询医共体医生列表
*
* @param openid
* @param unionId
* @param isEnPid
* @return
*/
public List<Patient> queryGMCPatientList(String enUnionId, String openid, String unionId, boolean isEnPid) {
// 在查询时完成数据同步
if (!WeChatConfig.IS_GMC_SERVER) { // 不为医共体主体
// 查询医共体患者数据
}
List<Patient> patients = new PatientDao().selectListByToken(openid, unionId); List<Patient> patients = new PatientDao().selectListByToken(openid, unionId);
if (isEnPid) { if (isEnPid) {
for (Patient item : patients) { patients = enPatientList(patients);
if (item.getPatientId() != null) { }
item.setEnPatientId(AesWxHelper.encode(item.getPatientId())); return patients;
} }
if (!ObjectUtils.isEmpty(item.getIdCardNo())) { public List<Patient> queryPatientList(String openid, String unionId, boolean isEnPid) {
// 加密数据 List<Patient> patients = new PatientDao().selectListByToken(openid, unionId);
item.setEnCardNo(AesWxHelper.encode(item.getIdCardNo())); if (isEnPid) {
item.setEnTel(AesWxHelper.encode(item.getTel())); patients = enPatientList(patients);
// 显示数据----------------------
item.setShowCardNo(ParamHelper.hideIdCardNo(item.getIdCardNo()));
item.setShowTel(ParamHelper.hidTel(item.getTel()));
} else {
// 无证绑定显示数据
item.setFatherIdCardNo(ParamHelper.hideIdCardNo(item.getFatherIdCardNo()));
item.setMotherIdCardNo(ParamHelper.hideIdCardNo(item.getMotherIdCardNo()));
// ------------
item.setFatherTel(ParamHelper.hidTel(item.getFatherTel()));
item.setMotherTel(ParamHelper.hidTel(item.getMotherTel()));
}
}
} }
return patients; return patients;
} }

@ -21,7 +21,7 @@ public class MessagePushConfig {
private MessagePushConfig() { private MessagePushConfig() {
} }
public static final String ORGANIZENAME; public static final String ORGANIZENAME;
// 挂号导航是否开启功能===================================== // 挂号导航是否开启功能=====================================
public static final boolean REG_NAVIGATE_IS_ENABLE; public static final boolean REG_NAVIGATE_IS_ENABLE;
@ -73,7 +73,7 @@ public class MessagePushConfig {
RECIPE_IS_ENABLE = config.getBoolean("msg.recipe.is_enable", false); RECIPE_IS_ENABLE = config.getBoolean("msg.recipe.is_enable", false);
RECIPE_URL = config.getString("msg.recipe.url"); RECIPE_URL = config.getString("msg.recipe.url");
REG_AI_IS_ENABLE = config.getBoolean("msg.ai.is_enable",false); REG_AI_IS_ENABLE = config.getBoolean("msg.ai.is_enable", false);
REG_AI_URL = config.getString("msg.ai.url"); REG_AI_URL = config.getString("msg.ai.url");
if (REG_CANCEL_URL == null) { if (REG_CANCEL_URL == null) {
@ -180,34 +180,35 @@ public class MessagePushConfig {
/** /**
* AI诊疗推送 * AI诊疗推送
*
* @param merchantEnum * @param merchantEnum
* @param reg * @param reg
*/ */
public static void regAI(MerchantEnum merchantEnum,Register reg){ public static void regAI(MerchantEnum merchantEnum, Register reg) {
try { try {
if (!merchantEnum.equals(MerchantEnum.WX) if (!merchantEnum.equals(MerchantEnum.WX)
|| !REG_AI_IS_ENABLE || reg == null || ObjectUtils.isEmpty(REG_AI_URL)) { || !REG_AI_IS_ENABLE || reg == null || ObjectUtils.isEmpty(REG_AI_URL)) {
return; return;
} }
log.info("[推送]AI智能问诊推送..."); log.info("[推送]AI智能问诊推送...");
String patientId = reg.getPatientId(); String patientId = reg.getPatientId();
if ( patientId == null) { if (patientId == null) {
log.warn("[推送]AI智能问诊推送通知失败,参数缺失~ patientId= null"); log.warn("[推送]AI智能问诊推送通知失败,参数缺失~ patientId= null");
return; return;
} }
String url = PWEHelper.getH5PWEUrl(reg.getOutTradeNo(),reg.getOpenid()); String url = PWEHelper.getH5PWEUrl(reg.getOutTradeNo(), reg.getOpenid());
if(url==null||"".equals(url)){ if (url == null || "".equals(url)) {
log.warn("[推送][推送]AI智能问诊推送通知失败,问诊获取参数为空 outTradeNo-{}",reg.getOutTradeNo()); log.warn("[推送][推送]AI智能问诊推送通知失败,问诊获取参数为空 outTradeNo-{}", reg.getOutTradeNo());
return; return;
} }
RequestBody requestBody = new FormBody.Builder() RequestBody requestBody = new FormBody.Builder()
.add("patientId",patientId) .add("patientId", patientId)
.add("content","为了帮助医生更全面地了解您的身体情况,请花2分钟时间填写病情信息,以便医生提前了解病症,为您提供更好的诊疗服务。") .add("content", "为了帮助医生更全面地了解您的身体情况,请花2分钟时间填写病情信息,以便医生提前了解病症,为您提供更好的诊疗服务。")
.add("url", url) .add("url", url)
.add("organizeName",ORGANIZENAME) .add("organizeName", ORGANIZENAME)
.build(); .build();
OkHttpHelper.post(REG_AI_URL, requestBody); OkHttpHelper.post(REG_AI_URL, requestBody);
} catch (Exception e) { } catch (Exception e) {
@ -218,22 +219,23 @@ public class MessagePushConfig {
/** /**
* 通用推送消息接口 * 通用推送消息接口
* @param tip 所属部分 *
* @param tip 所属部分
* @param patientId 患者id * @param patientId 患者id
* @param content 推送内容 * @param content 推送内容
* @param url 链接地址 * @param url 链接地址
*/ */
public static void businessPush(String tip, String patientId, String content,String url){ public static void businessPush(String tip, String patientId, String content, String url) {
if(patientId==null) { if (patientId == null) {
log.info("[{}]通用推送错误,patientId为空",tip); log.info("[{}]通用推送错误,patientId为空", tip);
return; return;
} }
log.info("[{}]通用推送开始,patientId-{},content-{},url-{}",tip,patientId,content,url); log.info("[{}]通用推送开始,patientId-{},content-{},url-{}", tip, patientId, content, url);
RequestBody requestBody = new FormBody.Builder() RequestBody requestBody = new FormBody.Builder()
.add("patientId",patientId) .add("patientId", patientId)
.add("content",content) .add("content", content)
.add("url", url) .add("url", url)
.add("organizeName",ORGANIZENAME) .add("organizeName", ORGANIZENAME)
.build(); .build();
OkHttpHelper.post(REG_AI_URL, requestBody); OkHttpHelper.post(REG_AI_URL, requestBody);
} }
@ -241,29 +243,30 @@ public class MessagePushConfig {
/** /**
* AI诊疗推送 * AI诊疗推送
*
* @param patientId * @param patientId
*/ */
public static void regAIReport(String patientId,String outTradeNo,String openId){ public static void regAIReport(String patientId, String outTradeNo, String openId) {
try { try {
if (!REG_AI_IS_ENABLE || ObjectUtils.isEmpty(REG_AI_URL)) { if (!REG_AI_IS_ENABLE || ObjectUtils.isEmpty(REG_AI_URL)) {
return; return;
} }
log.info("[推送]AI问诊报告推送..."); log.info("[推送]AI问诊报告推送...");
if ( patientId == null) { if (patientId == null) {
log.warn("[推送]AI问诊报告推送通知失败,参数缺失~ patientId= null"); log.warn("[推送]AI问诊报告推送通知失败,参数缺失~ patientId= null");
return; return;
} }
String url = PWEHelper.getH5PWEUrl(outTradeNo,openId); String url = PWEHelper.getH5PWEUrl(outTradeNo, openId);
if(url==null||"".equals(url)){ if (url == null || "".equals(url)) {
log.warn("[推送]AI问诊报告推送通知失败,问诊获取参数为空 outTradeNo-{}",outTradeNo); log.warn("[推送]AI问诊报告推送通知失败,问诊获取参数为空 outTradeNo-{}", outTradeNo);
return; return;
} }
RequestBody requestBody = new FormBody.Builder() RequestBody requestBody = new FormBody.Builder()
.add("patientId",patientId) .add("patientId", patientId)
.add("content","您好,您的预问诊报告可以查看啦") .add("content", "您好,您的预问诊报告可以查看啦")
.add("url", url) .add("url", url)
.add("organizeName",ORGANIZENAME) .add("organizeName", ORGANIZENAME)
.build(); .build();
OkHttpHelper.post(REG_AI_URL, requestBody); OkHttpHelper.post(REG_AI_URL, requestBody);
} catch (Exception e) { } catch (Exception e) {
@ -272,33 +275,32 @@ public class MessagePushConfig {
} }
/** /**
* 红河州医院产科建党推送 * 红河州医院产科建党推送
*
* @param merchantEnum * @param merchantEnum
* @param reg * @param reg
*/ */
public static void regObsDocument(MerchantEnum merchantEnum, Register reg){ public static void regObsDocument(MerchantEnum merchantEnum, Register reg) {
try { try {
if (!merchantEnum.equals(MerchantEnum.WX) if (!merchantEnum.equals(MerchantEnum.WX)
|| reg == null || ObjectUtils.isEmpty(OBS_DOCUMENT)) { || reg == null || ObjectUtils.isEmpty(OBS_DOCUMENT)) {
return; return;
} }
log.info("[推送]产科建档推送通知..."); log.info("[推送]产科建档推送通知...");
String patientId = reg.getPatientId(); String patientId = reg.getPatientId();
if ( patientId == null) { if (patientId == null) {
log.warn("[推送]产科建档推送通知失败,参数缺失~ patientId= null"); log.warn("[推送]产科建档推送通知失败,参数缺失~ patientId= null");
return; return;
} }
RequestBody requestBody = new FormBody.Builder() RequestBody requestBody = new FormBody.Builder()
.add("patientId",patientId) .add("patientId", patientId)
.add("content","[孕产建档提示]尊敬的孕妈妈您好!为了向您提供更好的服务,请点击下方链接完成孕产建档,若您已建档请忽略!") .add("content", "[孕产建档提示]尊敬的孕妈妈您好!为了向您提供更好的服务,请点击下方链接完成孕产建档,若您已建档请忽略!")
.add("url","https://zhck.hhzyy.com:10082/wxapp/") .add("url", "https://zhck.hhzyy.com:10082/wxapp/")
.add("organizeName",ORGANIZENAME) .add("organizeName", ORGANIZENAME)
.add("buttonName","进入产科建档系统") .add("buttonName", "进入产科建档系统")
.build(); .build();
OkHttpHelper.post(OBS_DOCUMENT, requestBody); OkHttpHelper.post(OBS_DOCUMENT, requestBody);
} catch (Exception e) { } catch (Exception e) {

@ -1,9 +1,12 @@
package com.ynxbd.wx.config; package com.ynxbd.wx.config;
import com.ynxbd.common.helper.ProperHelper; import com.ynxbd.common.helper.ProperHelper;
import com.ynxbd.common.helper.common.URLHelper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import javax.annotation.Nullable;
@Slf4j @Slf4j
public class WeChatConfig { public class WeChatConfig {
private WeChatConfig() { private WeChatConfig() {
@ -16,56 +19,74 @@ public class WeChatConfig {
public static final String AES_KEY; public static final String AES_KEY;
public static final String MCH_ID; public static final String MCH_ID;
public static final String MCH_KEY; public static final String MCH_KEY;
//
// 域名
public static final String DOMAIN;
// 请求路径
public static final String BASE_REQ_URL;
// 静态资源请求路径
public static final String WEB_REQ_URL;
// 部署的服务名称
private static final String DEPLOY_SERVER_NAME;
// 静态资源路径
private static final String WEB_STATIC_PATH;
// 退费密码
public static final String PASSWORD; public static final String PASSWORD;
public static final String DEV_OPEN_IDS; public static final String DEV_OPEN_IDS;
//
private static String BASE_URL;
private static String WEB_PATH;
private static String CACHE_WEB_URL = null;
// 开启预结算(第2开关) // 开启预结算(第2开关)
public static boolean IS_RECIPE_PREPAY; public static final boolean IS_RECIPE_PREPAY;
// 判断链接是否有https // 判断链接是否有https
public static boolean HAS_HTTPS_BY_BASE_URL; public static final boolean HAS_HTTPS_BY_BASE_URL;
// 医共体配置
public static final boolean IS_ENABLE_GMC;
// 是否为医共体主服务
public static final boolean IS_GMC_SERVER;
// public static final String GMC_AUTH_APP_ID;
// public static final String GMC_AUTH_APP_SECRET;
public static final String GMC_AUTH_DOMAIN;
static { static {
ProperHelper config = new ProperHelper().read("wx.properties"); ProperHelper config = new ProperHelper().read("wx.properties");
IS_RECIPE_PREPAY = config.getBoolean("wx.is_recipe_prepay", false);
APP_ID = config.getString("wx.appId"); APP_ID = config.getString("wx.app_id");
APP_SECRET = config.getString("wx.appSecret"); APP_SECRET = config.getString("wx.app_secret");
AES_KEY = config.getString("wx.aes_key");
TOKEN = config.getString("wx.token"); TOKEN = config.getString("wx.token");
AES_KEY = config.getString("wx.aesKey"); // 商户配置
BASE_URL = config.getString("wx.baseURL"); MCH_ID = config.getString("wx.mch_id");
PASSWORD = config.getString("wx.password"); MCH_KEY = config.getString("wx.mch_key");
// 商户
MCH_ID = config.getString("wx.mchId");
MCH_KEY = config.getString("wx.mchKey");
DEV_OPEN_IDS = config.getString("wx.dev_open_ids", ""); DOMAIN = config.getString("wx.domain");
DEPLOY_SERVER_NAME = config.getString("wx.deploy_server_name");
WEB_STATIC_PATH = config.getString("wx.web_static_path", "");
WEB_PATH = config.getString("wx.webPath"); BASE_REQ_URL = toReqUrl(DOMAIN + "/" + DEPLOY_SERVER_NAME);
if (WEB_PATH == null) { WEB_REQ_URL = toReqUrl(DOMAIN + "/" + DEPLOY_SERVER_NAME + WEB_STATIC_PATH);
WEB_PATH = "";
}
if (BASE_URL == null) { if (DOMAIN == null || DEPLOY_SERVER_NAME == null) {
log.error("【微信】读取配置文件wx.properties失败"); log.error("【微信】读取配置文件wx.properties失败");
} else {
HAS_HTTPS_BY_BASE_URL = BASE_URL.contains("https:");
} }
} HAS_HTTPS_BY_BASE_URL = (BASE_REQ_URL != null && BASE_REQ_URL.contains("https:"));
PASSWORD = config.getString("wx.password");
DEV_OPEN_IDS = config.getString("wx.dev_open_ids", "");
IS_RECIPE_PREPAY = config.getBoolean("wx.is_recipe_prepay", false);
public static String getBaseUrl() { // 医共体
if (BASE_URL == null) { IS_ENABLE_GMC = config.getBoolean("wx.gmc.is_enable", false);
BASE_URL = ""; // GMC_AUTH_APP_ID = config.getString("wx.gmc.auth_app_id");
} // GMC_AUTH_APP_SECRET = config.getString("wx.gmc.auth_app_secret");
GMC_AUTH_DOMAIN = config.getString("wx.gmc.auth_domain");
if (BASE_URL.isEmpty()) return BASE_URL; IS_GMC_SERVER = DOMAIN != null && DOMAIN.equals(GMC_AUTH_DOMAIN);
}
String path = BASE_URL; // 给链接末尾加上"/"
private static String toReqUrl(String path) {
String suffix = path.substring(path.length() - 1); String suffix = path.substring(path.length() - 1);
if (!"/".equals(suffix)) { if (!"/".equals(suffix)) {
path += "/"; path += "/";
@ -73,95 +94,80 @@ public class WeChatConfig {
return path; return path;
} }
public static String getBaseUrlByState(boolean isHttps) { public static String getBaseURL() {
if (isHttps) { return BASE_REQ_URL;
return getHttpsBaseUrl();
}
return getBaseUrl();
} }
public static String getHttpsBaseUrl() { public static String getHttpsBaseURL() {
String url = getBaseUrl(); return URLHelper.URLToHttps(BASE_REQ_URL);
if (url != null && url.contains("http") && !url.contains("https")) {
url = url.replace("http", "https");
}
return url;
} }
/** public static String getBaseURL(boolean isHttps) {
* 获取配置中原本的域名
*/
public static String getBaseDomain(boolean isHttps) {
if (BASE_URL.length() < 4) {
return BASE_URL;
}
String url = BASE_URL.substring(0, BASE_URL.length() - 4);
if (isHttps) { if (isHttps) {
int index = url.indexOf("http://"); return getHttpsBaseURL();
if (index == 0) {
url = "https://" + url.substring(7);
}
} }
return url; return getBaseURL();
} }
// 域名 /**
* 获取域名
*
* @param isHttps 是否强制替换为https
* @return String
*/
public static String getDomain(boolean isHttps) { public static String getDomain(boolean isHttps) {
if (BASE_URL.length() < 4) { return getDomain(isHttps, true);
return BASE_URL;
}
String url = BASE_URL;
if (isHttps) {
int index = url.indexOf("http://");
if (index == 0) {
url = "https://" + url.substring(7);
}
}
return url.substring(0, url.length() - 4);
} }
public static String getWebPath(boolean isPrefix, boolean isSuffix) { /**
if (WEB_PATH == null || WEB_PATH.isEmpty()) return "/"; * 获取域名
*
String path = WEB_PATH; * @param isHttps 是否强制替换为https
String prefix = path.substring(0, 1); * @param hasProtocol 是否含有协议
if ("/".equals(prefix)) { * @return String
path = isPrefix ? path : path.substring(1); */
} else { public static String getDomain(boolean isHttps, boolean hasProtocol) {
path = isPrefix ? ("/" + path) : path; String domain = DOMAIN;
if (domain == null) {
return null;
} }
if (!hasProtocol) {
String suffix = path.substring(path.length() - 1); int index = domain.indexOf("://");
if ("/".equals(suffix)) { return index >= 0 ? domain.substring(index + 3) : domain;
path = isSuffix ? path : path.substring(0, path.length() - 1);
} else {
path = isSuffix ? (path + "/") : path;
} }
return path; if (isHttps) { // 强制替换
domain = URLHelper.URLToHttps(domain);
}
return domain;
} }
public static String getWebReqURL() {
return WEB_REQ_URL;
}
public static String getWebUrl() { public static String getWebReqURL(boolean isHttps) {
if (!ObjectUtils.isEmpty(CACHE_WEB_URL)) { String url = WEB_REQ_URL;
return CACHE_WEB_URL; if (isHttps && !HAS_HTTPS_BY_BASE_URL) {
} url = URLHelper.URLToHttps(url);
String webPath = getWebPath(false, true);
if ("/".equals(webPath)) {
webPath = "";
} }
CACHE_WEB_URL = getBaseUrl() + webPath; return url;
return CACHE_WEB_URL;
} }
public static String getWebUrl(boolean isHttps) { public static String getGMCAuthDomain(boolean isHttps, boolean isServerName) {
String webUrl = getWebUrl(); String domain = GMC_AUTH_DOMAIN;
if (isHttps && !HAS_HTTPS_BY_BASE_URL) { if (domain == null) {
webUrl = webUrl.replace("http://", "https://"); return null;
}
if (isHttps) { // 强制替换
domain = URLHelper.URLToHttps(domain);
} }
return webUrl; if (isServerName) {
return toReqUrl(domain + "/" + DEPLOY_SERVER_NAME);
}
return domain;
} }
/** /**
* 判断是否为开发用户 * 判断是否为开发用户
*/ */

@ -24,6 +24,6 @@ public class TJServlet extends HttpServlet {
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.sendRedirect(WeChatConfig.getWebUrl() + "report-shilin-tj.html"); resp.sendRedirect(WeChatConfig.getWebReqURL() + "report-shilin-tj.html");
} }
} }

@ -8,7 +8,6 @@ import com.ynxbd.wx.config.WeChatConfig;
import com.ynxbd.wx.wxfactory.AesWxHelper; import com.ynxbd.wx.wxfactory.AesWxHelper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC; import org.slf4j.MDC;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -81,7 +80,7 @@ public class QServlet extends HttpServlet {
groupTreatNum = hasTreatNum ? ("&treatNum=" + groupTreatNum) : ""; groupTreatNum = hasTreatNum ? ("&treatNum=" + groupTreatNum) : "";
if (MerchantEnum.WX.equals(merchantEnum)) { if (MerchantEnum.WX.equals(merchantEnum)) {
response.sendRedirect(WeChatConfig.getWebUrl() + "pay-qr-recipe.html?p=" + patientId + "&enp=" + AesWxHelper.encode(patientId) + cardNo + groupTreatNum); response.sendRedirect(WeChatConfig.getWebReqURL() + "pay-qr-recipe.html?p=" + patientId + "&enp=" + AesWxHelper.encode(patientId) + cardNo + groupTreatNum);
} }
} }

@ -148,9 +148,9 @@ public class QRPayServlet2 extends HttpServlet {
unifiedorder.setTotal_fee(String.valueOf(fFee)); unifiedorder.setTotal_fee(String.valueOf(fFee));
unifiedorder.setSpbill_create_ip(request.getRemoteAddr()); unifiedorder.setSpbill_create_ip(request.getRemoteAddr());
unifiedorder.setNotify_url(WeChatConfig.getBaseUrl() + "old_pay_notify_servlet"); unifiedorder.setNotify_url(WeChatConfig.getBaseURL() + "old_pay_notify_servlet");
unifiedorder.setTrade_type("NATIVE"); unifiedorder.setTrade_type("NATIVE");
log.info("扫码回调地址:" + WeChatConfig.getBaseUrl() + "old_pay_notify_servlet"); log.info("扫码回调地址:" + WeChatConfig.getBaseURL() + "old_pay_notify_servlet");
UnifiedorderResult unifiedorderResult = PayMchAPI.payUnifiedorder(unifiedorder, mchKey); UnifiedorderResult unifiedorderResult = PayMchAPI.payUnifiedorder(unifiedorder, mchKey);

@ -15,6 +15,13 @@ public class AesWxHelper extends AesHelper {
return encryptHex(data, KEY, IV); return encryptHex(data, KEY, IV);
} }
public static String encode(String data, boolean isDataNotNull) {
if (isDataNotNull && ObjectUtils.isEmpty(data)) {
return null;
}
return encryptHex(data, KEY, IV);
}
public static String decode(String enData) { public static String decode(String enData) {
if (ObjectUtils.isEmpty(enData)) return null; if (ObjectUtils.isEmpty(enData)) return null;
return decryptHex(enData, KEY, IV); return decryptHex(enData, KEY, IV);

@ -2,10 +2,8 @@ package com.ynxbd.wx.wxfactory;
import com.ynxbd.common.bean.Patient; import com.ynxbd.common.bean.Patient;
import com.ynxbd.common.bean.User; import com.ynxbd.common.bean.User;
import com.ynxbd.common.helper.common.AesMicroHelper; import com.ynxbd.common.helper.common.*;
import com.ynxbd.common.helper.common.Base64Helper; import com.ynxbd.common.helper.http.OkHttpHelper;
import com.ynxbd.common.helper.common.CodeHelper;
import com.ynxbd.common.helper.common.JsonHelper;
import com.ynxbd.common.result.Result; import com.ynxbd.common.result.Result;
import com.ynxbd.common.service.PatientService; import com.ynxbd.common.service.PatientService;
import com.ynxbd.wx.config.WeChatConfig; import com.ynxbd.wx.config.WeChatConfig;
@ -13,6 +11,8 @@ import com.ynxbd.wx.wxfactory.bean.SnsOath2AccessToken;
import com.ynxbd.wx.wxfactory.bean.SnsUserInfo; import com.ynxbd.wx.wxfactory.bean.SnsUserInfo;
import com.ynxbd.wx.wxfactory.bean.auth.AuthData; import com.ynxbd.wx.wxfactory.bean.auth.AuthData;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.FormBody;
import okhttp3.RequestBody;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.ehcache.Cache; import org.ehcache.Cache;
@ -28,38 +28,48 @@ import java.util.Map;
@Slf4j @Slf4j
public class WxAuthHelper { public class WxAuthHelper {
private static final int SESSION_MAX_INACTIVE_INTERVAL = 60 * 60; // session最大存活时间 1H private static final int SESSION_MAX_INACTIVE_INTERVAL = 60 * 60; // session最大存活时间 1H
public static String auth(HttpServletRequest request, HttpServletResponse response, boolean isUserInfo) { public static String auth(HttpServletRequest request, HttpServletResponse response, boolean isUserInfo) {
String code = request.getParameter("code"); String code = request.getParameter("code");
String state = request.getParameter("state"); String state = request.getParameter("state"); // base64
String hash = request.getParameter("hash"); String enuId = request.getParameter("enuId");
log.info("[授权] code={}, state={}, enuId={}", code, state, enuId);
try { try {
if (hash == null) { state = state == null ? "" : URLDecoder.decode(Base64Helper.decode(state), "UTF-8");
hash = ""; String enUnionId = null;
} else { String protocolState = null;
hash = Base64Helper.decode(hash);
hash = URLDecoder.decode(hash, "UTF-8"); if (!ObjectUtils.isEmpty(enuId)) {
int index = enuId.indexOf("@protocolState=");
if (index == -1) index = enuId.indexOf("%40protocolState="); // 防止数据转义失败
if (index != -1) {
enUnionId = enuId.substring(0, index);
protocolState = enuId.substring(index);
}
} }
log.info("[授权-解码] enUnionId={}, protocolState={}, state={}", enUnionId, protocolState, state);
SnsOath2AccessToken snsToken = WxFactory.Base.OAuth().oauth2AccessToken(WeChatConfig.APP_ID, WeChatConfig.APP_SECRET, code); SnsOath2AccessToken snsToken = WxFactory.Base.OAuth().oauth2AccessToken(WeChatConfig.APP_ID, WeChatConfig.APP_SECRET, code);
if (snsToken != null) { if (snsToken != null) {
String openid = snsToken.getOpenid(); String openid = snsToken.getOpenid();
String unionId = snsToken.getUnionid();
if (unionId == null) {
log.info("[测试] enUnionId={}", enUnionId);
}
if (openid != null) { if (openid != null) {
HttpSession session = request.getSession(); HttpSession session = request.getSession();
session.setMaxInactiveInterval(SESSION_MAX_INACTIVE_INTERVAL); session.setMaxInactiveInterval(SESSION_MAX_INACTIVE_INTERVAL);
session.setAttribute("openid", openid); session.setAttribute("openid", openid);
Cache<String, User> cache = WxCacheHelper.getUserCache(); Cache<String, User> cache = WxCacheHelper.getUserCacheManager();
if (WeChatConfig.isDevUser(openid) || !cache.containsKey(openid)) { if (WeChatConfig.isDevUser(openid) || !cache.containsKey(openid)) {
String unionId = snsToken.getUnionid();
User user = new User(); User user = new User();
user.setUnionId(unionId); user.setUnionId(unionId);
user.setOpenid(openid); user.setOpenid(openid);
user.setIsSnapShotUser(snsToken.getIsSnapShotUser()); user.setIsSnapShotUser(snsToken.getIsSnapShotUser());
user.setPatientList(new PatientService().queryPatientList(openid, unionId, true)); user.setPatientList(new PatientService().queryPatientList(openid, unionId, true));
if (isUserInfo) { if (isUserInfo) {
@ -69,10 +79,7 @@ public class WxAuthHelper {
user.setAvatar(snsUser.getHeadImgUrl()); user.setAvatar(snsUser.getHeadImgUrl());
user.setNickName(snsUser.getNickname_emoji()); user.setNickName(snsUser.getNickname_emoji());
user.setProvince(snsUser.getProvince()); user.setProvince(snsUser.getProvince());
Integer sex = snsUser.getSex(); user.setGenderByInt(snsUser.getSex());
if (sex != null) {
user.setGender(sex == 1 ? "男" : "女");
}
user.setCity(snsUser.getCity()); user.setCity(snsUser.getCity());
user.setLanguage(snsUser.getLanguage()); user.setLanguage(snsUser.getLanguage());
} }
@ -86,10 +93,7 @@ public class WxAuthHelper {
if (snsUser != null) { if (snsUser != null) {
user.setAvatar(snsUser.getHeadImgUrl()); user.setAvatar(snsUser.getHeadImgUrl());
user.setNickName(snsUser.getNickname_emoji()); user.setNickName(snsUser.getNickname_emoji());
Integer sex = snsUser.getSex(); user.setGenderByInt(snsUser.getSex());
if (sex != null) {
user.setGender(sex == 1 ? "男" : "女");
}
} }
} }
} }
@ -97,24 +101,18 @@ public class WxAuthHelper {
} }
} }
if (hash == null) hash = "";
if (state == null) state = "";
String protocol = ""; //
int index = state.indexOf("@protocol="); if (WeChatConfig.HAS_HTTPS_BY_BASE_URL) { // 强制为https
if (index == -1) index = state.indexOf("%40protocol="); // 防止数据转义失败 String httpsURL = URLHelper.URLToHttps(state);
if (index != -1) { state = httpsURL == null ? "" : httpsURL;
protocol = state.substring(index);
state = state.substring(0, index);
} }
String domain = WeChatConfig.getBaseDomain(WeChatConfig.HAS_HTTPS_BY_BASE_URL || "@protocol=1".equals(protocol)); // 配置中baseURL有"https"时优先级最高 ["@protocol=1"为https;"@protocol=0"为默认的http;] if (state.contains(".html")) { // 网页授权配置
if (state.contains(".html")) { return state;
return domain + state + hash;
} else { } else {
String baseUrl = WeChatConfig.getBaseUrl(); String baseUrl = WeChatConfig.getBaseURL();
if (baseUrl != null && state.contains(baseUrl)) { if (baseUrl != null && state.contains(baseUrl)) {
return domain + state + hash; return state;
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -124,22 +122,50 @@ public class WxAuthHelper {
} }
public static Result isAuth(HttpServletRequest request) throws Exception { public static Result isAuth(HttpServletRequest request, boolean isPayOAuth) throws Exception {
HttpSession session = request.getSession();
String token = request.getParameter("token"); // 前端缓存 String token = request.getParameter("token"); // 前端缓存
String state = request.getParameter("state");
String isUserInfo = request.getParameter("isUserInfo");
String protocolState = request.getParameter("protocolState");
String enuId = ParamHelper.filterParamNull(request.getParameter("enuId"), "");
String deState = URLDecoder.decode(Base64Helper.decode(state), "UTF-8");
if (WeChatConfig.IS_ENABLE_GMC && !WeChatConfig.IS_GMC_SERVER && !isPayOAuth) { // 开启医共体开关 & 不是医共体主服务器 & 不是支付授权
try { // 请求转发
String serverDomain = WeChatConfig.getDomain(false, false);
if (deState != null && serverDomain != null && !deState.contains(serverDomain)) {
return Result.error("授权域名不匹配");
}
RequestBody requestBody = new FormBody.Builder()
.add("token", token)
.add("state", state)
.add("isUserInfo", isUserInfo)
.add("enuId", enuId)
.add("protocolState", protocolState)
.build();
log.info("[认证请求转发] URL:[{}]", WeChatConfig.getGMCAuthDomain(isHttpsWithProxy(request), true));
String data = OkHttpHelper.post(WeChatConfig.getGMCAuthDomain(isHttpsWithProxy(request), true) + "wx_auth/is_auth", requestBody);
return Result.dataToResult(data, true);
} catch (Exception e) {
return Result.error(e);
}
}
boolean isFindUserInfo = ("true".equals(isUserInfo));
AuthData authData = new AuthData(); AuthData authData = new AuthData();
String cacheOpenid = authData.decodeToken(token); String cacheOpenid = authData.decodeToken(token, WeChatConfig.APP_ID);
if (cacheOpenid != null) { if (cacheOpenid != null) {
log.info("[微信token认证] token={}, openid={}", token, cacheOpenid); log.info("[微信token认证] token={}, openid={}", token, cacheOpenid);
User user = WxCacheHelper.getCacheUser(cacheOpenid); User user = WxCacheHelper.getCacheUser(cacheOpenid);
List<Patient> patients; List<Patient> patients;
if (user == null) { if (user == null) {
patients = new PatientService().queryPatientList(cacheOpenid, null, true); patients = new PatientService().queryPatientList(cacheOpenid, null, true);
Cache<String, User> cache = WxCacheHelper.getUserCache(); Cache<String, User> cache = WxCacheHelper.getUserCacheManager();
User addCache = new User(); User addCache = new User();
addCache.setUnionId("");
addCache.setOpenid(cacheOpenid); addCache.setOpenid(cacheOpenid);
addCache.setUnionId(authData.getUnionId());
addCache.setAvatar(authData.getAvatar()); addCache.setAvatar(authData.getAvatar());
addCache.setNickName(authData.getNickName()); addCache.setNickName(authData.getNickName());
addCache.setPatientList(patients); addCache.setPatientList(patients);
@ -151,88 +177,108 @@ public class WxAuthHelper {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("openid", cacheOpenid); map.put("openid", cacheOpenid);
map.put("token", token); map.put("token", token);
map.put("unionId", ""); map.put("enOpenId", AesWxHelper.encode(cacheOpenid, true));
map.put("enUnionId", AesWxHelper.encode(authData.getUnionId(), true));
map.put("date", new Date()); map.put("date", new Date());
map.put("avatar", authData.getAvatar()); map.put("avatar", authData.getAvatar());
map.put("nickName", authData.getNickName()); map.put("nickName", authData.getNickName());
map.put("patients", CodeHelper.get28UUID() + Base64Helper.encode(URLEncoder.encode(JsonHelper.toJsonString(patients), "UTF-8"))); map.put("patients", CodeHelper.get28UUID() + Base64Helper.encode(URLEncoder.encode(JsonHelper.toJsonString(patients), "UTF-8")));
map.put("hash", request.getParameter("hash"));
map.put("enParams", AesMicroHelper.encode(cacheOpenid)); map.put("enParams", AesMicroHelper.encode(cacheOpenid));
return Result.success(map); return Result.success(map);
} }
HttpSession session = request.getSession();
Object openid = session.getAttribute("openid"); Object openid = session.getAttribute("openid");
if (openid != null) { if (openid != null) {
log.info("[微信认证]openid={}", openid); log.info("[微信认证]openid={}", openid);
User user = WxCacheHelper.getCacheUser((String) openid); User user = WxCacheHelper.getCacheUser((String) openid);
if (user == null) { if (user == null) {
return Result.success(getAuthUrl(request)); return Result.success(getAuthUrl(request, state, isFindUserInfo, enuId, protocolState));
} }
String isUserInfo = request.getParameter("isUserInfo"); if (isFindUserInfo) { // 更换授权模式,需更新信息
if ("true".equals(isUserInfo)) { // 更换授权模式,需更新信息
if (user.getNickName() == null || user.getAvatar() == null) { if (user.getNickName() == null || user.getAvatar() == null) {
return Result.success(getAuthUrl(request)); return Result.success(getAuthUrl(request, state, true, enuId, protocolState));
} }
} }
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("openid", openid); map.put("openid", openid);
map.put("token", new AuthData().createToken(openid.toString(), user.getAvatar(), user.getNickName())); map.put("token", new AuthData().createToken(WeChatConfig.APP_ID, openid.toString(), user.getUnionId(), user.getAvatar(), user.getNickName()));
map.put("unionId", user.getUnionId()); map.put("enOpenId", AesWxHelper.encode(openid.toString(), true));
map.put("enUnionId", AesWxHelper.encode(user.getUnionId(), true));
map.put("date", new Date()); map.put("date", new Date());
map.put("avatar", user.getAvatar()); map.put("avatar", user.getAvatar());
map.put("nickName", user.getNickName()); map.put("nickName", user.getNickName());
map.put("patients", CodeHelper.get28UUID() + Base64Helper.encode(URLEncoder.encode(JsonHelper.toJsonString(user.getPatientList()), "UTF-8"))); map.put("patients", CodeHelper.get28UUID() + Base64Helper.encode(URLEncoder.encode(JsonHelper.toJsonString(user.getPatientList()), "UTF-8")));
map.put("hash", request.getParameter("hash"));
map.put("enParams", AesMicroHelper.encode(openid.toString())); map.put("enParams", AesMicroHelper.encode(openid.toString()));
return Result.success(map); return Result.success(map);
} }
return Result.success(getAuthUrl(request)); return Result.success(getAuthUrl(request, state, isFindUserInfo, enuId, protocolState));
} }
private static final String OAUTH_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WeChatConfig.APP_ID + "&redirect_uri="; private static final String OAUTH_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WeChatConfig.APP_ID + "&redirect_uri=";
private static String getAuthUrl(HttpServletRequest request, String state, boolean isFindUserInfo, String enuId, String protocolState) {
private static String getAuthUrl(HttpServletRequest request) {
// StringBuffer url = request.getRequestURL(); // StringBuffer url = request.getRequestURL();
// String baseUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append("/").toString(); // String baseUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append("/").toString();
String state = request.getParameter("state"); if (state == null) {
String hash = request.getParameter("hash"); return null;
String isUserInfo = request.getParameter("isUserInfo");
String protocolState = request.getParameter("protocolState"); // 1:https;0:http
if (ObjectUtils.isEmpty(protocolState)) {
protocolState = "0";
} }
if (hash == null) { String api = isFindUserInfo ? "u_auth" : "b_auth";
hash = ""; String scope = isFindUserInfo ? "snsapi_userinfo" : "snsapi_base";
}
state = OAUTH_URL + WeChatConfig.getBaseURL(WeChatConfig.HAS_HTTPS_BY_BASE_URL || isHttpsWithProxy(request)) +
"wx_auth/" + api +
"?state=" + state +
"&response_type=code" +
"&scope=" + scope + "&forcePopup=true" +
"&enuId=" + (enuId == null ? "" : enuId) +
(protocolState == null ? "" : ("%40protocolState=" + protocolState)) +
"#wechat_redirect";
return Base64Helper.encode(state);
}
if (state != null) {
String decode = Base64Helper.decode(state);
if (!decode.contains(".html") && !decode.contains(".jsp")) {
decode = "my-info.html";
}
String api = ("true".equals(isUserInfo) ? "u_auth" : "b_auth"); // 是否为https请求
String scope = ("true".equals(isUserInfo) ? "snsapi_userinfo" : "snsapi_base"); public static boolean isHttpsWithProxy(HttpServletRequest request) {
// 优先检查代理头(适用于反向代理场景)
// 配置中baseURL有"https"时优先级最高 String forwardedProto = request.getHeader("X-Forwarded-Proto");
state = OAUTH_URL + WeChatConfig.getBaseUrlByState((WeChatConfig.HAS_HTTPS_BY_BASE_URL || "1".equals(protocolState))) + if (forwardedProto != null) {
"wx_auth/" + api + return "https".equalsIgnoreCase(forwardedProto);
"?hash=" + hash +
"&response_type=code" +
"&scope=" + scope + "&forcePopup=true" +
"&state=" + decode +
"%40protocol=" + protocolState +
"#wechat_redirect";
state = Base64Helper.encode(state);
} }
return state; // 未经过代理,直接检查原生请求
return request.isSecure();
} }
// // 医共体开启 & 不是支付授权
// private static boolean isAuthGMC(boolean isPayOAuth) {
// return WeChatConfig.IS_ENABLE_GMC && !isPayOAuth;
// }
// private static String getOAuthURL(HttpServletRequest request, boolean isPayOAuth) {
// boolean isHttps = WeChatConfig.HAS_HTTPS_BY_BASE_URL || isHttpsWithProxy(request);
// return isAuthGMC(isPayOAuth)
// ? "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WeChatConfig.GMC_AUTH_APP_ID + "&redirect_uri=" + WeChatConfig.getGMCAuthDomain(isHttps, true)
// : "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WeChatConfig.APP_ID + "&redirect_uri=" + WeChatConfig.getBaseURL(isHttps);
// }
// private static SnsOath2AccessToken getOath2AccessToken(String code, boolean isPayOAuth) {
// if (isAuthGMC(isPayOAuth)) {
// return WxFactory.Base.OAuth().oauth2AccessToken(WeChatConfig.GMC_AUTH_APP_ID, WeChatConfig.GMC_AUTH_APP_SECRET, code);
// }
// return WxFactory.Base.OAuth().oauth2AccessToken(WeChatConfig.APP_ID, WeChatConfig.APP_SECRET, code);
// }
// // 获取重定向链接
// private static String getAuthDomain(HttpServletRequest request, boolean isPayOAuth) {
// if (isAuthGMC(isPayOAuth)) {
// return WeChatConfig.getGMCAuthDomain(true, false); // 强制为https
// }
// return WeChatConfig.getDomain(WeChatConfig.HAS_HTTPS_BY_BASE_URL || isHttpsWithProxy(request)); // 配置中baseURL有"https"时优先级最高 ["@protocol=1"为https;"@protocol=0"为默认的http;]
// }
} }

@ -9,35 +9,35 @@ import org.ehcache.Cache;
@Slf4j @Slf4j
public class WxCacheHelper { public class WxCacheHelper {
static {
createUserCache();
createAccessTokenCache();
}
// 缓存 // 缓存
private static Cache<String, User> USER_CACHE; private static Cache<String, User> USER_CACHE;
private static Cache<String, AccessToken> ACCESS_TOKEN_CACHE; // private static Cache<String, User> PAY_USER_CACHE;
private static Cache<String, AccessToken> ACCESS_TOKEN_CACHE;
private static Cache<String, JsapiTicket> JSAPI_TICKET_CACHE; private static Cache<String, JsapiTicket> JSAPI_TICKET_CACHE;
private synchronized static void createUserCache() { static {
createUserCacheManager();
createAccessTokenCache();
}
private synchronized static void createUserCacheManager() {
if (USER_CACHE == null) { if (USER_CACHE == null) {
USER_CACHE = EhCacheConfig.createCacheTTL(String.class, User.class, "wx_auth_cache", (5400L)); // 一个半小时 USER_CACHE = EhCacheConfig.createCacheTTL(String.class, User.class, "wx_oauth_cache", (5400L)); // 一个半小时
} }
} }
public static Cache<String, User> getUserCacheManager() {
public static Cache<String, User> getUserCache() {
if (USER_CACHE == null) { if (USER_CACHE == null) {
createUserCache(); createUserCacheManager();
} }
return USER_CACHE; return USER_CACHE;
} }
public static void removeUser(String openid) { public static void removeUser(String openid) {
Cache<String, User> cache = getUserCache(); Cache<String, User> cache = getUserCacheManager();
if (cache != null) { if (cache != null) {
cache.remove(openid); cache.remove(openid);
} }
@ -45,7 +45,7 @@ public class WxCacheHelper {
public static User getCacheUser(String openid) { public static User getCacheUser(String openid) {
if (USER_CACHE == null) { if (USER_CACHE == null) {
createUserCache(); createUserCacheManager();
} }
return USER_CACHE.get(openid); return USER_CACHE.get(openid);
} }

@ -221,7 +221,7 @@ public class WxMedHelper {
public static JSONObject getMdAuthRedirectUrl(String redirectUrl) { public static JSONObject getMdAuthRedirectUrl(String redirectUrl) {
redirectUrl = (ObjectUtils.isEmpty(redirectUrl) ? "" : redirectUrl); redirectUrl = (ObjectUtils.isEmpty(redirectUrl) ? "" : redirectUrl);
JSONObject jsonObj = new JSONObject(); JSONObject jsonObj = new JSONObject();
jsonObj.put("url", WxFactory.Medical.Common().getAuthUrl(WeChatConfig.getWebUrl() + redirectUrl)); jsonObj.put("url", WxFactory.Medical.Common().getAuthUrl(WeChatConfig.getWebReqURL() + redirectUrl));
jsonObj.put("type", MerchantEnum.WX_MEDICAL.CODE); jsonObj.put("type", MerchantEnum.WX_MEDICAL.CODE);
return jsonObj; return jsonObj;
} }
@ -235,7 +235,7 @@ public class WxMedHelper {
JSONObject jsonObj = new JSONObject(); JSONObject jsonObj = new JSONObject();
String authUrl = WxFactory.Medical.Common().getAuthUrl(WeChatConfig.getWebUrl(isHttps) + callbackUrl); String authUrl = WxFactory.Medical.Common().getAuthUrl(WeChatConfig.getWebReqURL(isHttps) + callbackUrl);
log.info("[医保] authUrl={}", authUrl); log.info("[医保] authUrl={}", authUrl);
if (ObjectUtils.isEmpty(authUrl)) { if (ObjectUtils.isEmpty(authUrl)) {
jsonObj.put("url", "config_error"); jsonObj.put("url", "config_error");
@ -367,9 +367,8 @@ public class WxMedHelper {
return token; return token;
} }
public static void main(String[] args) { // public static void main(String[] args) {
String a = "{\\\"payAuthNo\\\":\\\"AUTH530100202509151551446281313\\\",\\\"setlLatlnt\\\":\\\"0,0\\\",\\\"payOrdId\\\":\\\"ORD530100202509151551510239700\\\"}"; // String a = "{\\\"payAuthNo\\\":\\\"AUTH530100202509151551446281313\\\",\\\"setlLatlnt\\\":\\\"0,0\\\",\\\"payOrdId\\\":\\\"ORD530100202509151551510239700\\\"}";
// }
}
} }

@ -181,7 +181,7 @@ public class WxPayHelper {
unifiedorder.setTotal_fee(cents); // 金额分 unifiedorder.setTotal_fee(cents); // 金额分
unifiedorder.setSpbill_create_ip(ip); unifiedorder.setSpbill_create_ip(ip);
unifiedorder.setNotify_url(WeChatConfig.getBaseUrl() + merchantEnum.NOTIFY_URL); unifiedorder.setNotify_url(WeChatConfig.getBaseURL() + merchantEnum.NOTIFY_URL);
unifiedorder.setTrade_type("JSAPI"); unifiedorder.setTrade_type("JSAPI");
// 额外参数 // 额外参数
unifiedorder.setAttach(notifyType); unifiedorder.setAttach(notifyType);
@ -1194,7 +1194,7 @@ public class WxPayHelper {
unifiedorder.setTotal_fee(cents); // 金额分 unifiedorder.setTotal_fee(cents); // 金额分
unifiedorder.setSpbill_create_ip(ip); unifiedorder.setSpbill_create_ip(ip);
unifiedorder.setNotify_url(WeChatConfig.getBaseUrl() + notifyUrl); unifiedorder.setNotify_url(WeChatConfig.getBaseURL() + notifyUrl);
unifiedorder.setTrade_type("NATIVE"); unifiedorder.setTrade_type("NATIVE");
// 额外参数 // 额外参数
unifiedorder.setAttach(notifyType); unifiedorder.setAttach(notifyType);

@ -55,7 +55,7 @@ public class Client {
/** /**
* 获取微信token * 获取微信oauth2认证授权token
* *
* @param appId appId * @param appId appId
* @param appSecret appSecret * @param appSecret appSecret

@ -8,6 +8,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import java.io.Serializable; import java.io.Serializable;
@ -16,21 +17,26 @@ import java.io.Serializable;
@Setter @Setter
@ToString @ToString
@NoArgsConstructor @NoArgsConstructor
@Slf4j
public class AuthData implements Serializable { public class AuthData implements Serializable {
private static final long serialVersionUID = 202511101525001L; private static final long serialVersionUID = 202511101525001L;
private String openid; private String appId;
private String openId;
private String unionId;
private String createTime; private String createTime;
private String avatar; private String avatar;
private String nickName; private String nickName;
public String createToken(String userOpenid, String avatar, String nickName) { public String createToken(String serverAppId, String userOpenid, String userUnionId, String userAvatar, String userNickName) {
if (userOpenid == null) { if (userOpenid == null) {
return null; return null;
} }
this.openid = userOpenid; this.appId = serverAppId;
this.avatar = avatar; this.openId = userOpenid;
this.nickName = nickName; this.unionId = userUnionId;
this.avatar = userAvatar;
this.nickName = userNickName;
this.createTime = DateHelper.getCurDateTime(); this.createTime = DateHelper.getCurDateTime();
String dataJson = JsonHelper.toJsonString(this); String dataJson = JsonHelper.toJsonString(this);
if (ObjectUtils.isEmpty(dataJson)) { if (ObjectUtils.isEmpty(dataJson)) {
@ -39,7 +45,7 @@ public class AuthData implements Serializable {
return AesWxHelper.encryptHex(dataJson, WeChatConfig.getAesKey(), WeChatConfig.getAesIV()); return AesWxHelper.encryptHex(dataJson, WeChatConfig.getAesKey(), WeChatConfig.getAesIV());
} }
public String decodeToken(String token) { public String decodeToken(String token, String serverAppId) {
if (ObjectUtils.isEmpty(token)) { if (ObjectUtils.isEmpty(token)) {
return null; return null;
} }
@ -51,15 +57,23 @@ public class AuthData implements Serializable {
if (authData == null) { if (authData == null) {
return null; return null;
} }
String cacheOpenid = authData.getOpenid(); String cacheOpenid = authData.getOpenId();
if (ObjectUtils.isEmpty(cacheOpenid)) { if (ObjectUtils.isEmpty(cacheOpenid)) {
return null; return null;
} }
String cacheAppId = authData.getAppId();
if (!cacheAppId.equals(serverAppId)) {
log.warn("[微信认证]token中的AppId和配置的不一致");
return null;
}
String cacheTime = authData.getCreateTime(); String cacheTime = authData.getCreateTime();
Boolean hasValidity = DateHelper.inDateRangeByDay(-3, cacheTime); Boolean hasValidity = DateHelper.inDateRangeByDay(-3, cacheTime);
if (hasValidity != null && hasValidity) { // 在有效期内 if (hasValidity != null && hasValidity) { // 在有效期内
this.openid = cacheOpenid; this.openId = cacheOpenid;
this.unionId = authData.getUnionId();
this.appId = authData.getAppId();
this.avatar = authData.getAvatar(); this.avatar = authData.getAvatar();
this.nickName = authData.getNickName(); this.nickName = authData.getNickName();
this.createTime = cacheTime; this.createTime = cacheTime;

@ -62,7 +62,7 @@ public class WxPassiveReplyHelper {
public static boolean subscribeCommon(HttpServletResponse response, String content, String msgType, String fromUserName, String toUserName, String event) { public static boolean subscribeCommon(HttpServletResponse response, String content, String msgType, String fromUserName, String toUserName, String event) {
log.info("event={}", event); log.info("event={}", event);
if (WxEventEnum.EVENT_SUBSCRIBE.CODE.equals(event)) { if (WxEventEnum.EVENT_SUBSCRIBE.CODE.equals(event)) {
String webUrl = WeChatConfig.getWebUrl(); String webUrl = WeChatConfig.getWebReqURL();
return createLinkMsg(response, fromUserName, toUserName, "清廉承诺", msgType, content, return createLinkMsg(response, fromUserName, toUserName, "清廉承诺", msgType, content,
(webUrl + "wx-subscribe.html"), (webUrl + "wx-subscribe.html"),
(webUrl + "images/message/subscribe.png")); (webUrl + "images/message/subscribe.png"));
@ -118,7 +118,7 @@ public class WxPassiveReplyHelper {
* 文字匹配 * 文字匹配
*/ */
public static boolean textCommon(HttpServletResponse response, String content, String msgType, String fromUserName, String toUserName) { public static boolean textCommon(HttpServletResponse response, String content, String msgType, String fromUserName, String toUserName) {
String webUrl = WeChatConfig.getWebUrl(); String webUrl = WeChatConfig.getWebReqURL();
if (Arrays.asList(new String[]{ if (Arrays.asList(new String[]{
"缓", "缓",
@ -207,8 +207,8 @@ public class WxPassiveReplyHelper {
if (WxEventEnum.MSG_TYPE_EVENT.CODE.equals(msgType)) { if (WxEventEnum.MSG_TYPE_EVENT.CODE.equals(msgType)) {
if (WxEventEnum.EVENT_SUBSCRIBE.CODE.equals(event)) { if (WxEventEnum.EVENT_SUBSCRIBE.CODE.equals(event)) {
String respInfo = "欢迎关注武定忠爱医院!" + String respInfo = "欢迎关注武定忠爱医院!" +
"\n\uD83D\uDD17 <a href='" + WeChatConfig.getWebUrl() + "reg-today.html" + "'>今日挂号</a>" + "\n\uD83D\uDD17 <a href='" + WeChatConfig.getWebReqURL() + "reg-today.html" + "'>今日挂号</a>" +
"\n\uD83D\uDD17 <a href='" + WeChatConfig.getWebUrl() + "reg-reserve.html" + "'>预约挂号</a>"; "\n\uD83D\uDD17 <a href='" + WeChatConfig.getWebReqURL() + "reg-reserve.html" + "'>预约挂号</a>";
XMLTextMessage msg = new XMLTextMessage(fromUserName, toUserName, respInfo); XMLTextMessage msg = new XMLTextMessage(fromUserName, toUserName, respInfo);
msg.outputStreamWrite(getOutputStream(response)); msg.outputStreamWrite(getOutputStream(response));
} }
@ -323,7 +323,7 @@ public class WxPassiveReplyHelper {
XMLNewsMessage.Article article; XMLNewsMessage.Article article;
if (content != null) { if (content != null) {
String webUrl = WeChatConfig.getWebUrl(); String webUrl = WeChatConfig.getWebReqURL();
if (content.equals("支付") || content.equals("微信支付") || content.contains("费")) { if (content.equals("支付") || content.equals("微信支付") || content.contains("费")) {
article = new XMLNewsMessage.Article(); article = new XMLNewsMessage.Article();
article.setTitle("微信支付"); article.setTitle("微信支付");
@ -415,7 +415,7 @@ public class WxPassiveReplyHelper {
} }
if (content.contains("食堂")) { if (content.contains("食堂")) {
String webUrl = WeChatConfig.getWebUrl(); String webUrl = WeChatConfig.getWebReqURL();
return createLinkMsg(response, fromUserName, toUserName, "食堂充值(温馨提示:第一次使用请进行电话号码绑定)", msgType, content, return createLinkMsg(response, fromUserName, toUserName, "食堂充值(温馨提示:第一次使用请进行电话号码绑定)", msgType, content,
("https://passport.whdc2002.com/"), ("https://passport.whdc2002.com/"),
(webUrl + "images/message/food.png")); (webUrl + "images/message/food.png"));

@ -33,7 +33,7 @@ public class CreateMenu extends HttpServlet {
WxMenuButton btn1 = new WxMenuButton(); WxMenuButton btn1 = new WxMenuButton();
btn1.setType(WxMsgConst.MENU_BUTTON_VIEW); btn1.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn1.setKey("l1"); btn1.setKey("l1");
btn1.setUrl(WeChatConfig.getBaseUrl() + "health-card.html"); btn1.setUrl(WeChatConfig.getBaseURL() + "health-card.html");
btn1.setName("电子健康卡"); btn1.setName("电子健康卡");
WxMenuButton btn2 = new WxMenuButton(); WxMenuButton btn2 = new WxMenuButton();
@ -45,15 +45,15 @@ public class CreateMenu extends HttpServlet {
WxMenuButton btn2_1 = new WxMenuButton(); WxMenuButton btn2_1 = new WxMenuButton();
btn2_1.setType(WxMsgConst.MENU_BUTTON_VIEW); btn2_1.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn2_1.setName("今日挂号"); btn2_1.setName("今日挂号");
btn2_1.setUrl(WeChatConfig.getBaseUrl() + "reg-site.html"); btn2_1.setUrl(WeChatConfig.getBaseURL() + "reg-site.html");
WxMenuButton btn2_2 = new WxMenuButton(); WxMenuButton btn2_2 = new WxMenuButton();
btn2_2.setType(WxMsgConst.MENU_BUTTON_VIEW); btn2_2.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn2_2.setName("预约挂号"); btn2_2.setName("预约挂号");
btn2_2.setUrl(WeChatConfig.getBaseUrl() + "reg-reserve.html"); btn2_2.setUrl(WeChatConfig.getBaseURL() + "reg-reserve.html");
WxMenuButton btn2_3 = new WxMenuButton(); WxMenuButton btn2_3 = new WxMenuButton();
btn2_3.setType(WxMsgConst.MENU_BUTTON_VIEW); btn2_3.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn2_3.setName("核酸自助检测"); btn2_3.setName("核酸自助检测");
btn2_3.setUrl(WeChatConfig.getBaseUrl() + "pay-nuclein.html"); btn2_3.setUrl(WeChatConfig.getBaseURL() + "pay-nuclein.html");
subList2.add(btn2_1); subList2.add(btn2_1);
subList2.add(btn2_2); subList2.add(btn2_2);
// subList2.add(btn2_3); // subList2.add(btn2_3);
@ -68,17 +68,17 @@ public class CreateMenu extends HttpServlet {
WxMenuButton btn3_1 = new WxMenuButton(); WxMenuButton btn3_1 = new WxMenuButton();
btn3_1.setType(WxMsgConst.MENU_BUTTON_VIEW); btn3_1.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn3_1.setName("报告单"); btn3_1.setName("报告单");
btn3_1.setUrl(WeChatConfig.getBaseUrl() + "all-result.html"); btn3_1.setUrl(WeChatConfig.getBaseURL() + "all-result.html");
WxMenuButton btn3_2 = new WxMenuButton(); WxMenuButton btn3_2 = new WxMenuButton();
btn3_2.setType(WxMsgConst.MENU_BUTTON_VIEW); btn3_2.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn3_2.setName("微信支付"); btn3_2.setName("微信支付");
btn3_2.setUrl(WeChatConfig.getBaseUrl() + "pay-info.html"); btn3_2.setUrl(WeChatConfig.getBaseURL() + "pay-info.html");
WxMenuButton btn3_3 = new WxMenuButton(); WxMenuButton btn3_3 = new WxMenuButton();
btn3_3.setType(WxMsgConst.MENU_BUTTON_VIEW); btn3_3.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn3_3.setName("个人信息"); btn3_3.setName("个人信息");
btn3_3.setUrl(WeChatConfig.getBaseUrl() + "my-info.html"); btn3_3.setUrl(WeChatConfig.getBaseURL() + "my-info.html");
subList3.add(btn3_1); subList3.add(btn3_1);
subList3.add(btn3_2); subList3.add(btn3_2);

@ -33,12 +33,12 @@ public class CreateMenu_md extends HttpServlet {
WxMenuButton btn1 = new WxMenuButton(); WxMenuButton btn1 = new WxMenuButton();
btn1.setType(WxMsgConst.MENU_BUTTON_VIEW); btn1.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn1.setKey("l1"); btn1.setKey("l1");
btn1.setUrl(WeChatConfig.getBaseUrl() + "reg-site.html"); btn1.setUrl(WeChatConfig.getBaseURL() + "reg-site.html");
btn1.setName("今日挂号"); btn1.setName("今日挂号");
WxMenuButton btn2 = new WxMenuButton(); WxMenuButton btn2 = new WxMenuButton();
btn2.setType(WxMsgConst.MENU_BUTTON_VIEW); btn2.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn2.setUrl(WeChatConfig.getBaseUrl() + "reg-reserve.html"); btn2.setUrl(WeChatConfig.getBaseURL() + "reg-reserve.html");
btn2.setKey("l2"); btn2.setKey("l2");
btn2.setName("预约挂号"); btn2.setName("预约挂号");
@ -51,11 +51,11 @@ public class CreateMenu_md extends HttpServlet {
WxMenuButton btn2_1 = new WxMenuButton(); WxMenuButton btn2_1 = new WxMenuButton();
btn2_1.setType(WxMsgConst.MENU_BUTTON_VIEW); btn2_1.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn2_1.setName("检查结果"); btn2_1.setName("检查结果");
btn2_1.setUrl(WeChatConfig.getBaseUrl() + "check.jsp"); btn2_1.setUrl(WeChatConfig.getBaseURL() + "check.jsp");
WxMenuButton btn2_2 = new WxMenuButton(); WxMenuButton btn2_2 = new WxMenuButton();
btn2_2.setType(WxMsgConst.MENU_BUTTON_VIEW); btn2_2.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn2_2.setName("化验结果"); btn2_2.setName("化验结果");
btn2_2.setUrl(WeChatConfig.getBaseUrl() + "inspection.jsp"); btn2_2.setUrl(WeChatConfig.getBaseURL() + "inspection.jsp");
// subList2.add(btn2_1); // subList2.add(btn2_1);
// subList2.add(btn2_2); // subList2.add(btn2_2);
// btn2.setSub_button(subList2); // btn2.setSub_button(subList2);
@ -64,15 +64,15 @@ public class CreateMenu_md extends HttpServlet {
WxMenuButton btn3_0 = new WxMenuButton(); WxMenuButton btn3_0 = new WxMenuButton();
btn3_0.setType(WxMsgConst.MENU_BUTTON_VIEW); btn3_0.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn3_0.setName("预约记录"); btn3_0.setName("预约记录");
btn3_0.setUrl(WeChatConfig.getBaseUrl() + "my-reservation.jsp"); btn3_0.setUrl(WeChatConfig.getBaseURL() + "my-reservation.jsp");
WxMenuButton btn3_1 = new WxMenuButton(); WxMenuButton btn3_1 = new WxMenuButton();
btn3_1.setType(WxMsgConst.MENU_BUTTON_VIEW); btn3_1.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn3_1.setName("微信支付"); btn3_1.setName("微信支付");
btn3_1.setUrl(WeChatConfig.getBaseUrl() + "my-pay.jsp"); btn3_1.setUrl(WeChatConfig.getBaseURL() + "my-pay.jsp");
WxMenuButton btn3_2 = new WxMenuButton(); WxMenuButton btn3_2 = new WxMenuButton();
btn3_2.setType(WxMsgConst.MENU_BUTTON_VIEW); btn3_2.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn3_2.setName("身份绑定"); btn3_2.setName("身份绑定");
btn3_2.setUrl(WeChatConfig.getBaseUrl() + "my.jsp"); btn3_2.setUrl(WeChatConfig.getBaseURL() + "my.jsp");
subList3.add(btn2_1); subList3.add(btn2_1);
subList3.add(btn2_2); subList3.add(btn2_2);
subList3.add(btn3_0); subList3.add(btn3_0);

@ -32,7 +32,7 @@ public class CreateMenu_normal extends HttpServlet {
WxMenuButton btn1 = new WxMenuButton(); WxMenuButton btn1 = new WxMenuButton();
btn1.setType(WxMsgConst.MENU_BUTTON_VIEW); btn1.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn1.setKey("l1"); btn1.setKey("l1");
btn1.setUrl(WeChatConfig.getBaseUrl() + "health-card.html"); btn1.setUrl(WeChatConfig.getBaseURL() + "health-card.html");
btn1.setName("电子健康卡"); btn1.setName("电子健康卡");
WxMenuButton btn2 = new WxMenuButton(); WxMenuButton btn2 = new WxMenuButton();
@ -44,11 +44,11 @@ public class CreateMenu_normal extends HttpServlet {
WxMenuButton btn2_1 = new WxMenuButton(); WxMenuButton btn2_1 = new WxMenuButton();
btn2_1.setType(WxMsgConst.MENU_BUTTON_VIEW); btn2_1.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn2_1.setName("今日挂号"); btn2_1.setName("今日挂号");
btn2_1.setUrl(WeChatConfig.getBaseUrl() + "reg-site.html"); btn2_1.setUrl(WeChatConfig.getBaseURL() + "reg-site.html");
WxMenuButton btn2_2 = new WxMenuButton(); WxMenuButton btn2_2 = new WxMenuButton();
btn2_2.setType(WxMsgConst.MENU_BUTTON_VIEW); btn2_2.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn2_2.setName("预约挂号"); btn2_2.setName("预约挂号");
btn2_2.setUrl(WeChatConfig.getBaseUrl() + "reg-reserve.html"); btn2_2.setUrl(WeChatConfig.getBaseURL() + "reg-reserve.html");
subList2.add(btn2_1); subList2.add(btn2_1);
subList2.add(btn2_2); subList2.add(btn2_2);
btn2.setSub_button(subList2); btn2.setSub_button(subList2);
@ -62,17 +62,17 @@ public class CreateMenu_normal extends HttpServlet {
WxMenuButton btn3_1 = new WxMenuButton(); WxMenuButton btn3_1 = new WxMenuButton();
btn3_1.setType(WxMsgConst.MENU_BUTTON_VIEW); btn3_1.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn3_1.setName("报告单"); btn3_1.setName("报告单");
btn3_1.setUrl(WeChatConfig.getBaseUrl() + "all-result.html"); btn3_1.setUrl(WeChatConfig.getBaseURL() + "all-result.html");
WxMenuButton btn3_2 = new WxMenuButton(); WxMenuButton btn3_2 = new WxMenuButton();
btn3_2.setType(WxMsgConst.MENU_BUTTON_VIEW); btn3_2.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn3_2.setName("微信支付"); btn3_2.setName("微信支付");
btn3_2.setUrl(WeChatConfig.getBaseUrl() + "pay-info.html"); btn3_2.setUrl(WeChatConfig.getBaseURL() + "pay-info.html");
WxMenuButton btn3_3 = new WxMenuButton(); WxMenuButton btn3_3 = new WxMenuButton();
btn3_3.setType(WxMsgConst.MENU_BUTTON_VIEW); btn3_3.setType(WxMsgConst.MENU_BUTTON_VIEW);
btn3_3.setName("个人信息"); btn3_3.setName("个人信息");
btn3_3.setUrl(WeChatConfig.getBaseUrl() + "my-info.html"); btn3_3.setUrl(WeChatConfig.getBaseURL() + "my-info.html");
subList3.add(btn3_1); subList3.add(btn3_1);
subList3.add(btn3_2); subList3.add(btn3_2);

@ -0,0 +1,16 @@
wx.app_id=
wx.app_secret=
wx.token=ynxbd
wx.aes_key=
wx.mch_id=
wx.mch_key=
# \u57DF\u540D
wx.domain=http://www.xxx.com
# \u9879\u76EE\u90E8\u7F72\u670D\u52A1\u540D
wx.deploy_server_name=wx
# \u9759\u6001\u8D44\u6E90\u8DEF\u5F84
wx.web_static_path=/web
#
# \u7528\u4E8E\u6388\u6743\u7684\u533B\u5171\u4F53\u516C\u4F17\u53F7\u914D\u7F6E=======================
wx.gmc.is_enable=true
wx.gmc.auth_domain=http://www.xxx.com

@ -1,33 +1,16 @@
#wx.appId=wxde5e86d0c5de92ec wx.app_id=
#wx.appSecret=21a5cbf407105a9e85835f85d4b0901f wx.app_secret=
#wx.token=ynxbd wx.token=ynxbd
#wx.aesKey=tqlPguPF7cx3Owm9xxJ0maJuI51pgsVj4P3mYWFnPKK wx.aes_key=
#wx.mchId=1540825461 wx.mch_id=
#wx.mchKey=jcxrmyyWxPay88372933ABCEZfggggpp wx.mch_key=
#wx.baseURL=http://www.dljcxrmyy.com/wx/ # \u57DF\u540D
#wx.webPath=/web wx.domain=http://www.xxx.com
# \u9879\u76EE\u90E8\u7F72\u670D\u52A1\u540D
wx.appId=wx64cc4b42bbed4090 wx.deploy_server_name=wx
#wx.appSecret=7d5d713378e7885c5186c739ba1bcf0c # \u9759\u6001\u8D44\u6E90\u8DEF\u5F84
#wx.token=ynxbd wx.web_static_path=/web
#wx.aesKey=s3ib5r9aE7VtICXjrix0zi9cZ2bipshqh4gzXkjJoh0 #
#wx.mchId=1528789611 # \u7528\u4E8E\u6388\u6743\u7684\u533B\u5171\u4F53\u516C\u4F17\u53F7\u914D\u7F6E=======================
#wx.mchKey=mzsrmyyWxPay8989328291232KAG8392 wx.gmc.is_enable=true
#wx.baseURL=http://wx.mzsrmyy.net/wx/ wx.gmc.auth_domain=http://www.xxx.com
#wx.webPath=/web
#wx.password=ynxbd@6910
## \u5F00\u542F\u5904\u65B9\u9884\u7ED3\u7B97\uFF08\u7B2C2\u5F00\u5173\uFF09\uFF08\u6CE8\u610F\u8BE5\u914D\u7F6E\u9700\u8054\u7CFBHIS\u5F00\u53D1\u8005\u786E\u8BA4\u652F\u6301\u624D\u80FD\u5F00\u542F\uFF0C\u5426\u5219\u5B58\u5728\u98CE\u9669\uFF01\uFF09
#wx.is_recipe_prepay=true
# \u8292\u5E02\u5987\u5E7C\u914D\u7F6E
#wx.appId=wx7d33a52af019f134
#wx.appSecret=56ac2bc26672f05f06d6c557d978c0b1
#wx.token=ynxbd
#wx.aesKey=SvUOQUIaawWoB6ptViNqcYkrTs1bmq5cbhiBglhtkct
#wx.mchId=1605084861
#wx.mchKey=MsfyBJ8871934EKFJA03jdslkfajAaBC
#wx.baseURL=http://127.0.0.1/wx/
#wx.webPath=/web
#wx.password=ynxbd@6910
## \u7ED5\u8FC7\u7528\u6237\u7F13\u5B58\uFF1A\u82F1\u6587\u9017\u53F7\u9694\u5F00
#wx.dev_open_ids=1,2,3
Loading…
Cancel
Save