|
|
|
|
package com.ynxbd.common.action.pay;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.ynxbd.common.action.base.BaseAction;
|
|
|
|
|
import com.ynxbd.common.bean.enums.MerchantEnum;
|
|
|
|
|
import com.ynxbd.common.bean.pay.ApiPayNotify;
|
|
|
|
|
import com.ynxbd.common.bean.pay.ReqOrder;
|
|
|
|
|
import com.ynxbd.common.helper.common.HttpHelper;
|
|
|
|
|
import com.ynxbd.common.helper.common.JsonHelper;
|
|
|
|
|
import com.ynxbd.common.result.Result;
|
|
|
|
|
import com.ynxbd.common.result.ResultEnum;
|
|
|
|
|
import com.ynxbd.common.result.ServiceException;
|
|
|
|
|
import com.ynxbd.common.service.PayService;
|
|
|
|
|
import com.ynxbd.common.service.RegService;
|
|
|
|
|
import com.ynxbd.common.service.RxService;
|
|
|
|
|
import com.ynxbd.jy.bean.JYOrder;
|
|
|
|
|
import com.ynxbd.jy.bean.JYPayNotify;
|
|
|
|
|
import com.ynxbd.jy.bean.JYPayRSAUtil;
|
|
|
|
|
import com.ynxbd.jy.bean.enums.JYBusinessTypeEnum;
|
|
|
|
|
import com.ynxbd.jy.bean.enums.JYOrderTypeEnum;
|
|
|
|
|
import com.ynxbd.jy.helper.JYPayConfig;
|
|
|
|
|
import com.ynxbd.jy.helper.JYPayHelper;
|
|
|
|
|
import com.ynxbd.wx.wxfactory.WxPayHelper;
|
|
|
|
|
import com.ynxbd.wx.wxfactory.utils.WxRespHelper;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
import org.apache.struts2.convention.annotation.Action;
|
|
|
|
|
import org.apache.struts2.convention.annotation.Namespace;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Namespace("/jy_pay")
|
|
|
|
|
public class JYPayAction extends BaseAction {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* [京颐支付]JSAPI预下单
|
|
|
|
|
*/
|
|
|
|
|
@Action("jsapi_prepay")
|
|
|
|
|
public Result jsapi_prepay(String payOpenId, String openid, String patientId, BigDecimal totalFee) {
|
|
|
|
|
String merOrderNum = MerchantEnum.JY.createBizTradeNo();
|
|
|
|
|
log.info("[京颐支付]测试 outTradeNo={}, totalFee={}", merOrderNum, totalFee);
|
|
|
|
|
if (totalFee == null || ObjectUtils.isEmpty(openid) || ObjectUtils.isEmpty(patientId)) {
|
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String ip = HttpHelper.getIpAddress(request);
|
|
|
|
|
String title = "支付测试";
|
|
|
|
|
|
|
|
|
|
ReqOrder req = new ReqOrder();
|
|
|
|
|
req.setPatientName("小王");
|
|
|
|
|
req.setPatientGender("男");
|
|
|
|
|
req.setPatientAge("18");
|
|
|
|
|
req.setPatientTel("15559603353");
|
|
|
|
|
req.setTreatNum("T001");
|
|
|
|
|
req.setPatientIdCardNo("532331199910053810");
|
|
|
|
|
req.setPatientId("1000001");
|
|
|
|
|
|
|
|
|
|
JYOrder jyOrder = new JYOrder();
|
|
|
|
|
jyOrder.orderTypeEnum = JYOrderTypeEnum._001; // 挂号费
|
|
|
|
|
jyOrder.businessTypeEnum = JYBusinessTypeEnum.B102;
|
|
|
|
|
|
|
|
|
|
req.setJyOrder(jyOrder);
|
|
|
|
|
JSONObject prepay = JYPayHelper.createOrder(MerchantEnum.JY, title, merOrderNum, totalFee.toString(), PEnum.REG.CODE, ip, payOpenId, openid, req);
|
|
|
|
|
if (prepay == null) {
|
|
|
|
|
return Result.error(ResultEnum.PAY_ERROR_ORDER); // 下单异常
|
|
|
|
|
}
|
|
|
|
|
return Result.success(prepay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * [京颐支付]JSAPI预下单
|
|
|
|
|
// */
|
|
|
|
|
// @Action("refund_test")
|
|
|
|
|
// public Result refund_test(String outRefundNo, BigDecimal refundFee, String outTradeNo, String bankMerchantNo, String tradeNo) {
|
|
|
|
|
//
|
|
|
|
|
// log.info("[京颐支付]退费测试 outRefundNo={}, refundFee={}, outTradeNo={}, bankMerchantNo={}, tradeNo={}",
|
|
|
|
|
// outRefundNo, refundFee, outTradeNo, bankMerchantNo, tradeNo);
|
|
|
|
|
//
|
|
|
|
|
// ReqOrder req = new ReqOrder();
|
|
|
|
|
// req.setPatientName("小王");
|
|
|
|
|
// req.setPatientGender("男");
|
|
|
|
|
// req.setPatientAge("18");
|
|
|
|
|
// req.setPatientTel("15559603353");
|
|
|
|
|
// req.setTreatNum("T001");
|
|
|
|
|
// req.setPatientIdCardNo("532331199910053810");
|
|
|
|
|
// req.setPatientId("1000001");
|
|
|
|
|
//
|
|
|
|
|
// JSONObject prepay = JYPayHelper.refundPayOrder(JYBusinessTypeEnum.B102, req, outRefundNo, refundFee, outTradeNo, bankMerchantNo, tradeNo);
|
|
|
|
|
// if (prepay == null) {
|
|
|
|
|
// return Result.error(); // 下单异常
|
|
|
|
|
// }
|
|
|
|
|
// return Result.success(prepay);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* [京颐支付]订单查询
|
|
|
|
|
*/
|
|
|
|
|
@Action("query_order")
|
|
|
|
|
public Result query_order(String outTradeNo, String merOrderNum, String tradeNo) {
|
|
|
|
|
log.info("[京颐支付]订单查询 outTradeNo={}, merOrderNum={}, tradeNo={}",
|
|
|
|
|
outTradeNo, merOrderNum, tradeNo);
|
|
|
|
|
|
|
|
|
|
JSONObject prepay = JYPayHelper.queryPayOrderInfo(outTradeNo, merOrderNum, tradeNo);
|
|
|
|
|
if (prepay == null) {
|
|
|
|
|
return Result.error(ResultEnum.DATA_NOT_FOUND);
|
|
|
|
|
}
|
|
|
|
|
return Result.success(prepay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 【京颐】支付|退款通知
|
|
|
|
|
*/
|
|
|
|
|
@Action("notify")
|
|
|
|
|
public Result notify(String notifyType) {
|
|
|
|
|
try {
|
|
|
|
|
PEnum pEnum = PEnum.findEnum(notifyType);
|
|
|
|
|
if (pEnum == null) {
|
|
|
|
|
return Result.respXml(WxRespHelper.respOk());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, String> params = reqParamsToMap();
|
|
|
|
|
String sign = JYPayRSAUtil.createSign(params, JYPayConfig.PRIVATE_KEY);
|
|
|
|
|
|
|
|
|
|
log.info("[sign]{}", sign);
|
|
|
|
|
ApiPayNotify info = JYPayHelper.jyPayNotify(reqParamsToBean(JYPayNotify.class), notifyType);
|
|
|
|
|
|
|
|
|
|
log.info("【京颐】[{}]收到[{}]通知-{}", pEnum.NAME, (info.isRefundOrder() ? "退款" : "支付"), JsonHelper.toJsonString(info));
|
|
|
|
|
Result.respXml(WxRespHelper.respOk()); // 收到请求-解析成功
|
|
|
|
|
|
|
|
|
|
if (info.isRefundOrder()) {
|
|
|
|
|
PayService.refundNotify(info);
|
|
|
|
|
} else {
|
|
|
|
|
PayService.wxNotify(info);
|
|
|
|
|
}
|
|
|
|
|
} catch (ServiceException e) {
|
|
|
|
|
Result.respXml(WxRespHelper.resp(e)); // 收到请求-解析失败
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|