You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							177 lines
						
					
					
						
							7.9 KiB
						
					
					
				
			
		
		
	
	
							177 lines
						
					
					
						
							7.9 KiB
						
					
					
				| package com.ynxbd.wx.wxfactory.message;
 | |
| 
 | |
| import com.ynxbd.common.result.JsonResult;
 | |
| import com.ynxbd.common.result.JsonResultEnum;
 | |
| import com.ynxbd.wx.wxfactory.utils.WxRequestHelper;
 | |
| import lombok.NoArgsConstructor;
 | |
| import lombok.extern.slf4j.Slf4j;
 | |
| import org.apache.commons.codec.digest.DigestUtils;
 | |
| 
 | |
| import java.util.HashMap;
 | |
| import java.util.Map;
 | |
| import java.util.UUID;
 | |
| 
 | |
| @Slf4j
 | |
| @NoArgsConstructor
 | |
| public class MdClient {
 | |
|     @FunctionalInterface
 | |
|     public interface MsgInterface {
 | |
|         Map<String, Object> setParams(MessageType messageType);
 | |
|     }
 | |
| 
 | |
| 
 | |
| //    public static void main(String[] args) {
 | |
| //        String accessToken = "59_wcKr1kaYK76uqkyaIlq3fGslfRbGsGKEg9Aa4NE2E2uen8Sv4IdSWVTw7x2JEzVoLP7UWBy6H9H-5fXxAldTXKl-wKW0XEROPw73jcmyf9oyyES3GyXhzDUTjGT2M-EShXRBx02g9Oeq02TcTJCaAIAJZS";
 | |
| //        String appId = "wxd503671f502bd89d";
 | |
| //
 | |
| //
 | |
| //        JsonResult query = new MdClient().query(accessToken, messageType -> messageType.auth("" , ""));
 | |
| //        System.out.println(query);
 | |
| //    }
 | |
| 
 | |
|     /**
 | |
|      * @param accessToken accessToken
 | |
|      * @param appId       appId
 | |
|      * @param status      status
 | |
|      * @param orderId     订单id
 | |
|      */
 | |
|     public JsonResult push(String accessToken, String appId, Integer status, String orderId, MsgInterface msgInterface) {
 | |
|         if (accessToken == null || appId == null || status == null || orderId == null || msgInterface == null) {
 | |
|             return JsonResult.createErrorResult("参数缺失", JsonResultEnum.SYS_MEDICAL_ASSISTANT);
 | |
|         }
 | |
|         JsonResult result = WxRequestHelper.postBody("https://api.weixin.qq.com/cityservice/sendchannelmsg?access_token=" + accessToken, params -> {
 | |
|             params.put("app_id", appId);
 | |
|             params.put("status", status);
 | |
|             params.put("order_id", orderId);
 | |
|             params.put("msg_id", UUID.randomUUID().toString().replace("-", ""));
 | |
|             params.put("business_id", 1);
 | |
|             params.put("business_info", msgInterface.setParams(new MessageType()));
 | |
|         });
 | |
|         if (!result.success()) {
 | |
|             log.info("[就医助手]调用失败 resp={}", result);
 | |
|         }
 | |
|         return result;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param accessToken accessToken
 | |
|      */
 | |
|     public JsonResult query(String accessToken,  MsgInterface msgInterface) {
 | |
|         if (accessToken == null ) {
 | |
|             return JsonResult.createErrorResult("参数缺失", JsonResultEnum.SYS_MEDICAL_ASSISTANT);
 | |
|         }
 | |
|         JsonResult result = WxRequestHelper.postBody("https://api.weixin.qq.com/cityservice/getmsgrelation?access_token=" + accessToken, params -> {
 | |
|             params.put("business_id", 1);
 | |
|             params.put("openid", "oeso-t0BquRJx0-WdxR1KPo7prgo");
 | |
|             params.put("business_info", msgInterface.setParams(new MessageType()));
 | |
|         });
 | |
|         if (!result.success()) {
 | |
|             log.info("[就医助手]调用失败 resp={}", result);
 | |
|         }
 | |
|         return result;
 | |
|     }
 | |
| 
 | |
|     @NoArgsConstructor
 | |
|     public static class MessageType {
 | |
|         /**
 | |
|          * 9001-就医流程提醒授权通知
 | |
|          *
 | |
|          * @param patCardNo 用户证件号md5
 | |
|          * @param patName   用户姓名utf8
 | |
|          */
 | |
|         public Map<String, Object> auth(String patCardNo, String patName) {
 | |
|             if (patCardNo == null || patName == null) {
 | |
|                 return null;
 | |
|             }
 | |
|             Map<String, Object> businessInfo = new HashMap<>();
 | |
|             businessInfo.put("pat_card_type", 11); // 用户证件类型 {11:二代身份证}
 | |
|             System.out.println(DigestUtils.md5Hex(patCardNo));
 | |
|             businessInfo.put("pat_card_no", DigestUtils.md5Hex(patCardNo)); // 用户证件号md5
 | |
|             patName = patName.trim();
 | |
|             int length = patName.length();
 | |
|             if (length == 2) {
 | |
|                 patName = patName.substring(0, 1) + "*";
 | |
|             } else if (length > 2) {
 | |
|                 StringBuilder x = new StringBuilder();
 | |
|                 for (int i = 0; i < length - 2; i++) {
 | |
|                     x.append("*");
 | |
|                 }
 | |
|                 patName = patName.substring(0, 1) + x + patName.substring(length - 1, length);
 | |
|             }
 | |
|             businessInfo.put("pat_name", patName); // 李*龙 ,张 *,姓名需打码
 | |
|             return businessInfo;
 | |
|         }
 | |
| 
 | |
|         /**
 | |
|          * 预约挂号
 | |
|          *
 | |
|          * @param hospitalName    医院名称,含院区(如果有)
 | |
|          * @param url             链接
 | |
|          * @param status          1001-预约挂号成功通知,1004-现场挂号成功通知,1002-取消预约挂号通知
 | |
|          * @param patCardNo       用户证件号md5
 | |
|          * @param patHospitalId   用户就诊卡号
 | |
|          * @param patName         患者姓名李*龙 ,张 *,姓名需打码
 | |
|          * @param deptName        科室名称
 | |
|          * @param docName         医生姓名utf8
 | |
|          * @param appointmentTime 挂号时间 | 取消挂号时间
 | |
|          */
 | |
|         public Map<String, Object> reg(String hospitalName, String url, Integer status, String patCardNo, String patName, String patHospitalId, String deptName, String docName, String appointmentTime, String memo) {
 | |
|             Map<String, Object> businessInfo = auth(patCardNo, patName);
 | |
| 
 | |
|             businessInfo.put("pat_hospital_id", patHospitalId); // 用户就诊卡号
 | |
|             businessInfo.put("hospital_name", hospitalName); // 医院名称,含院区(如果有)
 | |
|             businessInfo.put("department_name", deptName); // 科室名称
 | |
|             businessInfo.put("doc_name", docName);
 | |
|             businessInfo.put("appointment_time", appointmentTime); // 预约时间
 | |
| 
 | |
|             // 取消预约------------------------------------------
 | |
|             businessInfo.put("memo", memo); // 备注(如:退款说明)
 | |
| 
 | |
|             Map<String, Object> redirectPage = new HashMap<>();
 | |
|             redirectPage.put("page_type", "web");
 | |
|             redirectPage.put("url", url);
 | |
|             businessInfo.put("redirect_page", redirectPage);
 | |
|             return businessInfo;
 | |
|         }
 | |
| 
 | |
| 
 | |
|         /**
 | |
|          * 缴费通知
 | |
|          *
 | |
|          * @param url            跳转链接
 | |
|          * @param status         4002-支付成功通知,status = "4003-支付失败通知
 | |
|          * @param patCardNo      患者证件号码
 | |
|          * @param patName        患者姓名
 | |
|          * @param deptName       科室名称
 | |
|          * @param payOrderNo     支付单号
 | |
|          * @param payOrderAmount 支付金额
 | |
|          * @param memo           备注
 | |
|          * @param payTime        支付时间
 | |
|          * @param payFailReason  失败原因
 | |
|          */
 | |
|         public Map<String, Object> recipe(String url, Integer status, String patCardNo, String patName, String deptName, String payOrderNo, String payOrderAmount, String memo, String payTime, String payFailReason) {
 | |
|             Map<String, Object> businessInfo = auth(patCardNo, patName);
 | |
|             //
 | |
|             businessInfo.put("pay_order_no", payOrderNo); // 支付单号
 | |
|             businessInfo.put("pay_order_amount", payOrderAmount); // 支付金额
 | |
|             businessInfo.put("department_name", deptName); // 科室名称
 | |
|             // -------------------------------------------------
 | |
|             if (4001 == status) { // 待缴费订单提醒
 | |
|                 businessInfo.put("memo", memo); // 缴费说明
 | |
|             }
 | |
|             if (4002 == status) { // 支付成功
 | |
|                 businessInfo.put("pay_time", payTime); // 支付时间
 | |
|             }
 | |
|             if (4003 == status) { // 支付失败
 | |
|                 businessInfo.put("pay_time", payTime); // 支付时间
 | |
|                 businessInfo.put("pay_fail_reason", payFailReason); // 失败原因
 | |
|             }
 | |
|             Map<String, Object> redirectPage = new HashMap<>();
 | |
|             redirectPage.put("page_type", "web");
 | |
|             redirectPage.put("url", url);
 | |
|             businessInfo.put("redirect_page", redirectPage);
 | |
|             return businessInfo;
 | |
|         }
 | |
|     }
 | |
| 
 | |
| }
 | |
| 
 |