支付调整

This commit is contained in:
GYJ
2024-08-01 11:00:31 +08:00
parent e991681f8d
commit ff9623fe8e
6 changed files with 253 additions and 24 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/target/ /target/
/logs/

View File

@@ -2,6 +2,7 @@ package com.sqx.modules.pay.controller;
import com.sqx.common.utils.Result; import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login; import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.common.service.CommonInfoService;
import com.sqx.modules.yskPay.resp.PublicResp; import com.sqx.modules.yskPay.resp.PublicResp;
import com.sqx.modules.yskPay.resp.WxScanPayResp; import com.sqx.modules.yskPay.resp.WxScanPayResp;
import com.sqx.modules.yskPay.service.ThirdPayService; import com.sqx.modules.yskPay.service.ThirdPayService;
@@ -25,22 +26,30 @@ import java.math.BigDecimal;
public class ThirdPayController { public class ThirdPayController {
final private ThirdPayService thirdPayService; final private ThirdPayService thirdPayService;
public ThirdPayController(ThirdPayService thirdPayService) { private final CommonInfoService commonRepository;
public ThirdPayController(ThirdPayService thirdPayService, CommonInfoService commonRepository) {
this.thirdPayService = thirdPayService; this.thirdPayService = thirdPayService;
this.commonRepository = commonRepository;
} }
// @Login // @Login
@ApiOperation("微信支付宝支付订单") @ApiOperation("微信支付宝支付订单")
@PostMapping("/wxPayJsApiOrder") @PostMapping("/wxPayJsApiOrder")
// public Result wxPayJsApiOrder(@RequestAttribute("userId") Long userId, Long parentId, Integer type, Long addressId, Integer orderType) throws Exception { public Result wxPayJsApiOrder(@RequestAttribute("userId") Long userId, Long parentId, Integer type, Long addressId, Integer orderType) throws Exception {
public Result wxPayJsApiOrder() { // public Result wxPayJsApiOrder() {
PublicResp<WxScanPayResp> scanpay = thirdPayService.scanpay("https://paymentapi.sxczgkj.cn", "66691a6afdf641f0bf1dc701", String thirdPayUrl = commonRepository.findOne(421).getValue();
String thirdUserAppId = commonRepository.findOne(422).getValue();
String thirdUserStoreId = commonRepository.findOne(424).getValue();
String thirdUserKey = commonRepository.findOne(423).getValue();
String userWxAppId = commonRepository.findOne(45).getValue();
PublicResp<WxScanPayResp> scanpay = thirdPayService.scanpay(thirdPayUrl, thirdUserAppId,
"外卖订单", "外卖订单", 1L, "外卖订单", "外卖订单", 1L,
"WECHAT", "wxd88fffa983758a30", "or1l869Gqm3jUeqbmuL1TFKK4XrM", "1.80.169.5", "WECHAT", userWxAppId, "o5Fun5ff9AWRjL2K0_sRTjMJHCPQ", "1.80.169.5",
"202407310944110001", "S2406120331", "202407310944110003", thirdUserStoreId,
"https://paymentapi.sxczgkj.cn", null, "https://paymentapi.sxczgkj.cn", null, thirdUserKey);
"jikd52TefZcSPI5hRWrfPSpQcXZrbqshbnLmqH6UattqspIDEzjbGvZmfwTW58RMf1XuPhN4zE1GbIjKy3b1oabgOx5n79faT93Si6i7g2IPSQJAln2NNsCSNynHIJ8p");
System.out.println(scanpay); System.out.println(scanpay);

View File

@@ -1,9 +1,14 @@
package com.sqx.modules.pay.controller.app; package com.sqx.modules.pay.controller.app;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.sqx.common.utils.Result; import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login; import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.pay.dao.PayDetailsDao; import com.sqx.modules.pay.dao.PayDetailsDao;
import com.sqx.modules.pay.service.WxService; import com.sqx.modules.pay.service.WxService;
import com.sqx.modules.yskPay.utils.RequestWrapper;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -19,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Map;
/** /**
* @author fang * @author fang
@@ -93,6 +99,22 @@ public class ApiWeiXinPayController {
return notify(2,request); return notify(2,request);
} }
@PostMapping("/thirdPayNotify")
@ApiOperation("用户端支付回调")
public String thirdPayNotify(HttpServletRequest request) {
Map<String, Object> map = getParameterMap(request);
log.info("支付回调返回信息:{}", JSONUtil.toJsonStr(map));
if (map != null && !map.isEmpty() && map.containsKey("code") && "000000".equals(map.get("code") + "")) {
JSONObject object = JSONUtil.parseObj(map.get("bizData"));
if (object.containsKey("state") && "TRADE_SUCCESS".equals(object.getStr("state"))) {
// String tradeNo=object.get("payOrderId").toString();
String orderNo = object.getStr("mchOrderNo");
return wxService.thirdPayBack(orderNo);
}
}
return null;
}
@PostMapping("/notifyShop") @PostMapping("/notifyShop")
@ApiOperation("商户端app微信回调") @ApiOperation("商户端app微信回调")
public String notifyShop(HttpServletRequest request) { public String notifyShop(HttpServletRequest request) {
@@ -184,4 +206,16 @@ public class ApiWeiXinPayController {
} }
} }
private Map getParameterMap(HttpServletRequest request) {
RequestWrapper requestWrapper = new RequestWrapper(request);
String body = requestWrapper.getBody();
if (StrUtil.isNotEmpty(body)) {
return JSONUtil.toBean(body, Map.class);
}else {
Map<String, String[]> parameterMap = request.getParameterMap();
return parameterMap;
}
}
} }

View File

@@ -20,6 +20,8 @@ public interface WxService {
String payBackShop(String resXml, Integer type); String payBackShop(String resXml, Integer type);
String thirdPayBack(String orderNo);
boolean wxRefund(PayDetails payDetails); boolean wxRefund(PayDetails payDetails);
Result balanceOrder(Long userId,Long parentId, Integer orderType, Long addressId); Result balanceOrder(Long userId,Long parentId, Integer orderType, Long addressId);

View File

@@ -1,7 +1,9 @@
package com.sqx.modules.pay.service.impl; package com.sqx.modules.pay.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.wxpay.sdk.WXPay; import com.github.wxpay.sdk.WXPay;
import com.github.wxpay.sdk.WXPayConstants; import com.github.wxpay.sdk.WXPayConstants;
import com.github.wxpay.sdk.WXPayUtil; import com.github.wxpay.sdk.WXPayUtil;
@@ -50,6 +52,9 @@ import com.sqx.modules.utils.AmountCalUtils;
import com.sqx.modules.utils.MD5Util; import com.sqx.modules.utils.MD5Util;
import com.sqx.modules.utils.SenInfoCheckUtil; import com.sqx.modules.utils.SenInfoCheckUtil;
import com.sqx.modules.utils.WXConfigUtil; import com.sqx.modules.utils.WXConfigUtil;
import com.sqx.modules.yskPay.resp.PublicResp;
import com.sqx.modules.yskPay.resp.WxScanPayResp;
import com.sqx.modules.yskPay.service.ThirdPayService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.gavaghan.geodesy.Ellipsoid; import org.gavaghan.geodesy.Ellipsoid;
@@ -126,6 +131,9 @@ public class WxServiceImpl implements WxService {
@Autowired @Autowired
private ShopMessageService shopMessageService; private ShopMessageService shopMessageService;
@Autowired
private ThirdPayService thirdPayService;
private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(true); private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(true);
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -426,7 +434,7 @@ public class WxServiceImpl implements WxService {
if (type == 4 || type == 5) { if (type == 4 || type == 5) {
return aliPayController.payVip(Double.valueOf(one.getValue()), type, userId, generalOrder, 4); return aliPayController.payVip(Double.valueOf(one.getValue()), type, userId, generalOrder, 4);
} }
return pay(Double.valueOf(one.getValue()), type, userId, generalOrder, 4); return pay2(Double.valueOf(one.getValue()), type, userId, generalOrder, 4);
} }
@Transactional @Transactional
@@ -474,7 +482,7 @@ public class WxServiceImpl implements WxService {
if (type == 4 || type == 5) { if (type == 4 || type == 5) {
return aliPayController.aliPayMoney(money.doubleValue(), type, userId, generalOrder, 2); return aliPayController.aliPayMoney(money.doubleValue(), type, userId, generalOrder, 2);
} }
return pay(money.doubleValue(), type, userId, generalOrder, 2); return pay2(money.doubleValue(), type, userId, generalOrder, 2);
} }
@Override @Override
@@ -597,20 +605,97 @@ public class WxServiceImpl implements WxService {
return aliPayController.payAppOrders(payMoney.doubleValue(), type, tbOrder2.getUserId(), generalOrder, 1); return aliPayController.payAppOrders(payMoney.doubleValue(), type, tbOrder2.getUserId(), generalOrder, 1);
} }
appOrderDao.updateById(tbOrder1); appOrderDao.updateById(tbOrder1);
return pay(payMoney.doubleValue(), type, tbOrder2.getUserId(), generalOrder, 1); return pay2(payMoney.doubleValue(), type, tbOrder2.getUserId(), generalOrder, 1);
} }
/** private Result pay2(Double moneys, Integer type, Long userId, String outTradeNo, Integer classify) throws Exception {
* 微信支付订单生成 //h5服务域名配置
* CommonInfo oneu = commonInfoService.findOne(19);
* @param moneys 支付金额 带小数点
* @param type 类型 1app 2 二维码支付 3小程序 公众号支付 String notifyUrl = oneu.getValue() + "/sqx_fast/app/wxPay/thirdPayNotify";
* @param userId 用户id
* @param outTradeNo 单号 String body = "";
* @param classify 支付类型 1支付订单 2充值 if (classify == 1) {
* @return //订单类型
* @throws Exception body = "下单支付";
*/ } else if (classify == 2) {
body = "充值余额";
} else if (classify == 4) {
body = "购买会员";
}
Double mul = AmountCalUtils.mul(moneys, 100);
String openId;
UserEntity userEntity = userService.queryByUserId(userId);
if (type == 2) {
openId = userEntity.getWxOpenId();
} else {
openId = userEntity.getOpenId();
}
String thirdPayUrl = commonInfoService.findOne(421).getValue();
String thirdUserAppId = commonInfoService.findOne(422).getValue();
String thirdUserStoreId = commonInfoService.findOne(424).getValue();
String thirdUserKey = commonInfoService.findOne(423).getValue();
String userWxAppId = commonInfoService.findOne(45).getValue();
PublicResp<WxScanPayResp> scanpay = thirdPayService.scanpay(thirdPayUrl, thirdUserAppId,
body, body, mul.longValue(),
"WECHAT", userWxAppId, openId, "127.0.0.1",
outTradeNo, thirdUserStoreId,
notifyUrl, null, thirdUserKey);
if (scanpay != null) {
if ("000000".equals(scanpay.getCode())) {
WxScanPayResp wxScanPayResp = scanpay.getObjData();
if ("TRADE_AWAIT".equals(wxScanPayResp.getState())) {
PayDetails payDetails = payDetailsDao.selectByOrderId(outTradeNo);
if (payDetails == null) {
String money = String.valueOf(mul.intValue());
payDetails = new PayDetails();
payDetails.setState(0);
payDetails.setCreateTime(sdf.format(new Date()));
payDetails.setOrderId(outTradeNo);
payDetails.setUserId(userId);
payDetails.setMoney(AmountCalUtils.divide(Double.parseDouble(money), 100));
payDetails.setClassify(classify);
payDetails.setType(type);
payDetailsDao.insert(payDetails);
}
String payInfo = wxScanPayResp.getPayInfo();
JSONObject jsonObj = JSONObject.parseObject(payInfo);
Map<String, String> param = new HashMap<>();
param.put("appid", jsonObj.getString("appid"));
param.put("partnerid", "");
param.put("prepayid", "");
param.put("package", jsonObj.getString("package"));
param.put("noncestr", jsonObj.getString("nonceStr"));
param.put("timestamp", jsonObj.getString("timeStamp"));
param.put("sign", jsonObj.getString("paySign"));
param.put("outtradeno", jsonObj.getString("tradeNo"));
param.put("signType", jsonObj.getString("signType"));
return Result.success().put("data", param);
} else {
return Result.error(scanpay.getMsg());
}
}
}
return Result.error("支付失败");
}
/**
* 微信支付订单生成
*
* @param moneys 支付金额 带小数点
* @param type 类型 1app 2 二维码支付 3小程序 公众号支付
* @param userId 用户id
* @param outTradeNo 单号
* @param classify 支付类型 1支付订单 2充值
* @return
* @throws Exception
*/
private Result pay(Double moneys, Integer type, Long userId, String outTradeNo, Integer classify) throws Exception { private Result pay(Double moneys, Integer type, Long userId, String outTradeNo, Integer classify) throws Exception {
//h5服务域名配置 //h5服务域名配置
CommonInfo oneu = commonInfoService.findOne(19); CommonInfo oneu = commonInfoService.findOne(19);
@@ -996,6 +1081,20 @@ public class WxServiceImpl implements WxService {
return xmlBack; return xmlBack;
} }
@Override
public String thirdPayBack(String orderNo) {
PayDetails payDetails = payDetailsDao.selectByOrderId(orderNo);
//设置查询条件
if (payDetails.getState() == 0) {
payDetailsDao.updateState(payDetails.getId(), 1, sdf.format(new Date()), "");
//调用处理接口
//业务操作
notfiy(payDetails);
}
return "SUCCESS";
}
public String getGeneralOrder() { public String getGeneralOrder() {
Date date = new Date(); Date date = new Date();

View File

@@ -0,0 +1,84 @@
package com.sqx.modules.yskPay.utils;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.*;
public class RequestWrapper extends HttpServletRequestWrapper {
private final String body;
public RequestWrapper(HttpServletRequest request) {
super(request);
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = null;
InputStream inputStream = null;
try {
inputStream = request.getInputStream();
if (inputStream != null) {
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
char[] charBuffer = new char[128];
int bytesRead = -1;
while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
stringBuilder.append(charBuffer, 0, bytesRead);
}
} else {
stringBuilder.append("");
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
if (bufferedReader != null) {
try {
bufferedReader.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
body = stringBuilder.toString();
}
@Override
public ServletInputStream getInputStream() throws IOException {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
ServletInputStream servletInputStream = new ServletInputStream() {
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
@Override
public int read() throws IOException {
return byteArrayInputStream.read();
}
};
return servletInputStream;
}
@Override
public BufferedReader getReader() throws IOException {
return new BufferedReader(new InputStreamReader(this.getInputStream()));
}
public String getBody() {
return this.body;
}
}