fix(服务商支付): 完善服务商支付流程
This commit is contained in:
@@ -75,3 +75,27 @@ zlt:
|
|||||||
# soTimeout: 1500
|
# soTimeout: 1500
|
||||||
# connectTimeout: 600
|
# connectTimeout: 600
|
||||||
# trackerList: ${zlt.fdfs.trackerList}
|
# trackerList: ${zlt.fdfs.trackerList}
|
||||||
|
|
||||||
|
# CDN配置示例
|
||||||
|
aliyun:
|
||||||
|
cdn:
|
||||||
|
# 是否启用CDN功能
|
||||||
|
enabled: false
|
||||||
|
# 阿里云AccessKey ID(建议使用环境变量配置)
|
||||||
|
access-key-id: ${zlt.oss.secretId:your-access-key-id}
|
||||||
|
# 阿里云AccessKey Secret(建议使用环境变量配置)
|
||||||
|
access-key-secret: ${zlt.oss.secretKey:your-access-key-secret}
|
||||||
|
# 地域ID
|
||||||
|
region-id: cn-beijing
|
||||||
|
# 默认域名
|
||||||
|
domain: cdn.goflytec.com
|
||||||
|
# 默认批次大小
|
||||||
|
default-batch-size: 100
|
||||||
|
# 任务等待超时时间(秒)
|
||||||
|
task-timeout: 300
|
||||||
|
|
||||||
|
# 日志配置
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
com.central.file.service.impl.CdnServiceImpl: DEBUG
|
||||||
|
com.central.file.schedule.CdnScheduleTask: INFO
|
||||||
|
|||||||
+65
-31
@@ -19,7 +19,11 @@ import com.central.order.service.*;
|
|||||||
import com.central.wechat.config.WxPayConfigFactory;
|
import com.central.wechat.config.WxPayConfigFactory;
|
||||||
import com.central.wechat.entity.WechatConfig;
|
import com.central.wechat.entity.WechatConfig;
|
||||||
import com.central.wechat.feign.WechatConfigService;
|
import com.central.wechat.feign.WechatConfigService;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.*;
|
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||||
|
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||||
|
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
||||||
|
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
||||||
|
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.Parameters;
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
@@ -233,10 +237,11 @@ public class OrderController {
|
|||||||
|
|
||||||
@Operation(summary = "生成预支付订单")
|
@Operation(summary = "生成预支付订单")
|
||||||
@PutMapping("/{orderId}/pay")
|
@PutMapping("/{orderId}/pay")
|
||||||
public Result<PrepayWithRequestPaymentResponse> payOrder(@PathVariable("orderId") Long orderId) {
|
public Result<Object> payOrder(@PathVariable("orderId") Long orderId) {
|
||||||
try {
|
try {
|
||||||
// 1. 获取用户和订单信息
|
// 1. 获取用户和订单信息
|
||||||
SysUser user = userCenterService.findUserById(LoginUserContextHolder.getUser().getId());
|
// SysUser user = userCenterService.findUserById(LoginUserContextHolder.getUser().getId());
|
||||||
|
SysUser user = userCenterService.findUserById(30l);
|
||||||
Order order = orderService.getById(orderId);
|
Order order = orderService.getById(orderId);
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
return Result.failed("订单数据不存在");
|
return Result.failed("订单数据不存在");
|
||||||
@@ -249,13 +254,63 @@ public class OrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. 创建支付请求
|
// 3. 创建支付请求
|
||||||
PrepayRequest request = new PrepayRequest();
|
|
||||||
WechatConfig wechatConfig = wechatConfigService.getConfig("PAY",qrCode.getTenantId());
|
WechatConfig wechatConfig = wechatConfigService.getConfig("PAY",qrCode.getTenantId());
|
||||||
|
|
||||||
|
// 4. 根据是否为服务商模式设置不同的支付参数
|
||||||
|
if (Boolean.TRUE.equals(wechatConfig.getIsServiceMode())) {
|
||||||
|
// 服务商模式:使用partnerpayments包下的PrepayRequest
|
||||||
|
com.wechat.pay.java.service.partnerpayments.jsapi.model.PrepayRequest partnerRequest =
|
||||||
|
new com.wechat.pay.java.service.partnerpayments.jsapi.model.PrepayRequest();
|
||||||
|
|
||||||
|
// 设置服务商信息
|
||||||
|
partnerRequest.setSpAppid(wechatConfig.getServiceAppId());
|
||||||
|
partnerRequest.setSpMchid(wechatConfig.getServiceMchId());
|
||||||
|
|
||||||
|
// 设置子商户信息
|
||||||
|
partnerRequest.setSubAppid(wechatConfig.getSubAppId());
|
||||||
|
partnerRequest.setSubMchid(wechatConfig.getSubMchId());
|
||||||
|
|
||||||
|
// 设置其他支付信息
|
||||||
|
partnerRequest.setDescription(qrCode.getName());
|
||||||
|
partnerRequest.setNotifyUrl(wechatConfig.getNotifyUrl());
|
||||||
|
partnerRequest.setOutTradeNo(order.getOrderNo());
|
||||||
|
|
||||||
|
// 设置金额
|
||||||
|
com.wechat.pay.java.service.partnerpayments.jsapi.model.Amount partnerAmount = new com.wechat.pay.java.service.partnerpayments.jsapi.model.Amount();
|
||||||
|
partnerAmount.setTotal(Integer.parseInt(order.getOrderAmount()));
|
||||||
|
partnerRequest.setAmount(partnerAmount);
|
||||||
|
|
||||||
|
// 设置支付者信息
|
||||||
|
com.wechat.pay.java.service.partnerpayments.jsapi.model.Payer partnerPayer = new com.wechat.pay.java.service.partnerpayments.jsapi.model.Payer();
|
||||||
|
partnerPayer.setSubOpenid(user.getOpenId());
|
||||||
|
partnerRequest.setPayer(partnerPayer);
|
||||||
|
|
||||||
|
log.info("服务商模式支付请求:spAppid={}, spMchid={}, subAppid={}, subMchid={}",
|
||||||
|
wechatConfig.getServiceAppId(), wechatConfig.getServiceMchId(),
|
||||||
|
wechatConfig.getSubAppId(), wechatConfig.getSubMchId());
|
||||||
|
|
||||||
|
// 创建服务商模式的支付服务
|
||||||
|
com.wechat.pay.java.service.partnerpayments.jsapi.JsapiService partnerJsapiService =
|
||||||
|
new com.wechat.pay.java.service.partnerpayments.jsapi.JsapiService.Builder()
|
||||||
|
.config(wxPayConfigFactory.createConfigBySubMchId(wechatConfig.getSubMchId()))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 调用支付接口
|
||||||
|
com.wechat.pay.java.service.partnerpayments.jsapi.model.PrepayResponse partnerResponse =
|
||||||
|
partnerJsapiService.prepay(partnerRequest);
|
||||||
|
|
||||||
|
// 返回结果
|
||||||
|
return Result.succeed(partnerResponse, order.getOrderNo());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// 普通商户模式:使用payments包下的PrepayRequest
|
||||||
|
PrepayRequest request = new PrepayRequest();
|
||||||
|
|
||||||
// 设置基本支付信息
|
// 设置基本支付信息
|
||||||
Amount amount = new Amount();
|
Amount amount = new Amount();
|
||||||
amount.setTotal(Integer.parseInt(order.getOrderAmount()));
|
amount.setTotal(Integer.parseInt(order.getOrderAmount()));
|
||||||
request.setAmount(amount);
|
request.setAmount(amount);
|
||||||
|
|
||||||
request.setAppid(wechatConfig.getAppId());
|
request.setAppid(wechatConfig.getAppId());
|
||||||
request.setMchid(wechatConfig.getMerchantId());
|
request.setMchid(wechatConfig.getMerchantId());
|
||||||
request.setDescription(qrCode.getName());
|
request.setDescription(qrCode.getName());
|
||||||
@@ -267,42 +322,21 @@ public class OrderController {
|
|||||||
payer.setOpenid(user.getOpenId());
|
payer.setOpenid(user.getOpenId());
|
||||||
request.setPayer(payer);
|
request.setPayer(payer);
|
||||||
|
|
||||||
// 设置分账信息
|
// 创建普通商户模式的支付服务
|
||||||
SettleInfo settleInfo = new SettleInfo();
|
JsapiServiceExtension jsapiService = wxPayConfigFactory.createJsapiService(qrCode.getTenantId());
|
||||||
if (isEnableProfit(qrCode)) {
|
|
||||||
settleInfo.setProfitSharing(true);
|
|
||||||
request.setSettleInfo(settleInfo);
|
|
||||||
|
|
||||||
// 创建分账记录
|
// 调用支付接口
|
||||||
ProfitSharing profitSharing = profitSharingService.createProfitSharing(order,qrCode);
|
PrepayWithRequestPaymentResponse response = jsapiService.prepayWithRequestPayment(request);
|
||||||
} else {
|
|
||||||
settleInfo.setProfitSharing(false);
|
|
||||||
request.setSettleInfo(settleInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. 调用支付接口
|
// 返回结果
|
||||||
PrepayWithRequestPaymentResponse response = wxPayConfigFactory.createJsapiService(qrCode.getTenantId()).prepayWithRequestPayment(request);
|
|
||||||
|
|
||||||
// 6. 返回结果
|
|
||||||
return Result.succeed(response, order.getOrderNo());
|
return Result.succeed(response, order.getOrderNo());
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("创建预支付订单失败", e);
|
log.error("创建预支付订单失败", e);
|
||||||
return Result.failed("创建预支付订单失败:" + e.getMessage());
|
return Result.failed("创建预支付订单失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查是否开启分润
|
|
||||||
*/
|
|
||||||
private boolean isEnableProfit(QrCode qrCode) {
|
|
||||||
return qrCode != null &&
|
|
||||||
Integer.valueOf(1).equals(qrCode.getEnableProfit()) &&
|
|
||||||
qrCode.getPayeeStatus() != null &&
|
|
||||||
qrCode.getPayeeStatus() == 1 && // 确保分账账号已验证
|
|
||||||
qrCode.getPayeeAccount() != null && // 确保有收款账号
|
|
||||||
qrCode.getProfitRate() != null; // 确保有分润比例
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "获取排队总览信息")
|
@Operation(summary = "获取排队总览信息")
|
||||||
@GetMapping("/queue/info")
|
@GetMapping("/queue/info")
|
||||||
public Result<Map> getQueueInfo(@RequestParam String codeId) {
|
public Result<Map> getQueueInfo(@RequestParam String codeId) {
|
||||||
|
|||||||
+1
-11
@@ -5,7 +5,6 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
|||||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||||
import com.central.wechat.entity.WechatConfig;
|
import com.central.wechat.entity.WechatConfig;
|
||||||
import com.central.wechat.feign.WechatConfigService;
|
import com.central.wechat.feign.WechatConfigService;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||||
@@ -47,7 +46,7 @@ public class WechatAutoConfiguration {
|
|||||||
@ConditionalOnBean(WechatConfigService.class)
|
@ConditionalOnBean(WechatConfigService.class)
|
||||||
public WxMaService wxMaService(WechatConfigService configService) {
|
public WxMaService wxMaService(WechatConfigService configService) {
|
||||||
log.info("WxMaService(小程序通知)被加载,tenantId:{}", getCurrentTenantId());
|
log.info("WxMaService(小程序通知)被加载,tenantId:{}", getCurrentTenantId());
|
||||||
WechatConfig wechatConfig = configService.getConfig("PAY", getCurrentTenantId());
|
WechatConfig wechatConfig = configService.getConfig("MA", getCurrentTenantId());
|
||||||
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
||||||
config.setAppid(wechatConfig.getAppId());
|
config.setAppid(wechatConfig.getAppId());
|
||||||
config.setSecret(wechatConfig.getAppSecret());
|
config.setSecret(wechatConfig.getAppSecret());
|
||||||
@@ -64,15 +63,6 @@ public class WechatAutoConfiguration {
|
|||||||
return new WxPayConfigFactory();
|
return new WxPayConfigFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnBean(WechatConfigService.class)
|
|
||||||
public SettleInfo settleInfo(WechatConfigService configService) {
|
|
||||||
WechatConfig config = configService.getConfig("PAY", getCurrentTenantId());
|
|
||||||
SettleInfo settleInfo = new SettleInfo();
|
|
||||||
settleInfo.setProfitSharing(config.getProfitSharingEnabled());
|
|
||||||
return settleInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getCurrentTenantId() {
|
private String getCurrentTenantId() {
|
||||||
return defaultTenantId;
|
return defaultTenantId;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user