修复支付的bug, storeid 莫名是空值,找了6个小时
This commit is contained in:
parent
30f14e0dbf
commit
fb5a417261
@ -17,26 +17,79 @@ import javax.servlet.http.HttpServletRequest;
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
private final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
public CommonResult exceptionHandler(HttpServletRequest req, Exception e) {
|
||||
logger.error("Exception全局异常捕获-" + e.getMessage(), e);
|
||||
return CommonResult.failed();
|
||||
|
||||
|
||||
// 获取异常的第一帧堆栈信息
|
||||
StackTraceElement[] stackTrace = e.getStackTrace();
|
||||
String location = "未知位置";
|
||||
|
||||
if (stackTrace.length > 0) {
|
||||
StackTraceElement element = stackTrace[0]; // 第一个异常抛出点
|
||||
String className = element.getClassName();
|
||||
String methodName = element.getMethodName();
|
||||
int lineNumber = element.getLineNumber();
|
||||
location = String.format("%s.%s (line: %d)", className, methodName, lineNumber);
|
||||
}
|
||||
|
||||
logger.error("Exception全局异常捕获 URI: {} - Method: {} - Error: {} at {}",
|
||||
req.getRequestURI(),
|
||||
req.getMethod(),
|
||||
e.getMessage(),
|
||||
location,
|
||||
e);
|
||||
|
||||
return CommonResult.failed("系统异常:" + location);
|
||||
|
||||
// logger.error("Exception全局异常捕获-" + e.getMessage(), e);
|
||||
// return CommonResult.failed();
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = ApiException.class)
|
||||
public CommonResult exceptionHandler(HttpServletRequest req, ApiException e) {
|
||||
// IErrorCode errorCode = e.getErrorCode();
|
||||
// String message = e.getMessage();
|
||||
// logger.error("ApiException全局异常捕获-" + e.getMessage(), e);
|
||||
// if (errorCode != null) {
|
||||
// return CommonResult.failed(errorCode);
|
||||
// } else if (StrUtil.isNotBlank(message)) {
|
||||
// return CommonResult.failed(message);
|
||||
// } else {
|
||||
// return CommonResult.failed(ResultCode.FAILED);
|
||||
// }
|
||||
|
||||
// 获取异常位置信息
|
||||
StackTraceElement[] stackTrace = e.getStackTrace();
|
||||
String location = "未知位置";
|
||||
|
||||
if (stackTrace.length > 0) {
|
||||
StackTraceElement element = stackTrace[0]; // 第一个异常抛出点
|
||||
location = String.format("%s.%s (line: %d)",
|
||||
element.getClassName(),
|
||||
element.getMethodName(),
|
||||
element.getLineNumber()
|
||||
);
|
||||
}
|
||||
|
||||
IErrorCode errorCode = e.getErrorCode();
|
||||
String message = e.getMessage();
|
||||
logger.error("ApiException全局异常捕获-" + e.getMessage(), e);
|
||||
|
||||
logger.error("Exception全局异常捕获 URI: {} - Method: {} - Error: {} at {}",
|
||||
req.getRequestURI(),
|
||||
req.getMethod(),
|
||||
e.getMessage(),
|
||||
location,
|
||||
e);
|
||||
|
||||
if (errorCode != null) {
|
||||
return CommonResult.failed(errorCode);
|
||||
} else if (StrUtil.isNotBlank(message)) {
|
||||
return CommonResult.failed(message);
|
||||
return CommonResult.failed("业务异常:" + message + " [" + location + "]");
|
||||
} else {
|
||||
return CommonResult.failed(ResultCode.FAILED);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,7 +289,7 @@ public interface ShopService {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/mobile/shop/orderlkl/pay/add/order")
|
||||
Boolean lklPayAddShopOrderLkl(@RequestBody JSONObject lklPayReqAndRespJson);
|
||||
boolean lklPayAddShopOrderLkl(@RequestBody JSONObject lklPayReqAndRespJson);
|
||||
|
||||
/**
|
||||
* 当拉卡拉支付成功后,更改一个拉卡拉订单信息
|
||||
@ -298,7 +298,7 @@ public interface ShopService {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/mobile/shop/orderlkl/pay/notify/update/order")
|
||||
Boolean lklPayNotifyUpdateShopOrderLkl(@RequestBody JSONObject lklPayNotifyDataJson);
|
||||
boolean lklPayNotifyUpdateShopOrderLkl(@RequestBody JSONObject lklPayNotifyDataJson);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
@ -27,6 +28,8 @@ import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -64,7 +67,7 @@ public class IndexController extends BaseControllerImpl {
|
||||
@RequestMapping(value = "/test/case", method = RequestMethod.POST)
|
||||
public JSONObject testCase(HttpServletRequest request, HttpServletResponse response,
|
||||
@RequestBody JSONObject objectJSON) {
|
||||
return lakalaPayService.transPreOrder(request, response, (String) objectJSON.get("orderId"));
|
||||
return lakalaPayService.lklTransPreOrder(request, response, (String) objectJSON.get("orderId"));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取支付密码", notes = "获取支付密码")
|
||||
@ -245,8 +248,13 @@ public class IndexController extends BaseControllerImpl {
|
||||
|
||||
@ApiOperation(value = "第三方拉卡拉在微信回调通知", notes = "第三方拉卡拉在微信回调通知")
|
||||
@RequestMapping(value = "/lkl_wxPay_notify_url", method = RequestMethod.POST)
|
||||
public String lklWxNotifyUrl(HttpServletRequest request) {
|
||||
return payUserPayService.lklNotifyUrl(request);
|
||||
public ResponseEntity<JSONObject> lklWxNotifyUrl(HttpServletRequest request) {
|
||||
JSONObject resp = JSONUtil.parseObj(payUserPayService.lklNotifyUrl(request));
|
||||
if (resp != null && "SUCCESS".equals(resp.get("code"))) {
|
||||
return new ResponseEntity<>(resp, HttpStatus.OK);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(resp, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pay_state_detection", method = RequestMethod.GET)
|
||||
|
||||
@ -18,7 +18,7 @@ public interface LakalaPayService {
|
||||
|
||||
Boolean initLKLSDK();
|
||||
|
||||
JSONObject transPreOrder(HttpServletRequest request, HttpServletResponse response, String orderId);
|
||||
JSONObject lklTransPreOrder(HttpServletRequest request, HttpServletResponse response, String orderId);
|
||||
|
||||
/**
|
||||
* 拉卡拉预下单
|
||||
@ -28,7 +28,6 @@ public interface LakalaPayService {
|
||||
* @param termNo 终端号
|
||||
* @param xcxAppId 小程序appid
|
||||
* @param openId openid
|
||||
* @param storeId 店铺号
|
||||
* @param orderId 订单号
|
||||
* @param subject 订单标题
|
||||
* @param totalAmount 订单金额
|
||||
@ -37,7 +36,7 @@ public interface LakalaPayService {
|
||||
* @param remark 备注
|
||||
* @return
|
||||
*/
|
||||
JSONObject transPreOrder(String merchantNo, String termNo, String xcxAppId, String openId, String storeId, String orderId, String subject, String totalAmount, String notifyURL, String requestIP, String remark);
|
||||
JSONObject lklTransPreOrder(String merchantNo, String termNo, String xcxAppId, String openId, String storeId, String orderId, String subject, String totalAmount, String notifyURL, String requestIP, String remark);
|
||||
|
||||
/**
|
||||
* 聚合扫码-交易查询
|
||||
|
||||
@ -108,7 +108,7 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.hutool.json.JSONObject transPreOrder(HttpServletRequest request, HttpServletResponse response, String orderId) {
|
||||
public cn.hutool.json.JSONObject lklTransPreOrder(HttpServletRequest request, HttpServletResponse response, String orderId) {
|
||||
// 1. 配置初始化
|
||||
initLKLSDK();
|
||||
|
||||
@ -157,7 +157,7 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
* @param termNo 终端号
|
||||
* @param xcxAppId 小程序appid
|
||||
* @param openId openid
|
||||
* @param storeId 订单号
|
||||
* @param storeId 店铺号
|
||||
* @param orderId 订单号
|
||||
* @param subject 订单标题
|
||||
* @param totalAmount 订单金额
|
||||
@ -167,7 +167,7 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JSONObject transPreOrder(String merchantNo, String termNo, String xcxAppId, String openId, String storeId, String orderId, String subject, String totalAmount, String notifyURL, String requestIP, String remark) {
|
||||
public JSONObject lklTransPreOrder(String merchantNo, String termNo, String xcxAppId, String openId, String storeId, String orderId, String subject, String totalAmount, String notifyURL, String requestIP, String remark) {
|
||||
// 1. 配置初始化
|
||||
initLKLSDK();
|
||||
|
||||
@ -203,7 +203,7 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
wechatBus.setSubAppid(xcxAppId); // 小程序appId
|
||||
wechatBus.setUserId(openId); // 微信 openId
|
||||
wechatBus.setDeviceInfo("WEB"); // 终端设备号(门店号或收银设备ID),注意:PC网页或JSAPI支付请传”WEB”
|
||||
wechatBus.setAttach(storeId); // 附加数据,商户自定义数据,在查询交易结果时原样返回。
|
||||
// wechatBus.setAttach(storeId); // 附加数据,商户自定义数据,在查询交易结果时原样返回。
|
||||
v3LabsTransPreorderWechatReq.setAccBusiFields(wechatBus);
|
||||
|
||||
try {
|
||||
|
||||
@ -222,7 +222,6 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
|
||||
}
|
||||
|
||||
PayConsumeTrade trade_row = new PayConsumeTrade();
|
||||
|
||||
List<Integer> trade_is_paids = trade_rows.stream().map(PayConsumeTrade::getTrade_is_paid).collect(Collectors.toList());
|
||||
Integer trade_is_paid = trade_is_paids.contains(StateCode.ORDER_PAID_STATE_YES) ? StateCode.ORDER_PAID_STATE_YES : StateCode.ORDER_PAID_STATE_NO;
|
||||
trade_row.setTrade_is_paid(trade_is_paid);
|
||||
@ -257,6 +256,11 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
|
||||
trade_row.setTrade_title(I18nUtil._("在线购物"));
|
||||
trade_row.setTrade_desc(I18nUtil._("在线购物"));
|
||||
}
|
||||
|
||||
if (CollUtil.isNotEmpty(trade_rows)) {
|
||||
trade_row.setStore_id(trade_rows.get(0).getStore_id());//店铺ID
|
||||
}
|
||||
|
||||
// 注:多渠道支付(重要)
|
||||
executeMultiChannelPayment(request, response, trade_row, payTypeBean);
|
||||
return;
|
||||
@ -595,8 +599,10 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
|
||||
data.put("code", 1);
|
||||
data.put("data", new Object());
|
||||
|
||||
Integer storeId = payConsumeTrade.getStore_id();
|
||||
|
||||
// 这里获取店铺的拉卡拉的商户号和终端号码
|
||||
ShopStoreBase shopStoreBase = shopService.getLklMerchantNoAndTermNo(payConsumeTrade.getStore_id());
|
||||
ShopStoreBase shopStoreBase = shopService.getLklMerchantNoAndTermNo(storeId);
|
||||
if (shopStoreBase == null) {
|
||||
data.put("message", "获取店铺商户号失败!");
|
||||
setResponseBody(response, data);
|
||||
@ -607,11 +613,11 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
|
||||
String domain = wxPayApiConfig.getDomain();
|
||||
String requestIP = IpKit.getRealIp(request);
|
||||
String notifyUrl = domain + "/lkl_wxPay_notify_url";
|
||||
String storeId = Convert.toStr(payConsumeTrade.getStore_id());// 店铺Id
|
||||
String storeIdStr = Convert.toStr(storeId);// 店铺Id
|
||||
|
||||
// 拉卡拉预支付返回参数
|
||||
cn.hutool.json.JSONObject lakalaRespJSON = lakalaPayService.transPreOrder(shopStoreBase.getLkl_merchant_no(), shopStoreBase.getLkl_term_no(),
|
||||
appId, openId, storeId, out_trade_no, subject, total_amt,
|
||||
cn.hutool.json.JSONObject lakalaRespJSON = lakalaPayService.lklTransPreOrder(shopStoreBase.getLkl_merchant_no(), shopStoreBase.getLkl_term_no(),
|
||||
appId, openId, storeIdStr, out_trade_no, subject, total_amt,
|
||||
notifyUrl,
|
||||
requestIP, trade_remark);
|
||||
|
||||
@ -1340,7 +1346,6 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
|
||||
// 修改 拉卡拉的订单记录 shop_order_lkl
|
||||
shopService.lklPayNotifyUpdateShopOrderLkl(lklNotifyRespJSON);
|
||||
|
||||
|
||||
if (tradeCombine != null && StrUtil.isNotBlank(tradeCombine.getOrder_ids())) {
|
||||
payConsumeDeposit.setOrder_id(tradeCombine.getOrder_ids());
|
||||
}
|
||||
@ -1348,20 +1353,17 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
|
||||
// 注:重要,支付完成接口调用
|
||||
if (!payConsumeDepositService.processDeposit(payConsumeDeposit, BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO)) {
|
||||
log.error("支付失败!");
|
||||
log.error("[processDeposit]处理订单数据失败!");
|
||||
return lklNotifyMsg(false, "支付失败!");
|
||||
}
|
||||
|
||||
transactionManager.commit(transactionStatus);
|
||||
} catch (Exception e) {
|
||||
transactionManager.rollback(transactionStatus);
|
||||
log.error("支付失败,错误信息:{}", e);
|
||||
log.error("接收拉卡拉支付异步通知出错:{}", e);
|
||||
throw new ApiException(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
// TODO 分账指令执行
|
||||
|
||||
return lklNotifyMsg(true, "执行成功");
|
||||
} catch (Exception e) {
|
||||
logger.error("通知处理发生异常:{}", e.getMessage(), e);
|
||||
|
||||
@ -25,13 +25,13 @@ public class ShopOrderLklController extends BaseControllerImpl {
|
||||
|
||||
@ApiOperation(value = "当拉卡拉支付时,新增一个拉卡拉订单信息", notes = "当拉卡拉支付时,新增一个拉卡拉订单信息")
|
||||
@RequestMapping(value = "/pay/add/order", method = RequestMethod.POST)
|
||||
public Boolean lklPayAddShopOrderLkl(@RequestBody JSONObject lklPayReqAndRespJson) {
|
||||
public boolean lklPayAddShopOrderLkl(@RequestBody JSONObject lklPayReqAndRespJson) {
|
||||
return shopOrderLklService.addOrUpdateByLklPayDataJson(lklPayReqAndRespJson);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "当拉卡拉支付成功后,更改一个拉卡拉订单信息", notes = "当拉卡拉支付成功后,更改一个拉卡拉订单信息")
|
||||
@RequestMapping(value = "/pay/notify/update/order", method = RequestMethod.POST)
|
||||
public Boolean lklPayNotifyUpdateShopOrderLkl(@RequestBody JSONObject lklPayNotifyDataJson) {
|
||||
public boolean lklPayNotifyUpdateShopOrderLkl(@RequestBody JSONObject lklPayNotifyDataJson) {
|
||||
return shopOrderLklService.addOrUpdateByLklPayNotifyDataJson(lklPayNotifyDataJson);
|
||||
}
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ public class OrderPayedListener {
|
||||
|
||||
if (flag) {
|
||||
// 3. 若订单更新成功,执行后续操作(取单号生成、打票机打印、顺丰下单等)
|
||||
handlePostPaymentActions(orderIdList);
|
||||
handleSfExpressOrderActions(orderIdList);
|
||||
}
|
||||
|
||||
// 4. 根据执行结果确认或拒绝消息
|
||||
@ -139,22 +139,14 @@ public class OrderPayedListener {
|
||||
|
||||
|
||||
/**
|
||||
* 处理支付完成后需要执行的操作:
|
||||
* 处理支付完成后执行顺丰订单生成和取单号操作:
|
||||
* - 生成取单号
|
||||
* - 打印小票
|
||||
* - 顺丰同城下单等
|
||||
*
|
||||
* @param orderIdList 订单 ID 列表
|
||||
*/
|
||||
/**
|
||||
* 处理支付完成后需要执行的操作:
|
||||
* - 生成取单号
|
||||
* - 打印小票
|
||||
* - 顺丰同城下单等
|
||||
*
|
||||
* @param orderIdList 订单 ID 列表
|
||||
*/
|
||||
private void handlePostPaymentActions(List<String> orderIdList) {
|
||||
private void handleSfExpressOrderActions(List<String> orderIdList) {
|
||||
if (orderIdList == null || orderIdList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -14,10 +14,12 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.suisung.mall.common.modules.order.ShopOrderBase;
|
||||
import com.suisung.mall.common.modules.order.ShopOrderLkl;
|
||||
import com.suisung.mall.common.utils.DateTimeUtils;
|
||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||
import com.suisung.mall.shop.order.mapper.ShopOrderLklMapper;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderBaseService;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderDataService;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderLklService;
|
||||
import com.suisung.mall.shop.store.service.ShopStoreBaseService;
|
||||
@ -39,10 +41,15 @@ public class ShopOrderLklServiceImpl extends BaseServiceImpl<ShopOrderLklMapper,
|
||||
@Resource
|
||||
private ShopStoreBaseService shopStoreBaseService;
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private ShopOrderBaseService shopOrderBaseService;
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private ShopOrderDataService shopOrderDataService;
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean addOrUpdateByStoreOrder(ShopOrderLkl record) {
|
||||
if (record == null
|
||||
@ -66,50 +73,52 @@ public class ShopOrderLklServiceImpl extends BaseServiceImpl<ShopOrderLklMapper,
|
||||
* 根据拉卡拉的回调数据,更新拉卡拉的订单信息
|
||||
*
|
||||
* @param lklPayReqAndRespJson 拉卡拉支付请求和响应JSON参数:
|
||||
* {"req":{
|
||||
* "req_time": "20240621153714",
|
||||
* "version": "3.0",
|
||||
* "req_data": {
|
||||
* "merchant_no": "822290059430BCY",
|
||||
* "term_no": "D9285650",
|
||||
* "out_trade_no": "720982165373671834096",
|
||||
* "account_type": "ALIPAY",
|
||||
* "trans_type": "41",
|
||||
* "total_amount": 1,
|
||||
* "notify_url": "http://47.105.146.241:9510/channelbacknotice/open/platform/transfer/V3",
|
||||
* "location_info": {
|
||||
* "request_ip": "192.168.23.165",
|
||||
* "location": "+23.137208/+113.381982"
|
||||
* },
|
||||
* "subject": "测试"
|
||||
* }
|
||||
* },
|
||||
* "resp": {
|
||||
* "code": "BBS00000",
|
||||
* "msg": "成功",
|
||||
* "resp_time": "20240626155843",
|
||||
* "code": "BBS00000",
|
||||
* "resp_time": "20250530235926",
|
||||
* "resp_data": {
|
||||
* "merchant_no": "822290059430BCY",
|
||||
* "out_trade_no": "720982165373671834096",
|
||||
* "trade_no": "2024062666210315450047",
|
||||
* "log_no": "66210315450047",
|
||||
* "settle_merchant_no": "",
|
||||
* "settle_term_no": "",
|
||||
* "merchant_no": "8226330599900LN",
|
||||
* "acc_resp_fields": {
|
||||
* "code": "https://qr.alipay.com/bax01162hikpdvl7nk9t005f",
|
||||
* "nonce_str": "2251c382b60b46779e2fcc817348c3a2",
|
||||
* "code": "",
|
||||
* "package": "prepay_id=wx30235926189682ec29c44fe15460f00000",
|
||||
* "time_stamp": "1748620766",
|
||||
* "sub_mch_id": "735994552",
|
||||
* "best_pay_info": "",
|
||||
* "prepay_id": "wx30235926189682ec29c44fe15460f00000",
|
||||
* "partner_id": "",
|
||||
* "code_image": "",
|
||||
* "prepay_id": "",
|
||||
* "app_id": "",
|
||||
* "pay_sign": "",
|
||||
* "time_stamp": "",
|
||||
* "nonce_str": "",
|
||||
* "package": "",
|
||||
* "sign_type": "",
|
||||
* "form_data": "",
|
||||
* "app_id": "wx5a73f844dac0da5c",
|
||||
* "sign_type": "RSA",
|
||||
* "redirect_url": "",
|
||||
* "best_pay_info": ""
|
||||
* }
|
||||
* }
|
||||
* "pay_sign": "EJGsPMiDJVSgH920E0eMoOzcVGHSt+CoFbvpyScIU4aANBD9ZGWNroQhgR4SbbWnJfGMMOBcyjVVB0V6cJKadwz0TAguQy5+yMTtnjuV5GTKV4LxWzo2hV2rXJUFT8QQlmRz0rmILyiJmgMhZNuUrVDentEyZfOJcEcQ4X21pNO79vDyEFy+P/2EAZZlNVhcgRe/k7tQTSGhtokRpyfadGfp1Le0q+vtfgBvoe4sVorbvEq2H067vPRl3JpoC7pJGdsZ0//DdOf9M60YqLjYLQa3Hc6EixtZr7H7YxPqwu4Zq16TIuQGBGNUa2ycY4ddkeuFhHhunmI/w/GsR+1VoQ=="
|
||||
* },
|
||||
* "settle_term_no": "",
|
||||
* "log_no": "66231419357295",
|
||||
* "out_trade_no": "DD-20250530-9",
|
||||
* "trade_no": "20250530110113130266231419357295",
|
||||
* "settle_merchant_no": "",
|
||||
* "trade_req_date": "20250530" * }
|
||||
* }, "req": {
|
||||
* "locationInfo": {
|
||||
* "requestIp": "111.58.69.144"
|
||||
* } ,
|
||||
* "subject": "在线购物",
|
||||
* "accountType": "WECHAT",
|
||||
* "remark": "",
|
||||
* "totalAmount": "1",
|
||||
* "transType": "51",
|
||||
* "outTradeNo": "DD-20250530-9",
|
||||
* "notifyUrl": "https://mall.gpxscs.cn/mobile/pay/index/lkl_wxPay_notify_url",
|
||||
* "termNo": "M0780798",
|
||||
* "accBusiFields": {
|
||||
* "userId": "oDVKR7T0qxg6O8tqIL9SgY6LXqqQ",
|
||||
* "deviceInfo": "WEB",
|
||||
* "subAppid": "wx5a73f844dac0da5c"
|
||||
* },
|
||||
* "settleType": "1",
|
||||
* "merchantNo": "8226330599900LN"
|
||||
* }
|
||||
* }
|
||||
* @return
|
||||
@ -121,63 +130,72 @@ public class ShopOrderLklServiceImpl extends BaseServiceImpl<ShopOrderLklMapper,
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取请求体和响应体
|
||||
JSONObject reqDataJson = JSONUtil.parseObj(lklPayReqAndRespJson.getByPath("req.req_data"));
|
||||
JSONObject respDataJson = JSONUtil.parseObj(lklPayReqAndRespJson.getByPath("resp.resp_data"));
|
||||
log.debug("拉卡拉支付请求和响应数据 body:{}", lklPayReqAndRespJson);
|
||||
try {
|
||||
|
||||
if (reqDataJson == null || respDataJson == null) {
|
||||
log.warn("请求或响应数据中的 req_data / resp_data 为空");
|
||||
// 获取请求体和响应体
|
||||
JSONObject reqDataJson = lklPayReqAndRespJson.getJSONObject("req");// 驼峰命名
|
||||
JSONObject respDataJson = JSONUtil.parseObj(lklPayReqAndRespJson.getByPath("resp.resp_data"));// 下划线命名
|
||||
|
||||
if (reqDataJson == null || respDataJson == null) {
|
||||
log.error("请求或响应数据中的 req_data / resp_data 为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 提取订单号并校验
|
||||
String orderId = respDataJson.getStr("out_trade_no");
|
||||
if (StringUtils.isBlank(orderId)) {
|
||||
log.error("订单ID为空,无法保存拉卡拉支付记录");
|
||||
return false;
|
||||
}
|
||||
|
||||
ShopOrderBase shopOrderBase = shopOrderBaseService.get(orderId);
|
||||
if (shopOrderBase == null) {
|
||||
log.error("订单不存在,无法保存拉卡拉支付记录");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ShopOrderLkl record = new ShopOrderLkl();
|
||||
record.setOrder_id(orderId);
|
||||
|
||||
// 设置请求内容
|
||||
|
||||
// 订单金额安全处理
|
||||
Integer amount = reqDataJson.getInt("totalAmount");
|
||||
if (amount == null) {
|
||||
log.error("订单{}金额无效: {}", orderId, amount);
|
||||
return false;
|
||||
}
|
||||
record.setTotal_amt(amount);
|
||||
|
||||
record.setAccount_type(reqDataJson.getStr("accountType"));
|
||||
record.setTrans_type(reqDataJson.getStr("transType"));
|
||||
record.setNotify_url(reqDataJson.getStr("notifyUrl"));
|
||||
record.setLkl_merchant_no(reqDataJson.getStr("merchantNo"));
|
||||
record.setLkl_term_no(reqDataJson.getStr("termNo"));
|
||||
record.setLkl_req(JSONUtil.toJsonStr(reqDataJson));
|
||||
|
||||
// 设置响应内容
|
||||
record.setLkl_log_no(respDataJson.getStr("log_no"));
|
||||
record.setLkl_trade_no(respDataJson.getStr("trade_no"));
|
||||
record.setLkl_resp(JSONUtil.toJsonStr(respDataJson));
|
||||
|
||||
// 关键数据:获取店铺ID,分账比例用到
|
||||
Integer storeId = shopOrderBase.getStore_id();
|
||||
|
||||
record.setStore_id(Convert.toStr(storeId));
|
||||
|
||||
// 运费和商家分账比例
|
||||
BigDecimal shipperFee = shopOrderDataService.getOrderShippingFee(orderId);
|
||||
record.setShopping_fee(shipperFee.multiply(BigDecimal.valueOf(100)).intValue()); // 运费,单位:分
|
||||
record.setSplit_ratio(shopStoreBaseService.getStorePlatformRatio(storeId, false)); // 商家分账比例
|
||||
|
||||
return addOrUpdateByStoreOrder(record);
|
||||
} catch (Exception e) {
|
||||
log.error("新增拉卡拉支付记录出错", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 提取订单号并校验
|
||||
String orderId = reqDataJson.getStr("out_trade_no");
|
||||
if (StringUtils.isBlank(orderId)) {
|
||||
log.warn("订单ID为空,无法保存拉卡拉支付记录");
|
||||
return false;
|
||||
}
|
||||
|
||||
ShopOrderLkl record = new ShopOrderLkl();
|
||||
record.setOrder_id(orderId);
|
||||
|
||||
// 设置请求内容
|
||||
record.setLkl_merchant_no(reqDataJson.getStr("merchant_no"));
|
||||
record.setLkl_term_no(reqDataJson.getStr("term_no"));
|
||||
|
||||
// 订单金额安全处理
|
||||
Integer amount = reqDataJson.getInt("total_amount");
|
||||
if (amount == null) {
|
||||
log.error("订单{}金额无效: {}", orderId, amount);
|
||||
return false;
|
||||
}
|
||||
record.setTotal_amt(amount);
|
||||
|
||||
record.setAccount_type(reqDataJson.getStr("account_type"));
|
||||
record.setTrans_type(reqDataJson.getStr("trans_type"));
|
||||
record.setNotify_url(reqDataJson.getStr("notify_url"));
|
||||
|
||||
|
||||
record.setLkl_req(JSONUtil.toJsonStr(reqDataJson));
|
||||
|
||||
// 设置响应内容
|
||||
record.setLkl_log_no(respDataJson.getStr("log_no"));
|
||||
record.setLkl_trade_no(respDataJson.getStr("trade_no"));
|
||||
record.setLkl_resp(JSONUtil.toJsonStr(respDataJson));
|
||||
|
||||
// 关键数据:获取店铺ID,分账比例用到
|
||||
Integer storeId = 0;
|
||||
Object attachObj = reqDataJson.getByPath("acc_busi_fields.attach");
|
||||
if (attachObj != null) {
|
||||
storeId = Convert.toInt(attachObj);
|
||||
record.setStore_id(storeId.toString());
|
||||
}
|
||||
|
||||
// 运费和商家分账比例
|
||||
BigDecimal shipperFee = shopOrderDataService.getOrderShippingFee(orderId);
|
||||
record.setShopping_fee(shipperFee.multiply(BigDecimal.valueOf(100)).intValue()); // 运费,单位:分
|
||||
record.setSplit_ratio(shopStoreBaseService.getStorePlatformRatio(storeId, false)); // 商家分账比例
|
||||
|
||||
return addOrUpdateByStoreOrder(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -187,34 +205,41 @@ public class ShopOrderLklServiceImpl extends BaseServiceImpl<ShopOrderLklMapper,
|
||||
return false;
|
||||
}
|
||||
|
||||
String orderId = lklPayNotifyDataJson.getStr("out_trade_no");
|
||||
if (StringUtils.isBlank(orderId)) {
|
||||
log.warn("订单ID为空,无法保存拉卡拉支付通知记录");
|
||||
log.debug("拉卡拉支付通知回调 body:{}", lklPayNotifyDataJson);
|
||||
try {
|
||||
|
||||
String orderId = lklPayNotifyDataJson.getStr("out_trade_no");
|
||||
if (StringUtils.isBlank(orderId)) {
|
||||
log.warn("订单ID为空,无法保存拉卡拉支付通知记录");
|
||||
return false;
|
||||
}
|
||||
|
||||
ShopOrderLkl record = new ShopOrderLkl();
|
||||
record.setOrder_id(orderId);
|
||||
|
||||
// 设置必填字段并校验
|
||||
String logNo = lklPayNotifyDataJson.getStr("log_no");
|
||||
if (StringUtils.isBlank(logNo)) {
|
||||
log.warn("log_no 为空,无法保存拉卡拉支付通知记录");
|
||||
return false;
|
||||
}
|
||||
record.setLkl_log_no(logNo);
|
||||
|
||||
// 设置日期字段
|
||||
record.setLkl_log_date(DateTimeUtils.formatDateTime(LocalDateTime.now(), "yyyy-MM-dd"));
|
||||
|
||||
// 设置可选字段
|
||||
record.setLkl_trade_no(lklPayNotifyDataJson.getStr("trade_no"));
|
||||
record.setTrade_status(lklPayNotifyDataJson.getStr("trade_status"));
|
||||
|
||||
// 安全地设置响应内容
|
||||
record.setLkl_notify_resp(JSONUtil.toJsonStr(lklPayNotifyDataJson));
|
||||
|
||||
return addOrUpdateByStoreOrder(record);
|
||||
} catch (Exception e) {
|
||||
log.error("修改拉卡拉支付通知记录出错", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
ShopOrderLkl record = new ShopOrderLkl();
|
||||
record.setOrder_id(orderId);
|
||||
|
||||
// 设置必填字段并校验
|
||||
String logNo = lklPayNotifyDataJson.getStr("log_no");
|
||||
if (StringUtils.isBlank(logNo)) {
|
||||
log.warn("log_no 为空,无法保存拉卡拉支付通知记录");
|
||||
return false;
|
||||
}
|
||||
record.setLkl_log_no(logNo);
|
||||
|
||||
// 设置日期字段
|
||||
record.setLkl_log_date(DateTimeUtils.formatDateTime(LocalDateTime.now(), "yyyy-MM-dd"));
|
||||
|
||||
// 设置可选字段
|
||||
record.setLkl_trade_no(lklPayNotifyDataJson.getStr("trade_no"));
|
||||
record.setTrade_status(lklPayNotifyDataJson.getStr("trade_status"));
|
||||
|
||||
// 安全地设置响应内容
|
||||
record.setLkl_resp(JSONUtil.toJsonStr(lklPayNotifyDataJson));
|
||||
|
||||
return addOrUpdateByStoreOrder(record);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user