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.
221 lines
9.2 KiB
221 lines
9.2 KiB
//package com.ynxbd.wx.servlet;
|
|
//
|
|
//import com.ynxbd.api.result.WsResult;
|
|
//import com.ynxbd.api.service.HCodeService;
|
|
//import com.ynxbd.common.bean.PayInfoBean;
|
|
//import com.ynxbd.common.bean.RegResponseBean;
|
|
//import com.ynxbd.common.bean.ReservationBean4Local;
|
|
//import com.ynxbd.common.dao.DBDao;
|
|
//import com.ynxbd.common.dao.WSDao;
|
|
//import com.ynxbd.api.utils.DateGenerate;
|
|
//import com.ynxbd.api.config.WeChatConfig;
|
|
//import com.ynxbd.api.utils.CommonUtil;
|
|
//import com.ynxbd.api.utils.Global;
|
|
//import org.apache.log4j.Logger;
|
|
//import org.apache.log4j.NDC;
|
|
//import weixin.popular.bean.paymch.MchBaseResult;
|
|
//import weixin.popular.bean.paymch.MchPayNotify;
|
|
//import weixin.popular.util.SignatureUtil;
|
|
//import weixin.popular.util.StreamUtils;
|
|
//import weixin.popular.util.XMLConverUtil;
|
|
//
|
|
//import javax.servlet.ServletInputStream;
|
|
//import javax.servlet.ServletOutputStream;
|
|
//import javax.servlet.http.HttpServlet;
|
|
//import javax.servlet.http.HttpServletRequest;
|
|
//import javax.servlet.http.HttpServletResponse;
|
|
//import java.io.IOException;
|
|
//import java.nio.charset.StandardCharsets;
|
|
//import java.util.List;
|
|
//import java.util.Map;
|
|
//import java.util.UUID;
|
|
//
|
|
///**
|
|
// * 非分时段挂号支付成功通知
|
|
// *
|
|
// * @author 张剑峰
|
|
// * @version v1.0.0
|
|
// * @Project:微信公众号
|
|
// * @date 2017年7月23日下午4:28:39
|
|
// * @Copyright: 2017云南新八达科技有限公司 All rights reserved.
|
|
// */
|
|
//public class RegPayMchNotifyServlet extends HttpServlet {
|
|
//
|
|
// private static final Logger logger = Logger.getLogger(RegPayMchNotifyServlet.class);
|
|
//
|
|
// @Override
|
|
// protected void doPost(HttpServletRequest request, HttpServletResponse response) {
|
|
// String remoteAddr = Global.getIpAddr(request);
|
|
// NDC.remove();
|
|
// NDC.push(remoteAddr);
|
|
//
|
|
// ServletInputStream inputStream = null;
|
|
// ServletOutputStream outputStream = null;
|
|
// try {
|
|
// inputStream = request.getInputStream();
|
|
// outputStream = response.getOutputStream();
|
|
//
|
|
// // 获取请求数据
|
|
// String wxXmlData = StreamUtils.copyToString(request.getInputStream(), StandardCharsets.UTF_8);
|
|
// // 将XML转为MAP,确保所有字段都参与签名验证
|
|
// Map<String, String> wxMapData = XMLConverUtil.convertToMap(wxXmlData);
|
|
// StringBuilder wxResp = new StringBuilder();
|
|
// for (String key : wxMapData.keySet()) {
|
|
// wxResp.append(key).append("=").append(wxMapData.get(key)).append(";"); // 拼接微信返回的信息
|
|
// }
|
|
//
|
|
// // 转换数据对象
|
|
// MchPayNotify wxPayNotify = XMLConverUtil.convertToObject(MchPayNotify.class, wxXmlData);
|
|
// String wxOpenid = wxPayNotify.getOpenid();
|
|
// String wxTradeNo = wxPayNotify.getOut_trade_no();
|
|
// String wxTransactionId = wxPayNotify.getTransaction_id();
|
|
// Integer wxTotalFee = wxPayNotify.getTotal_fee(); // 金额
|
|
//
|
|
// // 已处理 去重
|
|
// if (Global.keys.exists(wxTransactionId)) {
|
|
// return;
|
|
// } else {
|
|
// Global.keys.add(wxTransactionId, Global.expire);
|
|
// }
|
|
//
|
|
// // @since 2.8.5
|
|
// wxPayNotify.buildDynamicField(wxMapData);
|
|
//
|
|
// MchBaseResult baseResult = new MchBaseResult();
|
|
//
|
|
// // 签名验证失败
|
|
// if (!SignatureUtil.validateSign(wxMapData, WeChatConfig.getMchKey())) {
|
|
// baseResult.setReturn_code("FAIL");
|
|
// baseResult.setReturn_msg("ERROR");
|
|
// outputStream.write(XMLConverUtil.convertToXML(baseResult).getBytes());
|
|
//
|
|
// logger.info("支付失败!");
|
|
// return;
|
|
// }
|
|
//
|
|
// // 验证通过
|
|
// baseResult.setReturn_code("SUCCESS");
|
|
// baseResult.setReturn_msg("OK");
|
|
// outputStream.write(XMLConverUtil.convertToXML(baseResult).getBytes());
|
|
//
|
|
// // 保存支付结果
|
|
// PayInfoBean payInfo = new PayInfoBean();
|
|
// payInfo.setOpenID(wxOpenid);
|
|
// payInfo.setTradeNo(wxTradeNo);
|
|
// payInfo.setInfo(wxResp.toString());
|
|
//
|
|
// DBDao dbDao = new DBDao();
|
|
//
|
|
// // 是否预约成功
|
|
// if (dbDao.hasReserved(wxTradeNo)) {
|
|
// return;
|
|
// }
|
|
//
|
|
// dbDao.savePayResult(payInfo);
|
|
//
|
|
// List<String> lstDate = DateGenerate.getDateAndTime(wxPayNotify.getTime_end());
|
|
//
|
|
// // 更新挂号信息R
|
|
// ReservationBean4Local reserve = dbDao.updateReserve(wxTradeNo, lstDate.get(0), lstDate.get(1), wxTransactionId);
|
|
// if (reserve == null) {
|
|
// logger.info("更新挂号信息失败");
|
|
// return;
|
|
// }
|
|
//
|
|
// String reserveTradeNo = reserve.getTradeNo();
|
|
// String patientId = reserve.getPatientId();
|
|
// if ("".equals(patientId) || reserveTradeNo == null) {
|
|
// logger.info(String.format("挂号失败reservation=null,patientId=%s, tradeNo=%s, transNo=%s", patientId, reserveTradeNo, wxTransactionId));
|
|
// return;
|
|
// }
|
|
//
|
|
// // 挂号
|
|
// logger.info(String.format("开始调用HIS挂号:patientId=%s", patientId));
|
|
//
|
|
// String transNo = reserve.getBankTransNo();
|
|
// reserve.setTransNo(transNo);
|
|
//
|
|
// WSDao wsDao = new WSDao();
|
|
// WsResult wsResult = wsDao.reg(reserve);
|
|
// if (wsResult.getResponseCode() == -1) { // 调用HIS失败-->自动退款
|
|
// logger.info(String.format("调用HIS挂号失败:patientId=%s", patientId));
|
|
// // 自动退款
|
|
// wxRefund(wxOpenid, wxTradeNo, wxTotalFee, wxTransactionId, wsResult.getResponseMessage());
|
|
// return;
|
|
// }
|
|
//
|
|
// RegResponseBean reg = wsResult.getDataMapBean(RegResponseBean.class);
|
|
// String mzNum = reg.getMZNum();
|
|
// String hisTransNo = reg.getHISTransNo();
|
|
//
|
|
// logger.info(String.format("HIS返回 hisTransNo=%s, mzNum=%s", hisTransNo, mzNum));
|
|
//
|
|
// // 更新挂号信息
|
|
// logger.info(String.format("更新挂号信息(after his reservation):tradeNo=%s, patientId=%s, transNo=%s", wxTradeNo, patientId, wxTransactionId));
|
|
// dbDao.updateRegAfter(wxTradeNo, wxTransactionId, hisTransNo, mzNum);
|
|
// logger.info(String.format("挂号成功,patientId=%s", patientId));
|
|
//
|
|
// HCodeService.regPayReportHISData(wxOpenid, patientId, reserve.getDeptName(), reserve.getReservationDate()); // 电子健康卡上报数据
|
|
//
|
|
// } catch (IOException e) {
|
|
// logger.info("回复微信支付成功通知异常");
|
|
// e.printStackTrace();
|
|
// } finally {
|
|
// try {
|
|
// if (inputStream != null) inputStream.close();
|
|
//
|
|
// if (outputStream != null) outputStream.close();
|
|
// } catch (Exception e) {
|
|
// e.printStackTrace();
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
// /**
|
|
// * 自动退款
|
|
// *
|
|
// * @param openid openid
|
|
// * @param tradeNo 商户单号
|
|
// * @param payMoney 退款金额
|
|
// * @param transNo 交易流水号
|
|
// * @param message 退款原因
|
|
// * @return 是否成功
|
|
// */
|
|
// private boolean wxRefund(String openid, String tradeNo, Integer payMoney, String transNo, String message) {
|
|
// boolean result = false;
|
|
//
|
|
// // 如果HIS交过费返回true-->就不向下执行(自动退款)
|
|
// String dateShort = DateGenerate.getStringDateShort();
|
|
// if (new WSDao().hasOutPayed(DateGenerate.getNextDay(dateShort, "-7"), DateGenerate.getNextDay(dateShort, "7"), transNo)) {
|
|
// logger.info(String.format("His已经缴费成功,不退费, tradeNo=%s, transNo=%s", tradeNo, transNo));
|
|
// return false;
|
|
// }
|
|
//
|
|
// logger.info(String.format("挂号失败,开始申请退款transNo=%s", transNo));
|
|
// DBDao dbDao = new DBDao();
|
|
// // 预约失败后记录
|
|
// if (!dbDao.updateReserveAfterFail(tradeNo, message)) { // 记录失败
|
|
// logger.info(String.format("预约记录失败transNo=%s", transNo));
|
|
// }
|
|
//
|
|
// // 退款
|
|
// boolean refundResult = dbDao.refund(1,
|
|
// UUID.randomUUID().toString().replace("-", ""),
|
|
// tradeNo,
|
|
// payMoney,
|
|
// message);
|
|
//
|
|
// if (refundResult) { // 退款成功
|
|
// logger.info(String.format("自动退款申请成功:tradeNo=%s", transNo));
|
|
// try {
|
|
// CommonUtil.sendMessage(openid, String.format("挂号失败,%s,已申请退款:%s", message, transNo)); // 推送消息
|
|
// result = true;
|
|
// } catch (Exception ex) {
|
|
// logger.info(String.format("自动退款失败:tradeNo=%s", transNo));
|
|
// logger.info(ex.getMessage());
|
|
// }
|
|
// }
|
|
// return result;
|
|
// }
|
|
//}
|
|
|