|  | @ -1,8 +1,11 @@
 | 
	
		
			
				|  |  | package com.yihu.wlyy.web.wx;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.charge.WlyyCharge;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.organization.HospitalMapping;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.charge.ChargeDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.organization.HospitalMappingDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.PatientDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.SignFamilyDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.third.httplog.LogService;
 | 
	
	
		
			
				|  | @ -19,6 +22,7 @@ import com.ylzinfo.onepay.sdk.utils.StringUtil;
 | 
	
		
			
				|  |  | import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiParam;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.BooleanUtils;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.json.JSONObject;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
	
		
			
				|  | @ -66,6 +70,10 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  |     LogService logService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private Configure config;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private HospitalMappingDao mappingDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     ObjectMapper objectMapper;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @RequestMapping(value = "createSicard", method = RequestMethod.POST)
 | 
	
	
		
			
				|  | @ -76,7 +84,8 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  |             String sicardUrl = pay.createSicard("0cc6e4562de2437ab2dbbf51a9fc3b49", "oULM4xAj9sOsHJ95ttKYd_Fjh6Hc");//getUID(), getOpenid());
 | 
	
		
			
				|  |  |             return write(200, "生成电子社保卡成功!", "data", sicardUrl);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return error(-1, e.getMessage());
 | 
	
		
			
				|  |  |             error(e);
 | 
	
		
			
				|  |  |             return write(-1, "生成电子社保卡失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -85,14 +94,11 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  |     @ResponseBody
 | 
	
		
			
				|  |  |     public String bindCard() throws Exception {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  | //            String patient = getUID();
 | 
	
		
			
				|  |  | //            String openid = getOpenid();
 | 
	
		
			
				|  |  | //            逸祥
 | 
	
		
			
				|  |  | //            String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
 | 
	
		
			
				|  |  | //            String openid = "oULM4xAj9sOsHJ95ttKYd_Fjh6Hc";
 | 
	
		
			
				|  |  |             String patient = getUID();
 | 
	
		
			
				|  |  |             String openid = getOpenid();
 | 
	
		
			
				|  |  | //            在鑫
 | 
	
		
			
				|  |  |             String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
 | 
	
		
			
				|  |  |             String openid = "o7NFZw7FlRW-Hlp0VjM71FR_1otw";
 | 
	
		
			
				|  |  | //            String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
 | 
	
		
			
				|  |  | //            String openid = "o7NFZw7FlRW-Hlp0VjM71FR_1otw";
 | 
	
		
			
				|  |  |             BindCard bindCard = pay.bindCard(patient, openid);//getUID(), getOpenid());      oULM4xAj9sOsHJ95ttKYd_Fjh6Hc
 | 
	
		
			
				|  |  |             String sicardUrl = pay.createSicard(patient, openid);//getUID(), getOpenid());
 | 
	
		
			
				|  |  |             if (bindCard != null) {
 | 
	
	
		
			
				|  | @ -108,7 +114,8 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  |                 return write(200, "生成电子社保卡成功!", "data", json);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return error(-1, e.getMessage());
 | 
	
		
			
				|  |  |             error(e);
 | 
	
		
			
				|  |  |             return write(-1, "查询电子社保卡失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -122,25 +129,25 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  |             @RequestParam String chargeType,
 | 
	
		
			
				|  |  |             @ApiParam(name = "chargeRelation", value = "支付关联代码签约code", defaultValue = "044701ea-5b23-11e6-8344-fa163e8aee56")
 | 
	
		
			
				|  |  |             @RequestParam String chargeRelation,
 | 
	
		
			
				|  |  |             @ApiParam(name = "totalAmount", value = "交易总金额(分)", defaultValue = "12000")
 | 
	
		
			
				|  |  |             @ApiParam(name = "totalAmount", value = "交易总金额(分)", defaultValue = "9000")
 | 
	
		
			
				|  |  |             @RequestParam String totalAmount) throws Exception {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             //            获取居民个人信息
 | 
	
		
			
				|  |  | //            String patient = getUID();
 | 
	
		
			
				|  |  | //            String openId = getOpenid();
 | 
	
		
			
				|  |  | //            String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
 | 
	
		
			
				|  |  | //            String openId = "oULM4xAj9sOsHJ95ttKYd_Fjh6Hc";
 | 
	
		
			
				|  |  |             totalAmount = "9000";
 | 
	
		
			
				|  |  |             String patient = getUID();
 | 
	
		
			
				|  |  |             String openId = getOpenid();
 | 
	
		
			
				|  |  | //            在鑫
 | 
	
		
			
				|  |  |             String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
 | 
	
		
			
				|  |  |             String openId = "o7NFZw7FlRW-Hlp0VjM71FR_1otw";
 | 
	
		
			
				|  |  | //            String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
 | 
	
		
			
				|  |  | //            String openId = "o7NFZw7FlRW-Hlp0VjM71FR_1otw";
 | 
	
		
			
				|  |  |             if (StringUtils.isNotEmpty(openId)) {
 | 
	
		
			
				|  |  |                 String settleNo = pay.charge(orgCode, chargeType, chargeRelation, totalAmount, patient, openId,getAccessToken());  //ohNH9sh4uwuJCxIwcLJtGTX-BaSk    getUID(),getOpenid()
 | 
	
		
			
				|  |  |                 String settleNo = pay.charge(orgCode, chargeType, chargeRelation, totalAmount, patient, openId, getAccessToken());  //ohNH9sh4uwuJCxIwcLJtGTX-BaSk    getUID(),getOpenid()
 | 
	
		
			
				|  |  |                 return write(200, "家庭医生签约支付成功!", "data", settleNo);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 return write(-1, "openId为空!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return error(-1, e.getMessage());
 | 
	
		
			
				|  |  |             error(e);
 | 
	
		
			
				|  |  |             return write(-1, "家庭医生签约支付失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -151,10 +158,12 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  |     public String chargeQuery(@ApiParam(name = "code", value = "接入应用业务流水号", defaultValue = "")
 | 
	
		
			
				|  |  |                               @RequestParam String code) throws Exception {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             Charge charge = pay.chargeQuery(code,getAccessToken());
 | 
	
		
			
				|  |  |             String result = pay.chargeQuery(code, getAccessToken());
 | 
	
		
			
				|  |  |             Charge charge = objectMapper.readValue(result, Charge.class);
 | 
	
		
			
				|  |  |             return write(200, "家庭医生签约支付查询成功!", "data", charge);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return error(-1, e.getMessage());
 | 
	
		
			
				|  |  |             error(e);
 | 
	
		
			
				|  |  |             return write(-1, "家庭医生签约支付查询失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -167,10 +176,11 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  |                              @ApiParam(name = "chargeRelation", value = "支付关联代码", defaultValue = "044701ea5b2311e68344fa163e8aee56")
 | 
	
		
			
				|  |  |                              @RequestParam String chargeRelation) throws Exception {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             List<WlyyCharge> charge = pay.chargeList(chargeType, chargeRelation,getAccessToken());
 | 
	
		
			
				|  |  |             List<WlyyCharge> charge = pay.chargeList(chargeType, chargeRelation, getAccessToken());
 | 
	
		
			
				|  |  |             return write(200, "获取某次签约的支付记录成功!", "data", charge);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return error(-1, e.getMessage());
 | 
	
		
			
				|  |  |             error(e);
 | 
	
		
			
				|  |  |             return write(-1, "获取某次签约的支付记录失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -185,10 +195,11 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  |                                       @ApiParam(name = "size", value = "每页几行", defaultValue = "10")
 | 
	
		
			
				|  |  |                                       @RequestParam Integer size) throws Exception {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             List<WlyyCharge> charge = pay.chargeListByPatient(patient,getAccessToken(), page, size);
 | 
	
		
			
				|  |  |             List<WlyyCharge> charge = pay.chargeListByPatient(patient, getAccessToken(), page, size);
 | 
	
		
			
				|  |  |             return write(200, "获取患者的支付记录成功!", "data", charge);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return error(-1, e.getMessage());
 | 
	
		
			
				|  |  |             error(e);
 | 
	
		
			
				|  |  |             return write(-1, "获取患者的支付记录失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -243,56 +254,87 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 页面回调更新数据
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param request
 | 
	
		
			
				|  |  |      * @param response
 | 
	
		
			
				|  |  |      * @throws IOException
 | 
	
		
			
				|  |  |      * @throws PayException
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/returnUrl", method = RequestMethod.GET)
 | 
	
		
			
				|  |  |     @ApiOperation("商户页面跳转")
 | 
	
		
			
				|  |  |     public String testReturnUrl(@RequestParam String jsonData) throws IOException, PayException {
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/returnUrl")
 | 
	
		
			
				|  |  |     public void returnUrl(HttpServletRequest request, HttpServletResponse response) throws IOException, PayException {
 | 
	
		
			
				|  |  |         Boolean isSuccess = false;
 | 
	
		
			
				|  |  |         String error = "";
 | 
	
		
			
				|  |  |         String responses = "";
 | 
	
		
			
				|  |  |         response.setContentType("text/html;charset=utf-8");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             JSONObject json = new JSONObject(jsonData);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             JSONObject requestParam = json.getJSONObject("param");//业务出参
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String chargeNo = requestParam.getString("chargeNo"); //支付平台流水号
 | 
	
		
			
				|  |  |             String chargeTime = requestParam.getString("chargeTime");//支付平台交易成功时间
 | 
	
		
			
				|  |  |             String outChargeNo = requestParam.getString("outChargeNo");//接入应用业务流水号
 | 
	
		
			
				|  |  |             String outChargeTime = requestParam.getString("outChargeTime");//接入应用时间
 | 
	
		
			
				|  |  |             String channel = requestParam.getString("channel");//支付方式
 | 
	
		
			
				|  |  |             String billNo = requestParam.getString("billNo");//待结算费用单据号
 | 
	
		
			
				|  |  |             String cardNo = requestParam.getString("cardNo");//医保卡号
 | 
	
		
			
				|  |  |             String totalAmount = requestParam.getString("totalAmount");//交易总金额
 | 
	
		
			
				|  |  |             String insuranceAmount = requestParam.getString("insuranceAmount");//医保支付金额
 | 
	
		
			
				|  |  |             String selfPayAmount = requestParam.getString("selfPayAmount");//自付金额
 | 
	
		
			
				|  |  |             String userId = requestParam.getString("userId");//用户openID
 | 
	
		
			
				|  |  |             String userName = requestParam.getString("userName");//用户名字
 | 
	
		
			
				|  |  |             String idType = requestParam.getString("idType");//证件类型
 | 
	
		
			
				|  |  |             String idNo = requestParam.getString("idNo");//证件号码
 | 
	
		
			
				|  |  |             String tradeStatus = requestParam.getString("tradeStatus");//交易状态
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             JSONObject responseContents = json.getJSONObject("responseContent");//医保结构体
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String miRegisterNo = responseContents.getString("miRegisterNo");//医保签约号
 | 
	
		
			
				|  |  |             String miCollectDate = responseContents.getString("miCollectDate");//扣费日期
 | 
	
		
			
				|  |  |             String miCollectTime = responseContents.getString("miCollectTime");//扣费时间
 | 
	
		
			
				|  |  |             String miSettleNo = responseContents.getString("miSettleNo");//扣费单据号
 | 
	
		
			
				|  |  |             String miCollectStatus = responseContents.getString("miCollectStatus");//扣费状态
 | 
	
		
			
				|  |  |             String miRegisterStatus = responseContents.getString("miRegisterStatus");//登记状态
 | 
	
		
			
				|  |  |             String cadresPay = responseContents.getString("cadresPay");//政府补贴支付
 | 
	
		
			
				|  |  |             String miTotalFee = responseContents.getString("miTotalFee");//扣费总额
 | 
	
		
			
				|  |  |             String healthCarePay = responseContents.getString("healthCarePay");//医保统筹支付
 | 
	
		
			
				|  |  | //                responseContents.getString("healthPay");
 | 
	
		
			
				|  |  |             String heathPay = responseContents.getString("heathPay");//健康账户支付
 | 
	
		
			
				|  |  |             String accountPay = responseContents.getString("accountPay");//医保账户支付
 | 
	
		
			
				|  |  |             String selfPay = responseContents.getString("selfPay");//个人现金支付
 | 
	
		
			
				|  |  |             //		如:查询显示订单信息
 | 
	
		
			
				|  |  |             isSuccess = true;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String appId = request.getParameter("appId");
 | 
	
		
			
				|  |  |             String billNo = request.getParameter("billNo");//待结算费用单据号
 | 
	
		
			
				|  |  |             String cardNo = request.getParameter("cardNo");//医保卡号
 | 
	
		
			
				|  |  |             String channel = request.getParameter("channel");//支付方式
 | 
	
		
			
				|  |  |             String chargeNo = request.getParameter("chargeNo");//支付平台流水号
 | 
	
		
			
				|  |  |             String chargeTime = request.getParameter("chargeTime");//支付平台交易成功时间
 | 
	
		
			
				|  |  |             String idNo = request.getParameter("idNo");//证件号码
 | 
	
		
			
				|  |  |             String idType = request.getParameter("idType");//证件类型
 | 
	
		
			
				|  |  |             String insuranceAmount = request.getParameter("insuranceAmount");//医保支付金额
 | 
	
		
			
				|  |  |             String outChargeNo = request.getParameter("outChargeNo");//接入应用业务流水号
 | 
	
		
			
				|  |  |             String outChargeTime = request.getParameter("outChargeTime");//接入应用时间
 | 
	
		
			
				|  |  |             String selfPayAmount = request.getParameter("selfPayAmount");//自付金额
 | 
	
		
			
				|  |  |             String sign = request.getParameter("sign");
 | 
	
		
			
				|  |  |             String signType = request.getParameter("signType");
 | 
	
		
			
				|  |  |             String timestamp = request.getParameter("timestamp");
 | 
	
		
			
				|  |  |             String totalAmount = request.getParameter("totalAmount");//交易总金额
 | 
	
		
			
				|  |  |             String tradeStatus = request.getParameter("tradeStatus");//交易状态
 | 
	
		
			
				|  |  |             String userId = request.getParameter("userId");//用户openID
 | 
	
		
			
				|  |  |             String userName = request.getParameter("userName");//用户名字
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String result = pay.chargeQuery(outChargeNo, getAccessToken());//业务出参
 | 
	
		
			
				|  |  |             JSONObject param = new JSONObject(result);
 | 
	
		
			
				|  |  |             String requestParam = param.getString("responseContent");
 | 
	
		
			
				|  |  |             JSONObject responseContents = new JSONObject(requestParam);//医保结构体
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String miRegisterNo = "";
 | 
	
		
			
				|  |  |             String miCollectDate = "";
 | 
	
		
			
				|  |  |             String miCollectTime = "";
 | 
	
		
			
				|  |  |             String miSettleNo = "";
 | 
	
		
			
				|  |  |             String miCollectStatus = "";
 | 
	
		
			
				|  |  |             String miRegisterStatus = "";
 | 
	
		
			
				|  |  |             String cadresPay = "";
 | 
	
		
			
				|  |  |             String miTotalFee = "";
 | 
	
		
			
				|  |  |             String healthCarePay = "";
 | 
	
		
			
				|  |  |             String heathPay = "";
 | 
	
		
			
				|  |  |             String accountPay = "";
 | 
	
		
			
				|  |  |             String selfPay = "";
 | 
	
		
			
				|  |  |             if (responseContents != null) {
 | 
	
		
			
				|  |  |                miRegisterNo = responseContents.getString("miRegisterNo");//医保签约号
 | 
	
		
			
				|  |  |                  miCollectDate = responseContents.getString("miCollectDate");//扣费日期
 | 
	
		
			
				|  |  |                  miCollectTime = responseContents.getString("miCollectTime");//扣费时间
 | 
	
		
			
				|  |  |                  miSettleNo = responseContents.getString("miSettleNo");//扣费单据号
 | 
	
		
			
				|  |  |                  miCollectStatus = responseContents.getString("miCollectStatus");//扣费状态
 | 
	
		
			
				|  |  |                  miRegisterStatus = responseContents.getString("miRegisterStatus");//登记状态
 | 
	
		
			
				|  |  |                  cadresPay = responseContents.getString("cadresPay");//政府补贴支付
 | 
	
		
			
				|  |  |                  miTotalFee = responseContents.getString("miTotalFee");//扣费总额
 | 
	
		
			
				|  |  |                  healthCarePay = responseContents.getString("healthCarePay");//医保统筹支付
 | 
	
		
			
				|  |  |                  heathPay = responseContents.getString("heathPay");//健康账户支付
 | 
	
		
			
				|  |  |                  accountPay = responseContents.getString("accountPay");//医保账户支付
 | 
	
		
			
				|  |  |                  selfPay = responseContents.getString("selfPay");//个人现金支付
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //                判断是否需要更新数据 needUpload为0不需要更新
 | 
	
		
			
				|  |  |             WlyyCharge charge = chargeDao.getUploadStatus(outChargeNo);
 | 
	
		
			
				|  |  |             if (charge!=null&&!("0".equals(charge.getNeedUpload()))){
 | 
	
		
			
				|  |  |                 pay.updateData(outChargeNo, chargeNo,chargeTime,totalAmount,insuranceAmount,selfPayAmount,billNo,miRegisterNo);
 | 
	
		
			
				|  |  |             if (charge != null && !("0".equals(charge.getNeedUpload()))) {
 | 
	
		
			
				|  |  |                 pay.updateData(outChargeNo, chargeNo, chargeTime, totalAmount, insuranceAmount, selfPayAmount, billNo, miRegisterNo);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             return write(200, "请求成功!");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return error(-1, e.getMessage());
 | 
	
		
			
				|  |  |             isSuccess = false;
 | 
	
		
			
				|  |  |             response.getWriter().write(e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //                记录log日志到数据库
 | 
	
		
			
				|  |  |         logService.saveHttpLog(isSuccess, config.getReturnUrl(), "支付页面跳转", "POST", null, "", responses, error, logService.onepayType);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
	
		
			
				|  | @ -303,17 +345,21 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  |      * @throws IOException
 | 
	
		
			
				|  |  |      * @throws PayException
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/receiveNotify", method = RequestMethod.POST)
 | 
	
		
			
				|  |  |     @ApiOperation("异步回调数据更改")
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/receiveNotify")
 | 
	
		
			
				|  |  |     public void receiveNotify(HttpServletRequest request, HttpServletResponse response) throws IOException, PayException {
 | 
	
		
			
				|  |  |         Boolean isSuccess = false;
 | 
	
		
			
				|  |  |         String error= "";
 | 
	
		
			
				|  |  |         String error = "";
 | 
	
		
			
				|  |  |         String responses = "";
 | 
	
		
			
				|  |  |         response.setContentType("text/html;charset=utf-8");
 | 
	
		
			
				|  |  |         String appId = "1BHEOI11C00J7B2CA8C0000071FA53E1";
 | 
	
		
			
				|  |  |         String appSecret = "1BHEOH8HB0006E0A0A0A00002DB28BC5";
 | 
	
		
			
				|  |  |         InputStream inputStream = request.getInputStream();
 | 
	
		
			
				|  |  |         String params = StreamUtils.copyToString(inputStream, Charset.forName("UTF-8"));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject json = new JSONObject(params);
 | 
	
		
			
				|  |  |         String appId = json.getString("appId");
 | 
	
		
			
				|  |  |         HospitalMapping hospital = mappingDao.findByAppId(appId);
 | 
	
		
			
				|  |  |         String appSecret = hospital.getAppSecret();
 | 
	
		
			
				|  |  | //        String appSecret = json.getString("appId");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         LOGGER.info("回调参数:{}", params);
 | 
	
		
			
				|  |  |         if (StringUtil.isEmpty(params)) {
 | 
	
		
			
				|  |  |             response.getWriter().write("empty");
 | 
	
	
		
			
				|  | @ -324,69 +370,75 @@ public class OnePayController extends WeixinBaseController {
 | 
	
		
			
				|  |  |         OnepayDefaultClient client = new OnepayDefaultClient("", appId, appSecret, encryptRes.getSignType(), encryptRes.getEncryptType());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  | //            已经封装的加解密及签名验证
 | 
	
		
			
				|  |  |             RequestParams requestParams = JSON.parseObject(params, RequestParams.class);
 | 
	
		
			
				|  |  |             ResponseParams<com.alibaba.fastjson.JSONObject> res =  client.execute(requestParams);
 | 
	
		
			
				|  |  |             responses = JSON.toJSONString(res);
 | 
	
		
			
				|  |  |             if (OnepayDefaultClient.isSuccessful(res)) {
 | 
	
		
			
				|  |  |                 isSuccess = true;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 String param = request.getParameter("param");//业务出参
 | 
	
		
			
				|  |  |                 JSONObject requestParam = new JSONObject(param);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 String chargeNo = requestParam.getString("chargeNo"); //支付平台流水号
 | 
	
		
			
				|  |  |                 String chargeTime = requestParam.getString("chargeTime");//支付平台交易成功时间
 | 
	
		
			
				|  |  |                 String outChargeNo = requestParam.getString("outChargeNo");//接入应用业务流水号
 | 
	
		
			
				|  |  |                 String outChargeTime = requestParam.getString("outChargeTime");//接入应用时间
 | 
	
		
			
				|  |  |                 String channel = requestParam.getString("channel");//支付方式
 | 
	
		
			
				|  |  |                 String billNo = requestParam.getString("billNo");//待结算费用单据号
 | 
	
		
			
				|  |  |                 String cardNo = requestParam.getString("cardNo");//医保卡号
 | 
	
		
			
				|  |  |                 String totalAmount = requestParam.getString("totalAmount");//交易总金额
 | 
	
		
			
				|  |  |                 String insuranceAmount = requestParam.getString("insuranceAmount");//医保支付金额
 | 
	
		
			
				|  |  |                 String selfPayAmount = requestParam.getString("selfPayAmount");//自付金额
 | 
	
		
			
				|  |  |                 String userId = requestParam.getString("userId");//用户openID
 | 
	
		
			
				|  |  |                 String userName = requestParam.getString("userName");//用户名字
 | 
	
		
			
				|  |  |                 String idType = requestParam.getString("idType");//证件类型
 | 
	
		
			
				|  |  |                 String idNo = requestParam.getString("idNo");//证件号码
 | 
	
		
			
				|  |  |                 String tradeStatus = requestParam.getString("tradeStatus");//交易状态
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 String responseContent = request.getParameter("responseContent");//医保结构体
 | 
	
		
			
				|  |  |                 JSONObject responseContents = new JSONObject(responseContent);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 String miRegisterNo = responseContents.getString("miRegisterNo");//医保签约号
 | 
	
		
			
				|  |  |                 String miCollectDate = responseContents.getString("miCollectDate");//扣费日期
 | 
	
		
			
				|  |  |                 String miCollectTime = responseContents.getString("miCollectTime");//扣费时间
 | 
	
		
			
				|  |  |                 String miSettleNo = responseContents.getString("miSettleNo");//扣费单据号
 | 
	
		
			
				|  |  |                 String miCollectStatus = responseContents.getString("miCollectStatus");//扣费状态
 | 
	
		
			
				|  |  |                 String miRegisterStatus = responseContents.getString("miRegisterStatus");//登记状态
 | 
	
		
			
				|  |  |                 String cadresPay = responseContents.getString("cadresPay");//政府补贴支付
 | 
	
		
			
				|  |  |                 String miTotalFee = responseContents.getString("miTotalFee");//扣费总额
 | 
	
		
			
				|  |  |                 String healthCarePay = responseContents.getString("healthCarePay");//医保统筹支付
 | 
	
		
			
				|  |  |             LOGGER.info("解密前:{}", JSON.toJSONString(encryptRes));
 | 
	
		
			
				|  |  |             ResponseParams<?> decryptRes = client.decryptNotifyResponse(encryptRes);
 | 
	
		
			
				|  |  |             LOGGER.info("解密后:{}", JSON.toJSONString(decryptRes));
 | 
	
		
			
				|  |  |             boolean isDecrypt = ("-1".equals(decryptRes.getRespCode()) ? false : true); // 是否解密失败
 | 
	
		
			
				|  |  |             if (!isDecrypt) {
 | 
	
		
			
				|  |  |                 response.getWriter().write("DECRYPT FAILURE");
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 boolean isVerify = client.verifyResponseSign(decryptRes);
 | 
	
		
			
				|  |  |                 LOGGER.info("验签结果:{}", isVerify);
 | 
	
		
			
				|  |  |                 if (!isVerify) {
 | 
	
		
			
				|  |  |                     response.getWriter().write("FAILURE");
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  | //					业务逻辑代码
 | 
	
		
			
				|  |  |                     isSuccess = true;
 | 
	
		
			
				|  |  |                     responses = JSON.toJSONString(decryptRes);
 | 
	
		
			
				|  |  |                     JSONObject requestParams = new JSONObject(responses);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     JSONObject requestParam = requestParams.getJSONObject("param");//业务出参
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     String chargeNo = requestParam.getString("chargeNo"); //支付平台流水号
 | 
	
		
			
				|  |  |                     String chargeTime = requestParam.getString("chargeTime");//支付平台交易成功时间
 | 
	
		
			
				|  |  |                     String outChargeNo = requestParam.getString("outChargeNo");//接入应用业务流水号
 | 
	
		
			
				|  |  |                     String outChargeTime = requestParam.getString("outChargeTime");//接入应用时间
 | 
	
		
			
				|  |  |                     String channel = requestParam.getString("channel");//支付方式
 | 
	
		
			
				|  |  |                     String billNo = requestParam.getString("billNo");//待结算费用单据号
 | 
	
		
			
				|  |  |                     String cardNo = requestParam.getString("cardNo");//医保卡号
 | 
	
		
			
				|  |  |                     String totalAmount = requestParam.getString("totalAmount");//交易总金额
 | 
	
		
			
				|  |  |                     String insuranceAmount = requestParam.getString("insuranceAmount");//医保支付金额
 | 
	
		
			
				|  |  |                     String selfPayAmount = requestParam.getString("selfPayAmount");//自付金额
 | 
	
		
			
				|  |  |                     String userId = requestParam.getString("userId");//用户openID
 | 
	
		
			
				|  |  |                     String userName = requestParam.getString("userName");//用户名字
 | 
	
		
			
				|  |  |                     String idType = requestParam.getString("idType");//证件类型
 | 
	
		
			
				|  |  |                     String idNo = requestParam.getString("idNo");//证件号码
 | 
	
		
			
				|  |  |                     String tradeStatus = requestParam.getString("tradeStatus");//交易状态
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     String miRegisterNo = "";//医保签约号
 | 
	
		
			
				|  |  |                     if (requestParams.has("responseContent") && (requestParams.getJSONObject("responseContent") != null)) {
 | 
	
		
			
				|  |  |                         JSONObject responseContents = requestParams.getJSONObject("responseContent");//医保结构体
 | 
	
		
			
				|  |  |                         miRegisterNo = responseContents.getString("miRegisterNo");//医保签约号
 | 
	
		
			
				|  |  |                         String miCollectDate = responseContents.getString("miCollectDate");//扣费日期
 | 
	
		
			
				|  |  |                         String miCollectTime = responseContents.getString("miCollectTime");//扣费时间
 | 
	
		
			
				|  |  |                         String miSettleNo = responseContents.getString("miSettleNo");//扣费单据号
 | 
	
		
			
				|  |  |                         String miCollectStatus = responseContents.getString("miCollectStatus");//扣费状态
 | 
	
		
			
				|  |  |                         String miRegisterStatus = responseContents.getString("miRegisterStatus");//登记状态
 | 
	
		
			
				|  |  |                         String cadresPay = responseContents.getString("cadresPay");//政府补贴支付
 | 
	
		
			
				|  |  |                         String miTotalFee = responseContents.getString("miTotalFee");//扣费总额
 | 
	
		
			
				|  |  |                         String healthCarePay = responseContents.getString("healthCarePay");//医保统筹支付
 | 
	
		
			
				|  |  | //                responseContents.getString("healthPay");
 | 
	
		
			
				|  |  |                 String heathPay = responseContents.getString("heathPay");//健康账户支付
 | 
	
		
			
				|  |  |                 String accountPay = responseContents.getString("accountPay");//医保账户支付
 | 
	
		
			
				|  |  |                 String selfPay = responseContents.getString("selfPay");//个人现金支付
 | 
	
		
			
				|  |  |                         String heathPay = responseContents.getString("heathPay");//健康账户支付
 | 
	
		
			
				|  |  |                         String accountPay = responseContents.getString("accountPay");//医保账户支付
 | 
	
		
			
				|  |  |                         String selfPay = responseContents.getString("selfPay");//个人现金支付
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //                判断是否需要更新数据 needUpload为0不需要更新
 | 
	
		
			
				|  |  |                 WlyyCharge charge = chargeDao.getUploadStatus(outChargeNo);
 | 
	
		
			
				|  |  |                 if (charge!=null&&!("0".equals(charge.getNeedUpload()))){
 | 
	
		
			
				|  |  |                     pay.updateData(outChargeNo, chargeNo,chargeTime,totalAmount,insuranceAmount,selfPayAmount,billNo,miRegisterNo);
 | 
	
		
			
				|  |  |                     WlyyCharge charge = chargeDao.getUploadStatus(outChargeNo);
 | 
	
		
			
				|  |  |                     if (charge != null && !("0".equals(charge.getNeedUpload()))) {
 | 
	
		
			
				|  |  |                         pay.updateData(outChargeNo, chargeNo, chargeTime, totalAmount, insuranceAmount, selfPayAmount, billNo, miRegisterNo);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     response.getWriter().write("SUCCESS");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 isSuccess = false;
 | 
	
		
			
				|  |  |                 error = "请求失败,返回结果:" + res.getRespCode() + "," + res.getRespMsg();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception ex) {
 | 
	
		
			
				|  |  |             isSuccess = false;
 | 
	
		
			
				|  |  |             StringWriter sw = new StringWriter();
 | 
	
		
			
				|  |  |             PrintWriter pw = new PrintWriter(sw);
 | 
	
		
			
				|  |  |             ex.printStackTrace(pw);
 | 
	
		
			
				|  |  |             error = sw.toString();
 | 
	
		
			
				|  |  |             response.getWriter().write(ex.getMessage());
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             response.getWriter().write(e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //                记录log日志到数据库
 | 
	
		
			
				|  |  |                 logService.saveHttpLog(isSuccess, config.getReceiveNotify(), "异步支付通知", "POST", null, params, responses, error, logService.onepayType);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         logService.saveHttpLog(isSuccess, config.getReceiveNotify(), "异步支付通知", "POST", null, params, responses, error, logService.onepayType);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |