支付宝App支付V2.0交易结果通知接口
@RequestMapping(value = "/yunpay/app/aliPayAppPayV2Notify", method = RequestMethod.POST) public void aliPayAppPayV2Notify(HttpServletRequest req, HttpServletResponse resp) { LOGGER.info("支付宝app(钱包)支付V2.0->交易结果通知->开始"); long start = System.currentTimeMillis(); dealWhitAliPayAppV2Req(req, resp, "aliPayAppPayV2Notify", ALIPAY_APPPAY_V2_KEY); long end = System.currentTimeMillis(); LOGGER.info("支付宝app(钱包)支付V2.0->交易结果通知->结束,耗时:{}", end - start); }
private void dealWhitAliPayAppV2Req(HttpServletRequest req, HttpServletResponse resp, String transCode, String redisKey) { /* 编码格式 */ String charset = req.getCharacterEncoding(); if (StringUtil.isEmpty(charset)) { charset = CHARSET; } String merNo = ""; Map<String, Object> jsonParams = getJsonParams(req); if (null == jsonParams) { LOGGER.error("支付宝手机app(钱包)支付V2->钱包支付结果异步通知->请求报文为空"); return; } LOGGER.info("支付宝手机app(钱包)支付V2->钱包支付结果异步通知->请求数据:{}", jsonParams);
//读取惠付发往通道订单号 merNo = jsonParams.get(AliPayV2CommonConstans.APP_ID).toString(); JSONObject secureFld = null; try { //截取通道商户号//读取安全域 Map<String, String> secureFldMap = redisInstance.getObj(HashMap.class, redisKey); String secureFldStr = secureFldMap.get(merNo); secureFld = JSONObject.parseObject(secureFldStr); } catch (Exception e) { LOGGER.error("支付宝手机app(钱包)支付V2->钱包支付结果异步通知->安全域读取失败或解析失败:{}", e); return; } if (secureFld == null) { LOGGER.error("支付宝手机app(钱包)支付V2->钱包支付结果异步通知->安全域读取失败或解析失败"); return; } try { LOGGER.info("请求客户端地址:{}", HttpUtils.getReqIPAddr(req)); //验签 调用支付宝SDK boolean signVerify = false; if (alipayV2Flag) { signVerify = true; } else { signVerify = AlipaySignature.rsaCheckV1(jsonParams, secureFld.getString(AliPayV2CommonConstans.ALIPAY_PUBLIC_KEY), charset, AliPayV2CommonConstans.SIGN_TYPE_RSA2); } if (signVerify) { //验签成功后对比交易请求的金额与异步返回是否一致 String total_amount = secureFld.getString(AliPayV2CommonConstans.TOTAL_AMOUNT);//支付金额 String returnAmout = jsonParams.get(AliPayV2CommonConstans.TOTAL_AMOUNT).toString();//返回金额 if (!StringUtil.equals(total_amount, returnAmout)){ LOGGER.error("支付宝APP支付V2->APP支付结果异步通知->支付与返回的交易金额不一致"); return; } IYunPayGateWayService notifyService = yunPayGateWayServiceFactory.getServiceByServiceName(transCode); notifyService.execute(jsonParams); writeToResp(resp, AliPayV2CommonConstans.SUCCESS); } else { LOGGER.error("异步通知异常:{}", "验签失败"); throw new SanxiaPayBizException(EnumRespMsg.VERIFY_FAILED.getRespCode(), EnumRespMsg.VERIFY_FAILED.getRespMsg()); } } catch (Exception e) { LOGGER.error("异步通知异常:{}", e); } }
private Map<String, Object> getJsonParams(HttpServletRequest req) {
Map<String, Object> jsonParams = new HashMap<>();
Enumeration
原文地址: https://www.cveoy.top/t/topic/pT0W 著作权归作者所有。请勿转载和采集!