xiaohanzi 5 лет назад
Родитель
Сommit
371492a9a3
4 измененных файлов: 337 добавлений и 337 удалений
  1. +23
    -23
      mallinkAdmin/src/main/java/com/iformall/controller/market/WxSubsidyController.java
  2. +57
    -57
      mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java
  3. +2
    -2
      mallinkService/src/main/java/com/iformall/service/WxSubsidyService.java
  4. +255
    -255
      mallinkService/src/main/java/com/iformall/service/impl/WxSubsidyServiceImpl.java

+ 23
- 23
mallinkAdmin/src/main/java/com/iformall/controller/market/WxSubsidyController.java Просмотреть файл

@@ -35,29 +35,29 @@ public class WxSubsidyController extends BaseController {
@Autowired
private WxSubsidyService wxSubsidyService;

@ApiOperation("补贴扫码支付发起")
@GetMapping("prePay")
@ApiImplicitParams({
@ApiImplicitParam(name = "amount", value = "金额", dataType = "String", paramType = "query", required = true)})
@SystemControllerLog(description = "商城补贴-补贴扫码支付发起")
public void subsidyPrepay(String amount, HttpServletResponse response) throws Exception {
String ipStr = getIpAddr();
logger.info("subsidyPrepay: " + ipStr + "-" + amount);
MallUserInfo userInfo = getUser();
ResultData resultData = wxSubsidyService.createSubsidy(userInfo, ipStr, amount);
if (resultData.code == 200) {
String codeUrl = ((Map<String, String>) resultData.data).get("code_url");
BufferedImage image = PayUtil.getQRCodeImge(codeUrl);
response.setContentType("image/jpeg");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setIntHeader("Expires", -1);
ImageIO.write(image, "JPEG", response.getOutputStream());
} else {
throw new MallinkException(resultData.code, resultData.message);
}
}
// @ApiOperation("补贴扫码支付发起")
// @GetMapping("prePay")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "amount", value = "金额", dataType = "String", paramType = "query", required = true)})
// @SystemControllerLog(description = "商城补贴-补贴扫码支付发起")
// public void subsidyPrepay(String amount, HttpServletResponse response) throws Exception {
// String ipStr = getIpAddr();
// logger.info("subsidyPrepay: " + ipStr + "-" + amount);
// MallUserInfo userInfo = getUser();
// ResultData resultData = wxSubsidyService.createSubsidy(userInfo, ipStr, amount);
// if (resultData.code == 200) {
// String codeUrl = ((Map<String, String>) resultData.data).get("code_url");
// BufferedImage image = PayUtil.getQRCodeImge(codeUrl);
//
// response.setContentType("image/jpeg");
// response.setHeader("Pragma", "no-cache");
// response.setHeader("Cache-Control", "no-cache");
// response.setIntHeader("Expires", -1);
// ImageIO.write(image, "JPEG", response.getOutputStream());
// } else {
// throw new MallinkException(resultData.code, resultData.message);
// }
// }

@ApiOperation("分页列表接口")
@GetMapping("list")


+ 57
- 57
mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java Просмотреть файл

@@ -209,62 +209,62 @@ public class WxPayController extends BaseController {
* @return 接收微信异步通知
* @throws Exception 可能产生的任何异常
*/
@RequestMapping(value = "/subsidyPay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public String _subsidyPayNotify(HttpServletRequest request) throws IOException, JDOMException {
logger.info("[" +getIpAddr() + "] 补贴微信支付回调");
InputStream inStream = request.getInputStream();
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outSteam.write(buffer, 0, len);
}
String resultxml = new String(outSteam.toByteArray(), Charset.forName("UTF-8"));
logger.info(resultxml);
outSteam.close();
inStream.close();
Map<String, String> paramMap = null;
try {
paramMap = WxPayment.xmlToMap(resultxml);
logger.info("微信支付回调, notify, param: " + paramMap.toString() );
String response = wxSubsidyService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT);
logger.info("微信支付回调, notify success, req : " + resultxml + ", resp: " + response.toString());
return response;
} catch (BizMessageException e) {
if (paramMap == null) {
logger.error("微信支付回调, order create error, e: " + e.getMessage());
} else {
logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage());
}
SortedMap resultMap = new TreeMap<>();
resultMap.put("return_code", "FAIL");
resultMap.put("return_msg", e.getMessage());
return XmlUtil.getRequestXml(resultMap);
} catch (MallinkException e) {
if (paramMap == null) {
logger.error("微信支付回调, order create error, e: " + e.getMessage());
} else {
logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage());
}
SortedMap resultMap = new TreeMap<>();
resultMap.put("return_code", "FAIL");
resultMap.put("return_msg", e.getMessage());
return XmlUtil.getRequestXml(resultMap);
} catch (Exception e) {
if (paramMap == null) {
logger.error("微信支付回调, order create error, e: " + e.getMessage());
} else {
logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage());
}
SortedMap resultMap = new TreeMap();
resultMap.put("return_code", "FAIL");
resultMap.put("return_msg", e.getMessage());
return XmlUtil.getRequestXml(resultMap);
}
}
// @RequestMapping(value = "/subsidyPay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
// @ResponseBody
// public String _subsidyPayNotify(HttpServletRequest request) throws IOException, JDOMException {
// logger.info("[" +getIpAddr() + "] 补贴微信支付回调");
// InputStream inStream = request.getInputStream();
// ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
// byte[] buffer = new byte[1024];
// int len = 0;
// while ((len = inStream.read(buffer)) != -1) {
// outSteam.write(buffer, 0, len);
// }
// String resultxml = new String(outSteam.toByteArray(), Charset.forName("UTF-8"));
// logger.info(resultxml);
//
// outSteam.close();
// inStream.close();
//
// Map<String, String> paramMap = null;
//
// try {
// paramMap = WxPayment.xmlToMap(resultxml);
// logger.info("微信支付回调, notify, param: " + paramMap.toString() );
// String response = wxSubsidyService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT);
// logger.info("微信支付回调, notify success, req : " + resultxml + ", resp: " + response.toString());
// return response;
// } catch (BizMessageException e) {
// if (paramMap == null) {
// logger.error("微信支付回调, order create error, e: " + e.getMessage());
// } else {
// logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage());
// }
// SortedMap resultMap = new TreeMap<>();
// resultMap.put("return_code", "FAIL");
// resultMap.put("return_msg", e.getMessage());
// return XmlUtil.getRequestXml(resultMap);
// } catch (MallinkException e) {
// if (paramMap == null) {
// logger.error("微信支付回调, order create error, e: " + e.getMessage());
// } else {
// logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage());
// }
// SortedMap resultMap = new TreeMap<>();
// resultMap.put("return_code", "FAIL");
// resultMap.put("return_msg", e.getMessage());
// return XmlUtil.getRequestXml(resultMap);
// } catch (Exception e) {
// if (paramMap == null) {
// logger.error("微信支付回调, order create error, e: " + e.getMessage());
// } else {
// logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage());
// }
// SortedMap resultMap = new TreeMap();
// resultMap.put("return_code", "FAIL");
// resultMap.put("return_msg", e.getMessage());
// return XmlUtil.getRequestXml(resultMap);
// }
// }
}

+ 2
- 2
mallinkService/src/main/java/com/iformall/service/WxSubsidyService.java Просмотреть файл

@@ -15,7 +15,7 @@ public interface WxSubsidyService {
* @param amountStr
* @return
*/
ResultData createSubsidy(MallUserInfo user, String ip, String amountStr);
//ResultData createSubsidy(MallUserInfo user, String ip, String amountStr);

/**
* 根据实体查询分页列表
@@ -49,7 +49,7 @@ public interface WxSubsidyService {
*/
void deleteById(Long id);

String notify(Map<String, String> paramMap, EnumPayWay payWay);
//String notify(Map<String, String> paramMap, EnumPayWay payWay);


+ 255
- 255
mallinkService/src/main/java/com/iformall/service/impl/WxSubsidyServiceImpl.java Просмотреть файл

@@ -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


Загрузка…
Отмена
Сохранить