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