支付回调
This commit is contained in:
parent
f204e0d54b
commit
38419d2524
|
|
@ -1,7 +1,9 @@
|
|||
package com.mdd.front.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.entity.RechargeOrder;
|
||||
|
|
@ -12,14 +14,13 @@ import com.mdd.front.LikeFrontThreadLocal;
|
|||
import com.mdd.front.service.IPayService;
|
||||
import com.mdd.front.validate.PaymentValidate;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.models.auth.In;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/pay")
|
||||
|
|
@ -32,6 +33,11 @@ public class PayController {
|
|||
@Resource
|
||||
IPayService iPayService;
|
||||
|
||||
@GetMapping("/payWay")
|
||||
public AjaxResult<Object> payWay() {
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 预支付
|
||||
*
|
||||
|
|
@ -40,7 +46,7 @@ public class PayController {
|
|||
@PostMapping("/prepay")
|
||||
public AjaxResult<Object> prepay(@Validated @RequestBody PaymentValidate paymentValidate) {
|
||||
String scene = paymentValidate.getScene();
|
||||
int payWay = paymentValidate.getPayWay();
|
||||
Integer payWay = paymentValidate.getPayWay();
|
||||
Integer orderId = paymentValidate.getOrderId();
|
||||
Integer terminal = LikeFrontThreadLocal.getTerminal();
|
||||
|
||||
|
|
@ -73,13 +79,13 @@ public class PayController {
|
|||
|
||||
// 发起支付
|
||||
try {
|
||||
if (payWay == PaymentEnum.WALLET_PAY.getCode()) {
|
||||
switch (payWay) {
|
||||
case 1: // 余额支付
|
||||
iPayService.walletPay();
|
||||
} else if (payWay == PaymentEnum.WX_PAY.getCode()) {
|
||||
break;
|
||||
case 2: // 微信支付
|
||||
WxPayUnifiedOrderV3Result.JsapiResult result = iPayService.wxPay(paymentValidate, terminal);
|
||||
return AjaxResult.success(result);
|
||||
} else if (payWay == PaymentEnum.ALI_PAY.getCode()) {
|
||||
iPayService.aliPay();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new OperateException(e.getMessage());
|
||||
|
|
@ -95,8 +101,30 @@ public class PayController {
|
|||
*/
|
||||
@NotLogin
|
||||
@PostMapping("/notifyMnp")
|
||||
public AjaxResult<Object> notifyMnp() {
|
||||
public AjaxResult<Object> notifyMnp(@RequestBody String jsonData, HttpServletRequest request) throws WxPayException {
|
||||
SignatureHeader signatureHeader = this.getWxRequestHeader(request);
|
||||
iPayService.handlePaidNotify(jsonData, signatureHeader);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信支付回调签名相关
|
||||
*
|
||||
* @param request HttpServletRequest
|
||||
* @return SignatureHeader
|
||||
*/
|
||||
private SignatureHeader getWxRequestHeader(HttpServletRequest request) {
|
||||
String signature = request.getHeader("wechatpay-signature");
|
||||
String nonce = request.getHeader("wechatpay-nonce");
|
||||
String serial = request.getHeader("wechatpay-serial");
|
||||
String timestamp = request.getHeader("wechatpay-timestamp");
|
||||
|
||||
SignatureHeader signatureHeader = new SignatureHeader();
|
||||
signatureHeader.setSignature(signature);
|
||||
signatureHeader.setNonce(nonce);
|
||||
signatureHeader.setSerial(serial);
|
||||
signatureHeader.setTimeStamp(timestamp);
|
||||
return signatureHeader;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.mdd.front.service;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.mdd.front.validate.PaymentValidate;
|
||||
|
||||
/**
|
||||
|
|
@ -8,12 +10,27 @@ import com.mdd.front.validate.PaymentValidate;
|
|||
*/
|
||||
public interface IPayService {
|
||||
|
||||
/**
|
||||
* 余额支付
|
||||
*/
|
||||
void walletPay();
|
||||
|
||||
/**
|
||||
* 微信支付
|
||||
*
|
||||
* @param params 参数
|
||||
* @param terminal 终端
|
||||
* @return WxPayUnifiedOrderV3Result.JsapiResult
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
WxPayUnifiedOrderV3Result.JsapiResult wxPay(PaymentValidate params, Integer terminal) throws Exception;
|
||||
|
||||
void aliPay();
|
||||
|
||||
void handlePaidNotify();
|
||||
/**
|
||||
* 支付回调处理
|
||||
*
|
||||
* @param jsonData 回调数据
|
||||
* @param signatureHeader 请求头
|
||||
*/
|
||||
void handlePaidNotify(String jsonData, SignatureHeader signatureHeader) throws WxPayException;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
package com.mdd.front.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
|
||||
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result;
|
||||
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
|
||||
import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.mdd.common.entity.user.UserAuth;
|
||||
import com.mdd.common.enums.ClientEnum;
|
||||
|
|
@ -15,12 +18,14 @@ import com.mdd.common.util.RequestUtils;
|
|||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.front.service.IPayService;
|
||||
import com.mdd.front.validate.PaymentValidate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PayServiceImpl implements IPayService {
|
||||
|
||||
|
|
@ -56,7 +61,7 @@ public class PayServiceImpl implements IPayService {
|
|||
.eq("user_id", userId)
|
||||
.eq("terminal", terminal)
|
||||
.last("limit 1"));
|
||||
System.out.println(userAuth);
|
||||
|
||||
if (StringUtils.isNotNull(userAuth)) {
|
||||
openId = userAuth.getOpenid();
|
||||
}
|
||||
|
|
@ -97,23 +102,28 @@ public class PayServiceImpl implements IPayService {
|
|||
// 发起订单
|
||||
WxPayService wxPayService = WxPayDriver.handler(terminal);
|
||||
wxPayUnifiedOrderV3Request.setPayer(payer);
|
||||
WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = wxPayService.createOrderV3(TradeTypeEnum.JSAPI, wxPayUnifiedOrderV3Request);
|
||||
return jsapiResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝支付
|
||||
*/
|
||||
@Override
|
||||
public void aliPay() {
|
||||
|
||||
return wxPayService.createOrderV3(TradeTypeEnum.JSAPI, wxPayUnifiedOrderV3Request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付回调处理
|
||||
*/
|
||||
public void handlePaidNotify() {
|
||||
public void handlePaidNotify(String jsonData, SignatureHeader signatureHeader) throws WxPayException {
|
||||
log.info("微信传来的json-------");
|
||||
log.info(jsonData);
|
||||
log.info("signatureHeader------------");
|
||||
log.info(signatureHeader.toString());
|
||||
|
||||
WxPayService wxPayService = WxPayDriver.handler(ClientEnum.MNP.getCode());
|
||||
WxPayOrderNotifyV3Result.DecryptNotifyResult notifyResult = wxPayService.parseOrderNotifyV3Result(jsonData, signatureHeader).getResult();
|
||||
|
||||
String transactionId = notifyResult.getTransactionId();
|
||||
String outTradeNo = notifyResult.getOutTradeNo();
|
||||
|
||||
log.info("transactionId-------");
|
||||
log.info(transactionId);
|
||||
log.info("outTradeNo-------");
|
||||
log.info(outTradeNo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue