1、调整:武定中医院小程序需要使用公众号的网页链接,必须为https为了方便调整授权可携带协议类型,用于认证时控制重定向的认证协议类型,并设置配置文件中的协议为最高优先级,可强制为https。

2、配置文件调整
debug
wangsq 4 days ago
parent b5ef61e167
commit 310c580dbb
  1. 76
      src/main/java/com/ynxbd/common/action/HealthCodeAction.java
  2. 4
      src/main/java/com/ynxbd/common/action/pay/WxAuthAction.java
  3. 4
      src/main/java/com/ynxbd/common/action/pay/WxPayAction.java
  4. 37
      src/main/java/com/ynxbd/common/service/HCodeService.java
  5. 28
      src/main/java/com/ynxbd/wx/config/WeChatConfig.java
  6. 32
      src/main/java/com/ynxbd/wx/wxfactory/WxAuthHelper.java
  7. 4
      src/main/resources/ehcache.xml
  8. 2
      src/main/resources/logback.xml

@ -302,16 +302,16 @@ public class HealthCodeAction extends BaseAction {
/** /**
* [升级绑定]-->已在HIS绑定-->注册健康卡 * [升级绑定]-->已在HIS绑定-->注册健康卡
* *
* @param weChatCode * @param weChatCode weChatCode
* @param idCardNo * @param idCardNo idCardNo
* @param cardType * @param cardType cardType
* @param openid * @param openid openid
* @param tel * @param tel tel
* @param name * @param name name
* @param nation * @param nation nation
* @param patientId * @param patientId patientId
* @param address * @param address address
* @return * @return Result
*/ */
@Action("upBind") @Action("upBind")
public Result upBind(String weChatCode, String idCardNo, String cardType, String openid, String tel, String name, String nation, String patientId, String address) { public Result upBind(String weChatCode, String idCardNo, String cardType, String openid, String tel, String name, String nation, String patientId, String address) {
@ -419,7 +419,7 @@ public class HealthCodeAction extends BaseAction {
try { try {
jsonArray = new HCodeService().batchUpdate(lstPatient); jsonArray = new HCodeService().batchUpdate(lstPatient);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error(e.getMessage());
} }
if (jsonArray == null) return; if (jsonArray == null) return;
@ -434,58 +434,4 @@ public class HealthCodeAction extends BaseAction {
}, 2 * 1000, 30 * 1000); }, 2 * 1000, 30 * 1000);
} }
public static void main(String[] args) {
HCodeService hCodeService = new HCodeService();
String qrCodeText = hCodeService.getQRCodeText("F43F5B90877116A61D3B960EDAECBCDDDDE7F452605C23DD425CC79BF4644F61", "530127199711211059");
hCodeService.reportHISData(qrCodeText, "口腔科", "0101011", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
hCodeService.reportHISData(qrCodeText, "口腔科", "0101012", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
hCodeService.reportHISData(qrCodeText, null, "0101013", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
hCodeService.reportHISData(qrCodeText, null, "0101014", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
// 门诊缴费
hCodeService.reportHISData(qrCodeText, "口腔科", "0101051", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
"0100");
// 门诊缴费记录
hCodeService.reportHISData(qrCodeText, null, "0101052", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
hCodeService.reportHISData(qrCodeText, null, "0101081", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
hCodeService.reportHISData(qrCodeText, null, "0101082", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
hCodeService.reportHISData(qrCodeText, null, "0101083", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
}
//
// public static void main(String[] args){
// String resultCode = "-10044";
// HealthCardRespCodeEnum healthCardRespCodeEnum = HCodeService.resultCodeHandle(resultCode);
// logger.info("resultCode=[" + resultCode + "],健康卡绑定失败原因,statusMsg=" + healthCardRespCodeEnum.getMessage() );
// System.out.println(healthCardRespCodeEnum);
// if (!healthCardRespCodeEnum.isContinue()) { // 不继续执行
// System.out.println("停止");
// Integer age = IDNumberHelper.getAge("532331202010054010");
// if (age != null && age > 10) {
// System.out.println(age);
// }
// }else{
// System.out.println("继续");
// }
// }
} }

@ -21,12 +21,12 @@ public class WxAuthAction extends BaseAction {
@Action("u_auth") @Action("u_auth")
public Result u_auth() { public Result u_auth() {
String auth = WxAuthHelper.auth(request, response, true); String auth = WxAuthHelper.auth(request, response, true);
return Result.redirect(WeChatConfig.getBaseDomain() + auth); return Result.redirect(auth);
} }
@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, true);
return Result.redirect(WeChatConfig.getBaseDomain() + auth); return Result.redirect(auth);
} }
} }

@ -4,7 +4,8 @@ import com.ynxbd.common.action.base.BaseAction;
import com.ynxbd.common.bean.enums.MerchantEnum; import com.ynxbd.common.bean.enums.MerchantEnum;
import com.ynxbd.common.result.Result; import com.ynxbd.common.result.Result;
import com.ynxbd.common.result.ServiceException; import com.ynxbd.common.result.ServiceException;
import com.ynxbd.common.service.*; import com.ynxbd.common.service.OutCollectService;
import com.ynxbd.common.service.PayService;
import com.ynxbd.wx.wxfactory.WxPayHelper; import com.ynxbd.wx.wxfactory.WxPayHelper;
import com.ynxbd.wx.wxfactory.bean.WxPayNotify; import com.ynxbd.wx.wxfactory.bean.WxPayNotify;
import com.ynxbd.wx.wxfactory.utils.WxRespHelper; import com.ynxbd.wx.wxfactory.utils.WxRespHelper;
@ -13,7 +14,6 @@ import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.Namespace;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
@Slf4j @Slf4j

@ -817,4 +817,41 @@ public class HCodeService {
return healthCardRespCodeEnum; return healthCardRespCodeEnum;
} }
public static void main(String[] args) {
new HCodeService().dataUpload();
}
public void dataUpload() {
String qrCodeText = getQRCodeText("F43F5B90877116A61D3B960EDAECBCDDDDE7F452605C23DD425CC79BF4644F61", "530127199711211059");
reportHISData(qrCodeText, "口腔科", "0101011", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
reportHISData(qrCodeText, "口腔科", "0101012", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
reportHISData(qrCodeText, null, "0101013", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
reportHISData(qrCodeText, null, "0101014", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
// 门诊缴费
reportHISData(qrCodeText, "口腔科", "0101051", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
"0100");
// 门诊缴费记录
reportHISData(qrCodeText, null, "0101052", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
reportHISData(qrCodeText, null, "0101081", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
reportHISData(qrCodeText, null, "0101082", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
reportHISData(qrCodeText, null, "0101083", HealthCardEnum.CARD_TYPE_HEALTH_CARD.STATUS,
null);
}
} }

@ -26,6 +26,8 @@ public class WeChatConfig {
private static String CACHE_WEB_URL = null; private static String CACHE_WEB_URL = null;
// 开启预结算(第2开关) // 开启预结算(第2开关)
public static boolean IS_RECIPE_PREPAY; public static boolean IS_RECIPE_PREPAY;
// 判断链接是否有https
public static boolean HAS_HTTPS_BY_BASE_URL;
static { static {
ProperHelper config = new ProperHelper().read("wx.properties"); ProperHelper config = new ProperHelper().read("wx.properties");
@ -50,6 +52,8 @@ public class WeChatConfig {
if (BASE_URL == null) { if (BASE_URL == null) {
log.error("【微信】读取配置文件wx.properties失败"); log.error("【微信】读取配置文件wx.properties失败");
} else {
HAS_HTTPS_BY_BASE_URL = BASE_URL.contains("https:");
} }
} }
@ -59,7 +63,7 @@ public class WeChatConfig {
BASE_URL = ""; BASE_URL = "";
} }
if (BASE_URL.length() == 0) return BASE_URL; if (BASE_URL.isEmpty()) return BASE_URL;
String path = BASE_URL; String path = BASE_URL;
String suffix = path.substring(path.length() - 1); String suffix = path.substring(path.length() - 1);
@ -69,6 +73,13 @@ public class WeChatConfig {
return path; return path;
} }
public static String getBaseUrlByState(boolean isHttps) {
if (isHttps) {
return getHttpsBaseUrl();
}
return getBaseUrl();
}
public static String getHttpsBaseUrl() { public static String getHttpsBaseUrl() {
String url = getBaseUrl(); String url = getBaseUrl();
if (url != null && url.contains("http") && !url.contains("https")) { if (url != null && url.contains("http") && !url.contains("https")) {
@ -80,11 +91,18 @@ public class WeChatConfig {
/** /**
* 获取配置中原本的域名 * 获取配置中原本的域名
*/ */
public static String getBaseDomain() { public static String getBaseDomain(boolean isHttps) {
if (BASE_URL.length() < 4) { if (BASE_URL.length() < 4) {
return BASE_URL; return BASE_URL;
} }
return BASE_URL.substring(0, BASE_URL.length() - 4); String url = BASE_URL.substring(0, BASE_URL.length() - 4);
if (isHttps) {
int index = url.indexOf("http://");
if (index == 0) {
url = "https://" + url.substring(7);
}
}
return url;
} }
// 域名 // 域名
@ -97,14 +115,14 @@ public class WeChatConfig {
if (isHttps) { if (isHttps) {
int index = url.indexOf("http://"); int index = url.indexOf("http://");
if (index == 0) { if (index == 0) {
url = "https://" + url.substring(index + 7); url = "https://" + url.substring(7);
} }
} }
return url.substring(0, url.length() - 4); return url.substring(0, url.length() - 4);
} }
public static String getWebPath(boolean isPrefix, boolean isSuffix) { public static String getWebPath(boolean isPrefix, boolean isSuffix) {
if (WEB_PATH == null || WEB_PATH.length() == 0) return "/"; if (WEB_PATH == null || WEB_PATH.isEmpty()) return "/";
String path = WEB_PATH; String path = WEB_PATH;
String prefix = path.substring(0, 1); String prefix = path.substring(0, 1);

@ -11,6 +11,7 @@ import com.ynxbd.wx.config.WeChatConfig;
import com.ynxbd.wx.wxfactory.bean.SnsOath2AccessToken; import com.ynxbd.wx.wxfactory.bean.SnsOath2AccessToken;
import com.ynxbd.wx.wxfactory.bean.SnsUserInfo; import com.ynxbd.wx.wxfactory.bean.SnsUserInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.ehcache.Cache; import org.ehcache.Cache;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -95,17 +96,26 @@ public class WxAuthHelper {
if (hash == null) hash = ""; if (hash == null) hash = "";
if (state == null) state = ""; if (state == null) state = "";
String protocol = ""; //
int index = state.indexOf("@protocol=");
if (index == -1) index = state.indexOf("%40protocol="); // 防止数据转义失败
if (index != -1) {
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 + hash; 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 state + hash; return domain + state + hash;
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("[微信][获取重定向链接异常]{}", e.getMessage());
} }
return null; return null;
} }
@ -154,6 +164,10 @@ public class WxAuthHelper {
String state = request.getParameter("state"); String state = request.getParameter("state");
String hash = request.getParameter("hash"); String hash = request.getParameter("hash");
String isUserInfo = request.getParameter("isUserInfo"); String isUserInfo = request.getParameter("isUserInfo");
String protocolState = request.getParameter("protocolState"); // 1:https;0:http
if (ObjectUtils.isEmpty(protocolState)) {
protocolState = "0";
}
if (hash == null) { if (hash == null) {
hash = ""; hash = "";
@ -168,13 +182,19 @@ public class WxAuthHelper {
String api = ("true".equals(isUserInfo) ? "u_auth" : "b_auth"); String api = ("true".equals(isUserInfo) ? "u_auth" : "b_auth");
String scope = ("true".equals(isUserInfo) ? "snsapi_userinfo" : "snsapi_base"); String scope = ("true".equals(isUserInfo) ? "snsapi_userinfo" : "snsapi_base");
state = OAUTH_URL + WeChatConfig.getBaseUrl() + "wx_auth/" + api + // 配置中baseURL有"https"时优先级最高
"?hash=" + hash + "&response_type=code" + state = OAUTH_URL + WeChatConfig.getBaseUrlByState((WeChatConfig.HAS_HTTPS_BY_BASE_URL || "1".equals(protocolState))) +
"wx_auth/" + api +
"?hash=" + hash +
"&response_type=code" +
"&scope=" + scope + "&forcePopup=true" + "&scope=" + scope + "&forcePopup=true" +
"&state=" + decode + "#wechat_redirect"; "&state=" + decode +
"%40protocol=" + protocolState +
"#wechat_redirect";
state = Base64Helper.encode(state); state = Base64Helper.encode(state);
} }
return state; return state;
} }
} }

@ -3,8 +3,8 @@
xmlns='http://www.ehcache.org/v3' xmlns='http://www.ehcache.org/v3'
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd"> xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd">
<!-- 硬盘缓存路径--> <!-- 硬盘缓存路径 -->
<persistence directory="${catalina.home}/app-cache/wx-cache-data"/> <persistence directory="${catalina.home}/logs/app-cache/wx-cache-data"/>
<cache-template name="cache-template"> <cache-template name="cache-template">
<key-type>java.lang.String</key-type> <key-type>java.lang.String</key-type>

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
<!-- 日志存放路径 home --> <!-- 日志存放路径 home -->
<property name="log.path" value="${catalina.home}/app-logs"/> <property name="log.path" value="${catalina.home}/logs/app-logs"/>
<!--日志最大保存天数 100年--> <!--日志最大保存天数 100年-->
<property name="log.days" value="36500"/> <property name="log.days" value="36500"/>
<!-- 日志输出格式 --> <!-- 日志输出格式 -->

Loading…
Cancel
Save