|
|
|
@@ -82,261 +82,261 @@ public class WxSubsidyServiceImpl implements WxSubsidyService { |
|
|
|
"\"REQUIRE_POST_METHOD\":{\"detail\":\"请使用post方法\",\"reason\":\"未使用post传递参数\",\"resolution\":\"请检查请求参数是否通过post方法提交\"}," + |
|
|
|
"\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData createSubsidy(MallUserInfo user, String ip, String amountStr) { |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
EnumPayShare isShare = EnumPayShare.NO; |
|
|
|
Date curDate = new Date(); |
|
|
|
// 1. 获取c端小程序 |
|
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfo(user); |
|
|
|
// 2. 获取payAccount |
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); |
|
|
|
if (payAccount.checkShare()) { |
|
|
|
isShare = EnumPayShare.YES; |
|
|
|
} |
|
|
|
// 3. 补贴订单 |
|
|
|
BigDecimal amountY = new BigDecimal(amountStr); |
|
|
|
int totalFee = amountY.multiply(new BigDecimal(100)).intValue(); // 元->分 |
|
|
|
|
|
|
|
Long id = idWorker.nextId(); |
|
|
|
String payOrderNo = String.valueOf(id); |
|
|
|
WxSubsidy record = new WxSubsidy(); |
|
|
|
record.setId(id); |
|
|
|
record.updateTenantInfo(user); |
|
|
|
record.setOperatorUserId(user.getId()); |
|
|
|
record.setCreateTime(curDate); |
|
|
|
record.setUpdateTime(curDate); |
|
|
|
record.setOrderNo(payOrderNo); |
|
|
|
record.setBody("商场补贴-"+amountStr + "元"); |
|
|
|
record.setIp(ip); |
|
|
|
record.setStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); |
|
|
|
record.setPayTimeStart(curDate); |
|
|
|
record.setPayTimeEnd(curDate); |
|
|
|
record.setAmount(totalFee); |
|
|
|
// 分账金额 |
|
|
|
int iChargeFee = PayUtils.getPayRate(record.getAmount(), payAccount.getRate(), false); |
|
|
|
Integer share_amount = record.getAmount() - iChargeFee; |
|
|
|
record.setShareAmount(share_amount); |
|
|
|
record.setShareRemainAmount(share_amount); |
|
|
|
try { |
|
|
|
wxSubsidyMapper.insert(record); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("wx_subsidy save fail" + e.getMessage()); |
|
|
|
return new ResultData(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
// 3. 支付发起 |
|
|
|
try { |
|
|
|
// 统一下单 // 服务商模式 |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
WxNativePayOrderSP payOrder = new WxNativePayOrderSP(); |
|
|
|
payOrder.setAppid(appInfo.getParentAppId()); |
|
|
|
payOrder.setSub_appid(appInfo.getAppId()); |
|
|
|
payOrder.setMch_id(payAccount.getMchId()); |
|
|
|
payOrder.setSub_mch_id(payAccount.getSubMchId()); |
|
|
|
payOrder.setDevice_info("WEB"); |
|
|
|
payOrder.setNonce_str(noncestr); |
|
|
|
payOrder.setBody(record.getBody()); |
|
|
|
payOrder.setOut_trade_no(record.getOrderNo()); |
|
|
|
payOrder.setTotal_fee(record.getAmount()); |
|
|
|
payOrder.setSpbill_create_ip(record.getIp()); |
|
|
|
payOrder.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(curDate)); |
|
|
|
Date futureDate = new Date(); |
|
|
|
futureDate.setTime(curDate.getTime() + 15 * 60 * 1000); |
|
|
|
payOrder.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 |
|
|
|
payOrder.setNotify_url(payAccount.getSubsidyNotifyUrl()); |
|
|
|
payOrder.setTrade_type("NATIVE"); |
|
|
|
payOrder.setProduct_id(record.getOrderNo()); |
|
|
|
payOrder.setSign_type("HMAC-SHA256"); |
|
|
|
payOrder.setProfit_sharing(null); |
|
|
|
if (isShare == EnumPayShare.YES) { |
|
|
|
payOrder.setProfit_sharing("Y"); |
|
|
|
} |
|
|
|
Map<String, String> payOrderMap = BeanUtils.toStringMap(payOrder); |
|
|
|
|
|
|
|
payOrder.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); |
|
|
|
String response = WxPay.pushOrder(BeanUtils.toStringMap(payOrder)); |
|
|
|
logger.info("wx_subsidy wechat native Pay, " + payOrder.toString() + ", response: " + response.toString()); |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
String return_code = returnMap.get("return_code"); |
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if ("SUCCESS".equalsIgnoreCase(return_code)) { |
|
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
|
String prepay_id = returnMap.get("prepay_id"); |
|
|
|
String code_url = returnMap.get("code_url"); |
|
|
|
// update payOrder with prepay_id |
|
|
|
record.setPrepayId(prepay_id); |
|
|
|
record.setCodeUrl(code_url); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
try { |
|
|
|
wxSubsidyMapper.updateById(record); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("wx_subsidy update error: " + record.toString()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, String> retMap = new HashMap<String, String>(); |
|
|
|
retMap.put("code_url", code_url); |
|
|
|
return new ResultData(Result.SUCCESS, "创建支付订单成功", retMap); |
|
|
|
} else { |
|
|
|
String errMsg = ""; |
|
|
|
JSONObject errObj = errorMap.getJSONObject(result_code); |
|
|
|
if (errObj != null) { |
|
|
|
errMsg = errObj.toJSONString(); |
|
|
|
record.setFailReason(errMsg); |
|
|
|
} else { |
|
|
|
errMsg = returnMap.get("return_msg"); |
|
|
|
record.setFailReason(errMsg); |
|
|
|
} |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
try { |
|
|
|
wxSubsidyMapper.updateById(record); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("pay order update error: " + record.toString()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); |
|
|
|
} |
|
|
|
} else { |
|
|
|
String errMsg = returnMap.get("return_msg"); |
|
|
|
record.setFailReason(errMsg); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
try { |
|
|
|
wxSubsidyMapper.updateById(record); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("pay order update error: " + record.toString()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); |
|
|
|
} |
|
|
|
} catch (RuntimeException e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 提供微信支付回调调用 |
|
|
|
* |
|
|
|
* @param paramMap 异步通知参数 |
|
|
|
* @param payWay 支付方式 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String notify(Map<String, String> paramMap, EnumPayWay payWay) { |
|
|
|
// how to get wechatAppId, wechatMchId, partnerKey |
|
|
|
String appId = paramMap.get("appid"); |
|
|
|
String subAppId = paramMap.get("sub_appid"); |
|
|
|
String mchId = paramMap.get("mch_id"); |
|
|
|
String subMchId = paramMap.get("sub_mch_id"); |
|
|
|
WxAppinfo appinfo = null; |
|
|
|
boolean isNormal = true; |
|
|
|
if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) { |
|
|
|
// 普通商户号 |
|
|
|
appinfo = wxAppinfoMapper.findByAppId(appId); |
|
|
|
if (appinfo == null) { |
|
|
|
logger.error("appid not found: " + appId); |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
isNormal = true; |
|
|
|
} else { |
|
|
|
// 服务号 现在用hmac-sha256 |
|
|
|
appinfo = wxAppinfoMapper.findByAppId(subAppId); |
|
|
|
if (appinfo == null) { |
|
|
|
logger.error("subappid not found: " + subAppId); |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
isNormal = false; |
|
|
|
} |
|
|
|
|
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); |
|
|
|
if (payAccount == null) { |
|
|
|
throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND); |
|
|
|
} |
|
|
|
String partnerKey = payAccount.getApiKey(); |
|
|
|
try { |
|
|
|
if (payWay.getType() == EnumPayWay.EnumPayWayType.WX_MINIPAY) { |
|
|
|
boolean signVerified = false; |
|
|
|
if (isNormal) { |
|
|
|
// 普通商户号支付 |
|
|
|
signVerified = WxPayment.verifyNotify(paramMap, partnerKey); |
|
|
|
if (!signVerified) { |
|
|
|
logger.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 服务号 现在用hmac-sha256 |
|
|
|
signVerified = WxPayment.verifyNotifyHMAC(paramMap, partnerKey); |
|
|
|
if (!signVerified) { |
|
|
|
logger.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!"SUCCESS".equals(paramMap.get("return_code"))) { |
|
|
|
logger.warn("notify order, wxpay status not success, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
SortedMap resultMap = new TreeMap(); |
|
|
|
resultMap.put("return_code", "FAIL"); |
|
|
|
resultMap.put("return_msg", "订单状态码非SUCCESS"); |
|
|
|
return XmlUtil.getRequestXml(resultMap); |
|
|
|
} |
|
|
|
|
|
|
|
String payOrderNo = paramMap.get("out_trade_no"); |
|
|
|
String transactionId = paramMap.get("transaction_id"); |
|
|
|
String openId = paramMap.get("sub_openid"); |
|
|
|
String timEndStr = paramMap.get("time_end"); |
|
|
|
Long payOrderId = Long.valueOf(payOrderNo); |
|
|
|
WxSubsidy subsidy = wxSubsidyMapper.selectById(payOrderId); |
|
|
|
if (subsidy == null) { |
|
|
|
logger.warn("notify order, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
SortedMap resultMap = new TreeMap(); |
|
|
|
resultMap.put("return_code", "FAIL"); |
|
|
|
resultMap.put("return_msg", "订单不存在"); |
|
|
|
return XmlUtil.getRequestXml(resultMap); |
|
|
|
} |
|
|
|
// 验证支付金额 |
|
|
|
if (!paramMap.get("total_fee").equals(subsidy.getAmount().toString())) { |
|
|
|
logger.warn("notify order, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
SortedMap resultMap = new TreeMap(); |
|
|
|
resultMap.put("return_code", "FAIL"); |
|
|
|
resultMap.put("return_msg", "订单总金额不一致"); |
|
|
|
return XmlUtil.getRequestXml(resultMap); |
|
|
|
} |
|
|
|
|
|
|
|
Date timeEnd = null; |
|
|
|
|
|
|
|
try { |
|
|
|
timeEnd = Utility.getDateFromString(timEndStr); |
|
|
|
} catch (ParseException e) { |
|
|
|
logger.error("解析timeEnd失败"); |
|
|
|
timeEnd = new Date(); |
|
|
|
} |
|
|
|
subsidy.setPayTimeEnd(timeEnd); |
|
|
|
subsidy.setTransactionId(transactionId); |
|
|
|
subsidy.setStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); |
|
|
|
subsidy.setOpenId(openId); |
|
|
|
subsidy.setUpdateTime(new Date()); |
|
|
|
try { |
|
|
|
wxSubsidyMapper.updateById(subsidy); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("wx_subsidy update exception"); |
|
|
|
} |
|
|
|
logger.info("notify order, wxpay checksign success, paramMap:{}, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
SortedMap resultMap = new TreeMap(); |
|
|
|
resultMap.put("return_code", "SUCCESS"); |
|
|
|
resultMap.put("return_msg", "OK"); |
|
|
|
return XmlUtil.getRequestXml(resultMap); |
|
|
|
} |
|
|
|
} catch (RuntimeException e) { |
|
|
|
logger.warn("notify order, checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString() + ", e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
SortedMap resultMap = new TreeMap(); |
|
|
|
resultMap.put("return_code", "FAIL"); |
|
|
|
resultMap.put("return_msg", "FAILED"); |
|
|
|
return XmlUtil.getRequestXml(resultMap); |
|
|
|
} |
|
|
|
// @Override |
|
|
|
// public ResultData createSubsidy(MallUserInfo user, String ip, String amountStr) { |
|
|
|
// final IdWorker idWorker = IdWorker.get(); |
|
|
|
// EnumPayShare isShare = EnumPayShare.NO; |
|
|
|
// Date curDate = new Date(); |
|
|
|
// // 1. 获取c端小程序 |
|
|
|
// WxAppinfo appInfo = wxAppinfoService.getCAppInfo(user); |
|
|
|
// // 2. 获取payAccount |
|
|
|
// WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); |
|
|
|
// if (payAccount.checkShare()) { |
|
|
|
// isShare = EnumPayShare.YES; |
|
|
|
// } |
|
|
|
// // 3. 补贴订单 |
|
|
|
// BigDecimal amountY = new BigDecimal(amountStr); |
|
|
|
// int totalFee = amountY.multiply(new BigDecimal(100)).intValue(); // 元->分 |
|
|
|
// |
|
|
|
// Long id = idWorker.nextId(); |
|
|
|
// String payOrderNo = String.valueOf(id); |
|
|
|
// WxSubsidy record = new WxSubsidy(); |
|
|
|
// record.setId(id); |
|
|
|
// record.updateTenantInfo(user); |
|
|
|
// record.setOperatorUserId(user.getId()); |
|
|
|
// record.setCreateTime(curDate); |
|
|
|
// record.setUpdateTime(curDate); |
|
|
|
// record.setOrderNo(payOrderNo); |
|
|
|
// record.setBody("商场补贴-"+amountStr + "元"); |
|
|
|
// record.setIp(ip); |
|
|
|
// record.setStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); |
|
|
|
// record.setPayTimeStart(curDate); |
|
|
|
// record.setPayTimeEnd(curDate); |
|
|
|
// record.setAmount(totalFee); |
|
|
|
// // 分账金额 |
|
|
|
// int iChargeFee = PayUtils.getPayRate(record.getAmount(), payAccount.getRate(), false); |
|
|
|
// Integer share_amount = record.getAmount() - iChargeFee; |
|
|
|
// record.setShareAmount(share_amount); |
|
|
|
// record.setShareRemainAmount(share_amount); |
|
|
|
// try { |
|
|
|
// wxSubsidyMapper.insert(record); |
|
|
|
// } catch (Exception e) { |
|
|
|
// logger.error("wx_subsidy save fail" + e.getMessage()); |
|
|
|
// return new ResultData(ErrorCode.DB_FAIL); |
|
|
|
// } |
|
|
|
// // 3. 支付发起 |
|
|
|
// try { |
|
|
|
// // 统一下单 // 服务商模式 |
|
|
|
// String noncestr = Utility.generate32UUID(); |
|
|
|
// WxNativePayOrderSP payOrder = new WxNativePayOrderSP(); |
|
|
|
// payOrder.setAppid(appInfo.getParentAppId()); |
|
|
|
// payOrder.setSub_appid(appInfo.getAppId()); |
|
|
|
// payOrder.setMch_id(payAccount.getMchId()); |
|
|
|
// payOrder.setSub_mch_id(payAccount.getSubMchId()); |
|
|
|
// payOrder.setDevice_info("WEB"); |
|
|
|
// payOrder.setNonce_str(noncestr); |
|
|
|
// payOrder.setBody(record.getBody()); |
|
|
|
// payOrder.setOut_trade_no(record.getOrderNo()); |
|
|
|
// payOrder.setTotal_fee(record.getAmount()); |
|
|
|
// payOrder.setSpbill_create_ip(record.getIp()); |
|
|
|
// payOrder.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(curDate)); |
|
|
|
// Date futureDate = new Date(); |
|
|
|
// futureDate.setTime(curDate.getTime() + 15 * 60 * 1000); |
|
|
|
// payOrder.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 |
|
|
|
// payOrder.setNotify_url(payAccount.getSubsidyNotifyUrl()); |
|
|
|
// payOrder.setTrade_type("NATIVE"); |
|
|
|
// payOrder.setProduct_id(record.getOrderNo()); |
|
|
|
// payOrder.setSign_type("HMAC-SHA256"); |
|
|
|
// payOrder.setProfit_sharing(null); |
|
|
|
// if (isShare == EnumPayShare.YES) { |
|
|
|
// payOrder.setProfit_sharing("Y"); |
|
|
|
// } |
|
|
|
// Map<String, String> payOrderMap = BeanUtils.toStringMap(payOrder); |
|
|
|
// |
|
|
|
// payOrder.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); |
|
|
|
// String response = WxPay.pushOrder(BeanUtils.toStringMap(payOrder)); |
|
|
|
// logger.info("wx_subsidy wechat native Pay, " + payOrder.toString() + ", response: " + response.toString()); |
|
|
|
// Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
// String return_code = returnMap.get("return_code"); |
|
|
|
// String result_code = returnMap.get("result_code"); |
|
|
|
// if ("SUCCESS".equalsIgnoreCase(return_code)) { |
|
|
|
// if ("SUCCESS".equals(result_code)) { |
|
|
|
// String prepay_id = returnMap.get("prepay_id"); |
|
|
|
// String code_url = returnMap.get("code_url"); |
|
|
|
// // update payOrder with prepay_id |
|
|
|
// record.setPrepayId(prepay_id); |
|
|
|
// record.setCodeUrl(code_url); |
|
|
|
// record.setUpdateTime(new Date()); |
|
|
|
// try { |
|
|
|
// wxSubsidyMapper.updateById(record); |
|
|
|
// } catch (Exception e) { |
|
|
|
// logger.error("wx_subsidy update error: " + record.toString()); |
|
|
|
// throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
// } |
|
|
|
// |
|
|
|
// Map<String, String> retMap = new HashMap<String, String>(); |
|
|
|
// retMap.put("code_url", code_url); |
|
|
|
// return new ResultData(Result.SUCCESS, "创建支付订单成功", retMap); |
|
|
|
// } else { |
|
|
|
// String errMsg = ""; |
|
|
|
// JSONObject errObj = errorMap.getJSONObject(result_code); |
|
|
|
// if (errObj != null) { |
|
|
|
// errMsg = errObj.toJSONString(); |
|
|
|
// record.setFailReason(errMsg); |
|
|
|
// } else { |
|
|
|
// errMsg = returnMap.get("return_msg"); |
|
|
|
// record.setFailReason(errMsg); |
|
|
|
// } |
|
|
|
// record.setUpdateTime(new Date()); |
|
|
|
// try { |
|
|
|
// wxSubsidyMapper.updateById(record); |
|
|
|
// } catch (Exception e) { |
|
|
|
// logger.error("pay order update error: " + record.toString()); |
|
|
|
// throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
// } |
|
|
|
// return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// String errMsg = returnMap.get("return_msg"); |
|
|
|
// record.setFailReason(errMsg); |
|
|
|
// record.setUpdateTime(new Date()); |
|
|
|
// try { |
|
|
|
// wxSubsidyMapper.updateById(record); |
|
|
|
// } catch (Exception e) { |
|
|
|
// logger.error("pay order update error: " + record.toString()); |
|
|
|
// throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
// } |
|
|
|
// return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); |
|
|
|
// } |
|
|
|
// } catch (RuntimeException e) { |
|
|
|
// throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
// } catch (Exception e) { |
|
|
|
// throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// /** |
|
|
|
// * 提供微信支付回调调用 |
|
|
|
// * |
|
|
|
// * @param paramMap 异步通知参数 |
|
|
|
// * @param payWay 支付方式 |
|
|
|
// * @return |
|
|
|
// */ |
|
|
|
// @Override |
|
|
|
// public String notify(Map<String, String> paramMap, EnumPayWay payWay) { |
|
|
|
// // how to get wechatAppId, wechatMchId, partnerKey |
|
|
|
// String appId = paramMap.get("appid"); |
|
|
|
// String subAppId = paramMap.get("sub_appid"); |
|
|
|
// String mchId = paramMap.get("mch_id"); |
|
|
|
// String subMchId = paramMap.get("sub_mch_id"); |
|
|
|
// WxAppinfo appinfo = null; |
|
|
|
// boolean isNormal = true; |
|
|
|
// if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) { |
|
|
|
// // 普通商户号 |
|
|
|
// appinfo = wxAppinfoMapper.findByAppId(appId); |
|
|
|
// if (appinfo == null) { |
|
|
|
// logger.error("appid not found: " + appId); |
|
|
|
// throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
// } |
|
|
|
// isNormal = true; |
|
|
|
// } else { |
|
|
|
// // 服务号 现在用hmac-sha256 |
|
|
|
// appinfo = wxAppinfoMapper.findByAppId(subAppId); |
|
|
|
// if (appinfo == null) { |
|
|
|
// logger.error("subappid not found: " + subAppId); |
|
|
|
// throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
// } |
|
|
|
// isNormal = false; |
|
|
|
// } |
|
|
|
// |
|
|
|
// WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); |
|
|
|
// if (payAccount == null) { |
|
|
|
// throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND); |
|
|
|
// } |
|
|
|
// String partnerKey = payAccount.getApiKey(); |
|
|
|
// try { |
|
|
|
// if (payWay.getType() == EnumPayWay.EnumPayWayType.WX_MINIPAY) { |
|
|
|
// boolean signVerified = false; |
|
|
|
// if (isNormal) { |
|
|
|
// // 普通商户号支付 |
|
|
|
// signVerified = WxPayment.verifyNotify(paramMap, partnerKey); |
|
|
|
// if (!signVerified) { |
|
|
|
// logger.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
// throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// // 服务号 现在用hmac-sha256 |
|
|
|
// signVerified = WxPayment.verifyNotifyHMAC(paramMap, partnerKey); |
|
|
|
// if (!signVerified) { |
|
|
|
// logger.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
// throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// if (!"SUCCESS".equals(paramMap.get("return_code"))) { |
|
|
|
// logger.warn("notify order, wxpay status not success, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
// SortedMap resultMap = new TreeMap(); |
|
|
|
// resultMap.put("return_code", "FAIL"); |
|
|
|
// resultMap.put("return_msg", "订单状态码非SUCCESS"); |
|
|
|
// return XmlUtil.getRequestXml(resultMap); |
|
|
|
// } |
|
|
|
// |
|
|
|
// String payOrderNo = paramMap.get("out_trade_no"); |
|
|
|
// String transactionId = paramMap.get("transaction_id"); |
|
|
|
// String openId = paramMap.get("sub_openid"); |
|
|
|
// String timEndStr = paramMap.get("time_end"); |
|
|
|
// Long payOrderId = Long.valueOf(payOrderNo); |
|
|
|
// WxSubsidy subsidy = wxSubsidyMapper.selectById(payOrderId); |
|
|
|
// if (subsidy == null) { |
|
|
|
// logger.warn("notify order, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
// SortedMap resultMap = new TreeMap(); |
|
|
|
// resultMap.put("return_code", "FAIL"); |
|
|
|
// resultMap.put("return_msg", "订单不存在"); |
|
|
|
// return XmlUtil.getRequestXml(resultMap); |
|
|
|
// } |
|
|
|
// // 验证支付金额 |
|
|
|
// if (!paramMap.get("total_fee").equals(subsidy.getAmount().toString())) { |
|
|
|
// logger.warn("notify order, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
// SortedMap resultMap = new TreeMap(); |
|
|
|
// resultMap.put("return_code", "FAIL"); |
|
|
|
// resultMap.put("return_msg", "订单总金额不一致"); |
|
|
|
// return XmlUtil.getRequestXml(resultMap); |
|
|
|
// } |
|
|
|
// |
|
|
|
// Date timeEnd = null; |
|
|
|
// |
|
|
|
// try { |
|
|
|
// timeEnd = Utility.getDateFromString(timEndStr); |
|
|
|
// } catch (ParseException e) { |
|
|
|
// logger.error("解析timeEnd失败"); |
|
|
|
// timeEnd = new Date(); |
|
|
|
// } |
|
|
|
// subsidy.setPayTimeEnd(timeEnd); |
|
|
|
// subsidy.setTransactionId(transactionId); |
|
|
|
// subsidy.setStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); |
|
|
|
// subsidy.setOpenId(openId); |
|
|
|
// subsidy.setUpdateTime(new Date()); |
|
|
|
// try { |
|
|
|
// wxSubsidyMapper.updateById(subsidy); |
|
|
|
// } catch (Exception e) { |
|
|
|
// logger.error("wx_subsidy update exception"); |
|
|
|
// } |
|
|
|
// logger.info("notify order, wxpay checksign success, paramMap:{}, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
|
// SortedMap resultMap = new TreeMap(); |
|
|
|
// resultMap.put("return_code", "SUCCESS"); |
|
|
|
// resultMap.put("return_msg", "OK"); |
|
|
|
// return XmlUtil.getRequestXml(resultMap); |
|
|
|
// } |
|
|
|
// } catch (RuntimeException e) { |
|
|
|
// logger.warn("notify order, checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString() + ", e:" + e.getMessage()); |
|
|
|
// throw new MallinkException(ErrorCode.PAY_ORDER_ERROR); |
|
|
|
// } |
|
|
|
// |
|
|
|
// SortedMap resultMap = new TreeMap(); |
|
|
|
// resultMap.put("return_code", "FAIL"); |
|
|
|
// resultMap.put("return_msg", "FAILED"); |
|
|
|
// return XmlUtil.getRequestXml(resultMap); |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|