fix
This commit is contained in:
@@ -82,13 +82,11 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
||||
protected void doFilterInternal(@NotNull HttpServletRequest httpServletRequest, @NotNull HttpServletResponse httpServletResponse, @NotNull FilterChain filterChain) throws ServletException, IOException {
|
||||
log.info("url = {}", httpServletRequest.getRequestURI());
|
||||
|
||||
// //微信支付回调接口,不需要验证
|
||||
//微信支付回调接口,不需要验证
|
||||
if ("/wx/pay/jsCallback".equals(httpServletRequest.getServletPath())) {
|
||||
log.info("微信支付回调,不需要验证");
|
||||
filterChain.doFilter(httpServletRequest, httpServletResponse);
|
||||
return;
|
||||
}
|
||||
|
||||
// 微信公众号的请求,必须存在tenantkey,否则抛出异常
|
||||
} else {// 微信公众号的请求,必须存在tenantkey,否则抛出异常
|
||||
if (httpServletRequest.getServletPath().startsWith("/wx/")) {
|
||||
|
||||
String tenantKey = httpServletRequest.getHeader("tenantkey");
|
||||
@@ -152,6 +150,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
||||
}
|
||||
}
|
||||
filterChain.doFilter(httpServletRequest, httpServletResponse);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public class PlayOrderInfoEntity extends BaseEntity<PlayOrderInfoEntity> {
|
||||
private String payMethod;
|
||||
|
||||
/**
|
||||
* 支付状态,[-1:支付失败,0:未支付;1:支付中;2:支付完成]
|
||||
* 支付状态,[-1:支付失败,0:未支付;1:支付完成]
|
||||
*/
|
||||
private String payState;
|
||||
|
||||
|
||||
@@ -279,6 +279,14 @@ public interface IPlayOrderInfoService extends IService<PlayOrderInfoEntity> {
|
||||
*/
|
||||
int deleteOrderInfoByIds(String[] ids);
|
||||
|
||||
/**
|
||||
* 根据订单编号查询订单信息
|
||||
*
|
||||
* @param orderNo 订单编号
|
||||
* @return 订单信息
|
||||
*/
|
||||
PlayOrderInfoEntity queryByOrderNo(String orderNo);
|
||||
|
||||
/**
|
||||
* 删除订单信息
|
||||
*
|
||||
|
||||
@@ -290,8 +290,8 @@ public class PlayOrderInfoServiceImpl extends ServiceImpl<PlayOrderInfoMapper, P
|
||||
@Override
|
||||
public void createRechargeOrder(String orderId, BigDecimal orderMoney, BigDecimal finalAmount, String purchaserBy) {
|
||||
PlayOrderInfoEntity entity = new PlayOrderInfoEntity(IdUtils.getUuid(), ORDER_STATUS_3, "0", "-1");
|
||||
entity.setOrderNo(this.getOrderNo());
|
||||
entity.setId(orderId);
|
||||
entity.setOrderNo(orderId);
|
||||
entity.setId(IdUtils.getUuid());
|
||||
entity.setOrderMoney(orderMoney);
|
||||
entity.setFinalAmount(finalAmount);
|
||||
entity.setPurchaserBy(purchaserBy);
|
||||
@@ -747,6 +747,12 @@ public class PlayOrderInfoServiceImpl extends ServiceImpl<PlayOrderInfoMapper, P
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayOrderInfoEntity queryByOrderNo(String orderNo) {
|
||||
LambdaQueryWrapper<PlayOrderInfoEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(PlayOrderInfoEntity::getOrderNo, orderNo);
|
||||
return this.baseMapper.selectOne(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.starry.admin.modules.weichat.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
||||
@@ -28,9 +27,15 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -71,67 +76,55 @@ public class WxPlayController {
|
||||
* @author admin
|
||||
* @since 2024/5/8 11:25
|
||||
**/
|
||||
@GetMapping("/jsCallback")
|
||||
public String wxPayNotify(@RequestBody String xmlData) {
|
||||
log.info("****************接受到微信支付回调:{}", xmlData);
|
||||
this.dealNotify(xmlData);
|
||||
|
||||
@RequestMapping("/jsCallback")
|
||||
public String wxPayNotify(HttpServletRequest request) {
|
||||
try (InputStream inStream = request.getInputStream(); ByteArrayOutputStream outSteam = new ByteArrayOutputStream()) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = inStream.read(buffer)) != -1) {
|
||||
outSteam.write(buffer, 0, len);
|
||||
}
|
||||
log.info("微信支付回调开始-参数解析-开始");
|
||||
// 获取微信调用我们notify_url的返回信息
|
||||
String result = outSteam.toString("utf-8");
|
||||
log.info("微信支付回调开始-参数解析-结束,result={}", result);
|
||||
this.dealNotify(result);
|
||||
} catch (Exception e) {
|
||||
log.error("微信支付回调业务处理异常", e);
|
||||
}
|
||||
return WxPayNotifyResponse.success("成功");
|
||||
}
|
||||
|
||||
private void dealNotify(String xmlData) {
|
||||
|
||||
public void dealNotify(String xmlData) {
|
||||
try {
|
||||
Map<String, String> orderMap = readStringXmlOut(xmlData);
|
||||
String outTradeNo = orderMap.get("out_trade_no");
|
||||
PlayOrderInfoEntity orderInfoEntity = orderInfoService.getById(outTradeNo);
|
||||
String tenantId = orderMap.get("attach");
|
||||
if (StrUtil.isBlank(tenantId)) {
|
||||
log.error("支付对应业务处理异常-未查询到租户信息,xmlData={}", xmlData);
|
||||
}
|
||||
SecurityUtils.setTenantId(tenantId);
|
||||
PlayOrderInfoEntity orderInfoEntity = orderInfoService.queryByOrderNo(outTradeNo);
|
||||
if (Objects.isNull(orderInfoEntity)) {
|
||||
log.error("*********未查询到对应的支付记录,订单号:{}", outTradeNo);
|
||||
log.error("支付对应业务处理异常-未查询到对应的支付记录,xmlData={}", xmlData);
|
||||
return;
|
||||
}
|
||||
// // TODO如果支付状态不是待支付
|
||||
// if (!orderInfoEntity.getOrderStatus().equals(RepairStatusEnum.NOT_PAY.name())) {
|
||||
// log.error("*********支付记录状态异常,支付记录:{}", JSONObject.toJSONString(repair));
|
||||
// return;
|
||||
// }
|
||||
// Date nowDate = new Date();
|
||||
// repair.setPaySuccessTime(nowDate);
|
||||
// repair.setPayStatus(RepairStatusEnum.PAID.name());
|
||||
// repair.setStatus(RepairStatusEnum.REPAIRING.name());
|
||||
// TODO如果订单不是支付订单,并且支付状态不为未支付
|
||||
if (!"0".equals(orderInfoEntity.getOrderType()) || !"0".equals(orderInfoEntity.getPayState())) {
|
||||
log.error("支付对应业务处理异常-支付记录状态异常,支付记录:xmlData={}", xmlData);
|
||||
return;
|
||||
}
|
||||
//修养订单状态
|
||||
orderInfoEntity.setPayState("1");
|
||||
orderInfoService.updateById(orderInfoEntity);
|
||||
|
||||
//修改账户余额
|
||||
customUserInfoService.customAccountBalanceRecharge(orderInfoEntity.getOrderMoney(), orderInfoEntity.getPurchaserBy(), orderInfoEntity.getId());
|
||||
log.info("*********支付处理完成");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
log.error("订单回调业务处理异常,xmlData={}", xmlData);
|
||||
}
|
||||
}
|
||||
//public void jsCallback(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
// // 读取回调数据
|
||||
// InputStream inputStream = request.getInputStream();
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// String s;
|
||||
// BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||
// while ((s = in.readLine()) != null) {
|
||||
// sb.append(s);
|
||||
// }
|
||||
// in.close();
|
||||
// inputStream.close();
|
||||
//
|
||||
// // 解析xml成map
|
||||
// Map<String, Object> m = XmlUtil.xmlToMap(sb.toString());
|
||||
// // 过滤空 设置 TreeMap
|
||||
// SortedMap<Object, Object> packageParams = new TreeMap<>();
|
||||
// for (String parameter : m.keySet()) {
|
||||
// Object parameterValue = m.get(parameter);
|
||||
// String v = "";
|
||||
// if (null != parameterValue) {
|
||||
// v = parameterValue.toString().trim();
|
||||
// }
|
||||
// packageParams.put(parameter, v);
|
||||
// }
|
||||
// log.info("packageParams=" + packageParams);
|
||||
// String resXml = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
|
||||
// response.getWriter().write(resXml);
|
||||
//}
|
||||
|
||||
|
||||
@CustomUserLogin
|
||||
@@ -161,24 +154,24 @@ public class WxPlayController {
|
||||
// 订单总金额,单位为分
|
||||
long totalFee = getTotalFee(money);
|
||||
// 创建订单信息
|
||||
// String orderNo = playOrderInfoService.getOrderNo();
|
||||
String orderId = IdUtil.fastSimpleUUID();
|
||||
orderInfoService.createRechargeOrder(orderId, new BigDecimal(totalFee * 1.0 / 100), new BigDecimal(totalFee * 1.0 / 100), customUserInfo.getId());
|
||||
customUserInfoService.customAccountBalanceRecharge(new BigDecimal(money), ThreadLocalRequestDetail.getCustomUserInfo().getId(), orderId);
|
||||
// return R.ok("充值成功");
|
||||
String orderNo = playOrderInfoService.getOrderNo();
|
||||
orderInfoService.createRechargeOrder(orderNo, new BigDecimal(totalFee * 1.0 / 100), new BigDecimal(totalFee * 1.0 / 100), customUserInfo.getId());
|
||||
|
||||
|
||||
WxPayService wxPayService = mpService.getWxPay();
|
||||
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
|
||||
request.setOpenid(customUserInfo.getOpenid());
|
||||
// 订单总金额,单位为分(开发阶段固定设置为支付1分钱)
|
||||
request.setAttach(tenantId);
|
||||
request.setTotalFee(1);
|
||||
request.setOutTradeNo(orderId);
|
||||
request.setOutTradeNo(orderNo);
|
||||
request.setTradeType("JSAPI");
|
||||
request.setSpbillCreateIp("101.43.206.16");
|
||||
request.setNotifyUrl(wxPayService.getConfig().getNotifyUrl());
|
||||
request.setBody("船票充值");
|
||||
WxPayUnifiedOrderResult orderResult;
|
||||
try {
|
||||
//统一下单,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易会话标识后再在APP里面调起支付
|
||||
orderResult = wxPayService.unifiedOrder(request);
|
||||
} catch (WxPayException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
Reference in New Issue
Block a user