微信后端代码
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.

78 lines
3.0 KiB

package com.ynxbd.common.action.pay;
import com.ynxbd.bcm.config.BCMHelper;
import com.ynxbd.common.action.base.BaseAction;
import com.ynxbd.common.bean.enums.MerchantEnum;
import com.ynxbd.common.bean.pay.PayResult;
import com.ynxbd.common.helper.common.DateHelper;
import com.ynxbd.common.result.Result;
import com.ynxbd.common.result.ServiceException;
import com.ynxbd.common.service.RecipeService;
import com.ynxbd.common.service.RegService;
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.Date;
@Slf4j
@Namespace("/bcm_pay")
public class BcmPayAction extends BaseAction {
/**
* [交行]处方支付通知
*
* @return 是否成功
*/
@Action("notify")
public Result notify(String notifyType) {
if (ObjectUtils.isEmpty(notifyType)) {
Result.respJson(BCMHelper.respError(String.format("【交行】获取回调参数失败,结束请求 notifyType={%s}", notifyType)));
return null;
}
try {
PayResult notifyInfo = BCMHelper.payNotify(request);
Result.respJson(BCMHelper.respOk()); // 成功
String openid = notifyInfo.getOpenid();
String bankTransNo = notifyInfo.getTransId();
String outTradeNo = notifyInfo.getOutTradeNo();
BigDecimal totalFee = notifyInfo.getTotalFee();
String payInfo = notifyInfo.getInfo();
String payDate = DateHelper.getCurDate();
String payTime = DateHelper.getCurTime();
String bankMerchantNo = notifyInfo.getBankMerchantNo();
log.info("【交行】[{}] 收到通知 outTradeNo={}, bankTransNo={}, bankMerchantNo={}", notifyType, outTradeNo, bankTransNo, bankMerchantNo);
switch (PEnum.toEnum(notifyType)) {
case RECIPE:
new RecipeService().recipeListPay(MerchantEnum.BCM, totalFee.toString(), openid, outTradeNo, bankTransNo, bankMerchantNo, payDate, payTime, payInfo);
break;
case REG: // 挂号
try {
new RegService().regPaidNotify(MerchantEnum.BCM, totalFee, openid, bankTransNo, outTradeNo, bankMerchantNo, payDate, payTime, payInfo, new Date());
} catch (ServiceException e) {
log.info("【交行]挂号通知错误 outTradeNo={}, bankTransNo={}, message={}", outTradeNo, bankTransNo, e.getMessage());
}
break;
default:
log.info("【交行】通知类型错误,结束请求");
break;
}
} catch (ServiceException e) {
log.error(e.getMessage());
Result.respJson(BCMHelper.resp(e));
}
return null;
}
}