|
|
@@ -1,13 +1,16 @@
|
|
|
package com.fs.app.controller.store;
|
|
|
|
|
|
|
|
|
+import com.fs.common.config.RedisTenantContext;
|
|
|
import com.fs.common.core.controller.BaseController;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
-import com.fs.course.service.IFsCourseRedPacketLogService;
|
|
|
+import com.fs.framework.datasource.DynamicDataSourceContextHolder;
|
|
|
+import com.fs.framework.datasource.TenantDataSourceManager;
|
|
|
import com.fs.hisStore.param.WxSendRedPacketParam;
|
|
|
import com.fs.hisStore.service.*;
|
|
|
import com.fs.sop.service.ISopUserLogsInfoService;
|
|
|
-import com.fs.system.service.ISysConfigService;
|
|
|
+import com.fs.tenant.domain.TenantInfo;
|
|
|
+import com.fs.tenant.service.TenantInfoService;
|
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
@@ -17,8 +20,6 @@ import org.apache.commons.io.IOUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.ApplicationEventPublisher;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@@ -36,22 +37,15 @@ public class WxPayScrmController {
|
|
|
@Autowired
|
|
|
private IFsStoreOrderScrmService orderService;
|
|
|
@Autowired
|
|
|
- private IFsStoreOrderStatusScrmService orderStatusService;
|
|
|
- @Autowired
|
|
|
- private IFsUserBillScrmService billService;
|
|
|
- @Autowired
|
|
|
- private IFsUserScrmService userService;
|
|
|
- @Autowired
|
|
|
- private ApplicationEventPublisher publisher;
|
|
|
- @Autowired
|
|
|
private IFsStorePaymentScrmService storePaymentService;
|
|
|
|
|
|
@Autowired
|
|
|
- private IFsCourseRedPacketLogService redPacketLogService;
|
|
|
+ private ISopUserLogsInfoService iSopUserLogsInfoService;
|
|
|
@Autowired
|
|
|
- private ISysConfigService configService;
|
|
|
+ private TenantInfoService tenantInfoService;
|
|
|
@Autowired
|
|
|
- private ISopUserLogsInfoService iSopUserLogsInfoService;
|
|
|
+ private TenantDataSourceManager tenantDataSourceManager;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 微信回调
|
|
|
@@ -61,21 +55,34 @@ public class WxPayScrmController {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@ApiOperation("微信回调")
|
|
|
- @PostMapping("/wxPayNotify")
|
|
|
- @Transactional
|
|
|
- public String wxPayNotify(HttpServletRequest request) throws Exception {
|
|
|
+ @PostMapping({"/wxPayNotify", "/wxPayNotify/{tenantCode}"})
|
|
|
+ public String wxPayNotify(@PathVariable(value = "tenantCode", required = false) String tenantCode,
|
|
|
+ HttpServletRequest request) throws Exception {
|
|
|
logger.info("====================进入微信回调接口===================");
|
|
|
+ boolean switched = false;
|
|
|
try {
|
|
|
+ if (tenantCode != null && !tenantCode.isEmpty()) {
|
|
|
+ TenantInfo tenant = tenantInfoService.selectTenantInfoByCode(tenantCode);
|
|
|
+ if (tenant != null) {
|
|
|
+ tenantDataSourceManager.switchTenant(tenant);
|
|
|
+ RedisTenantContext.setTenantId(tenant.getId());
|
|
|
+ switched = true;
|
|
|
+ logger.info("微信回调切库成功: tenantCode={}, tenantId={}", tenantCode, tenant.getId());
|
|
|
+ } else {
|
|
|
+ logger.error("微信回调切库失败-租户不存在: tenantCode={}", tenantCode);
|
|
|
+ return WxPayNotifyResponse.fail("租户不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
|
|
|
logger.info("xml result:{}", xmlResult);
|
|
|
WxPayOrderNotifyResult result = wxPayService.parseOrderNotifyResult(xmlResult,"MD5");
|
|
|
- System.out.println(result.getReturnCode());
|
|
|
+// WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlResult);
|
|
|
+// logger.info("微信回调结果:{}", result);
|
|
|
if("SUCCESS".equals(result.getReturnCode())){
|
|
|
//订单号
|
|
|
String outtradeno = result.getOutTradeNo();
|
|
|
String tradeNo = result.getTransactionId();
|
|
|
- System.out.println(outtradeno);
|
|
|
- System.out.println(tradeNo);
|
|
|
String[] orderId=outtradeno.split("-");
|
|
|
switch (orderId[0]){
|
|
|
case "store":
|
|
|
@@ -96,6 +103,13 @@ public class WxPayScrmController {
|
|
|
} catch (Exception e) {
|
|
|
logger.error("微信回调结果异常,异常原因{}", e.getMessage());
|
|
|
return WxPayNotifyResponse.fail(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (switched) {
|
|
|
+ RedisTenantContext.clear();
|
|
|
+ tenantDataSourceManager.clear();
|
|
|
+ DynamicDataSourceContextHolder.clearDataSourceType();
|
|
|
+ logger.info("微信回调清理租户上下文完成");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|