From 186feb98da8ac01643cc9ab855b741efaf103608 Mon Sep 17 00:00:00 2001 From: Loki <654612@qq.com> Date: Fri, 6 May 2022 21:09:40 +0800 Subject: [PATCH] fix --- ...ultiUserDetailsAuthenticationProvider.java | 1 + .../rest/controller/WechatController.java | 43 +++++++++++-------- .../modules/mp/config/WxPayConfiguration.java | 5 ++- .../modules/mp/service/WeixinPayService.java | 5 ++- .../java/co/yixiang/utils/ShopKeyUtils.java | 9 ++-- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/authentication/MultiUserDetailsAuthenticationProvider.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/authentication/MultiUserDetailsAuthenticationProvider.java index 7e6f237e..972c3408 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/authentication/MultiUserDetailsAuthenticationProvider.java +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/authentication/MultiUserDetailsAuthenticationProvider.java @@ -143,6 +143,7 @@ public class MultiUserDetailsAuthenticationProvider extends AbstractUserDetailsA if (request.getRequestURI().startsWith(properties.getAdminApi().getPrefix()) || request.getRequestURI().startsWith("/common/") || request.getRequestURI().startsWith("/bxg") + || request.getRequestURI().startsWith("/api/upload") ) { return UserTypeEnum.ADMIN; } diff --git a/zsw-bxg/src/main/java/co/yixiang/app/modules/wechat/rest/controller/WechatController.java b/zsw-bxg/src/main/java/co/yixiang/app/modules/wechat/rest/controller/WechatController.java index ceebcc46..56fed21e 100644 --- a/zsw-bxg/src/main/java/co/yixiang/app/modules/wechat/rest/controller/WechatController.java +++ b/zsw-bxg/src/main/java/co/yixiang/app/modules/wechat/rest/controller/WechatController.java @@ -9,6 +9,7 @@ package co.yixiang.app.modules.wechat.rest.controller; import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import co.yixiang.annotation.AnonymousAccess; import cn.iocoder.yudao.framework.common.pojo.ApiResult; import co.yixiang.constant.SystemConfigConstants; @@ -45,11 +46,7 @@ import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -95,9 +92,10 @@ public class WechatController { /** * jssdk配置 */ - @GetMapping("/wechat/config") + @GetMapping("/wechat/config/{tenantCode}") @ApiOperation(value = "jssdk配置",notes = "jssdk配置") - public ApiResult> jsConfig(HttpServletRequest request) throws WxErrorException { + public ApiResult> jsConfig(HttpServletRequest request,@PathVariable String tenantCode) throws WxErrorException { + TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); WxMpService wxService = WxMpConfiguration.getWxMpService(); String url = request.getParameter("url"); log.info("url:"+url); @@ -118,14 +116,15 @@ public class WechatController { /** * 微信小程序接口能力配置 */ - @GetMapping("/wxapp/config") + @GetMapping("/wxapp/config/{tenantCode}") @ApiOperation(value = "微信小程序接口能力配置",notes = "微信小程序接口能力配置",produces = "text/plain;charset=utf-8") public String wxAppConfig(@RequestParam(value = "signature") String signature, @RequestParam(value = "timestamp") String timestamp, @RequestParam(value = "nonce") String nonce, + @PathVariable String tenantCode, @RequestParam(name = "echostr", required = false) String echostr) throws WxErrorException { + TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); WxMaService wxService = WxMaConfiguration.getWxMaService(); - if( wxService.checkSignature(timestamp,nonce,signature)){ return echostr; } @@ -136,9 +135,11 @@ public class WechatController { * 微信支付/充值回调 */ @AnonymousAccess - @PostMapping("/wechat/notify") + @PostMapping("/wechat/notify/{tenantCode}") @ApiOperation(value = "微信支付充值回调",notes = "微信支付充值回调") - public String renotify(@RequestBody String xmlData) { + public String renotify(@RequestBody String xmlData, @PathVariable String tenantCode) { + log.info("tenantCode:{}",tenantCode); + TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); try { WxPayService wxPayService = WxPayConfiguration.getPayService(PayMethodEnum.WECHAT); if(wxPayService == null) { @@ -174,6 +175,7 @@ public class WechatController { return WxPayNotifyResponse.success("处理成功!"); } catch (WxPayException e) { + e.printStackTrace(); log.error(e.getMessage()); return WxPayNotifyResponse.fail(e.getMessage()); } @@ -184,8 +186,10 @@ public class WechatController { * 微信退款回调 */ @ApiOperation(value = "退款回调通知处理",notes = "退款回调通知处理") - @PostMapping("/notify/refund") - public String parseRefundNotifyResult(@RequestBody String xmlData) { + @PostMapping("/notify/refund/{tenantCode}") + public String parseRefundNotifyResult(@RequestBody String xmlData,@PathVariable String tenantCode) { + log.info("tenantCode:{}",tenantCode); + TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); try { WxPayService wxPayService = WxPayConfiguration.getPayService(PayMethodEnum.WECHAT); if(wxPayService == null) { @@ -225,13 +229,15 @@ public class WechatController { /** * 微信验证消息 */ - @GetMapping( value = "/wechat/serve",produces = "text/plain;charset=utf-8") + @GetMapping( value = "/wechat/serve/{tenantCode}",produces = "text/plain;charset=utf-8") @ApiOperation(value = "微信验证消息",notes = "微信验证消息") public String authGet(@RequestParam(name = "signature", required = false) String signature, @RequestParam(name = "timestamp", required = false) String timestamp, @RequestParam(name = "nonce", required = false) String nonce, - @RequestParam(name = "echostr", required = false) String echostr){ - + @RequestParam(name = "echostr", required = false) String echostr, + @PathVariable String tenantCode + ){ + TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); final WxMpService wxService = WxMpConfiguration.getWxMpService(); if (wxService == null) { throw new IllegalArgumentException("未找到对应配置的服务,请核实!"); @@ -247,7 +253,7 @@ public class WechatController { /** *微信获取消息 */ - @PostMapping("/wechat/serve") + @PostMapping("/wechat/serve/{tenantCode}") @ApiOperation(value = "微信获取消息",notes = "微信获取消息") public void post(@RequestBody String requestBody, @RequestParam("signature") String signature, @@ -256,11 +262,12 @@ public class WechatController { @RequestParam("openid") String openid, @RequestParam(name = "encrypt_type", required = false) String encType, @RequestParam(name = "msg_signature", required = false) String msgSignature, + @PathVariable String tenantCode, HttpServletRequest request, HttpServletResponse response) throws IOException { + TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); WxMpService wxService = WxMpConfiguration.getWxMpService(); - if (!wxService.checkSignature(timestamp, nonce, signature)) { throw new IllegalArgumentException("非法请求,可能属于伪造的请求!"); } diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/mp/config/WxPayConfiguration.java b/zsw-bxg/src/main/java/co/yixiang/modules/mp/config/WxPayConfiguration.java index 4e86e438..2dde2ace 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/mp/config/WxPayConfiguration.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/mp/config/WxPayConfiguration.java @@ -42,7 +42,8 @@ public class WxPayConfiguration { * @return */ public static WxPayService getPayService(PayMethodEnum payMethodEnum) { - WxPayService wxPayService = payServices.get(ShopKeyUtils.getYshopWeiXinPayService()+payMethodEnum.getValue()); + String payKey = ShopKeyUtils.getYshopWeiXinPayService() +":"+ payMethodEnum.getValue(); + WxPayService wxPayService = payServices.get(payKey); if(wxPayService == null || redisUtils.get(ShopKeyUtils.getYshopWeiXinPayService()) == null) { WxPayConfig payConfig = new WxPayConfig(); switch (payMethodEnum){ @@ -64,7 +65,7 @@ public class WxPayConfiguration { payConfig.setUseSandboxEnv(false); wxPayService = new WxPayServiceImpl(); wxPayService.setConfig(payConfig); - payServices.put(ShopKeyUtils.getYshopWeiXinPayService()+payMethodEnum.getValue(), wxPayService); + payServices.put(payKey, wxPayService); //增加标识 redisUtils.set(ShopKeyUtils.getYshopWeiXinPayService(),"yshop"); diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/mp/service/WeixinPayService.java b/zsw-bxg/src/main/java/co/yixiang/modules/mp/service/WeixinPayService.java index 23c9ecd1..ea0856af 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/mp/service/WeixinPayService.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/mp/service/WeixinPayService.java @@ -11,6 +11,7 @@ import cn.hutool.core.lang.UUID; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import co.yixiang.api.BusinessException; import cn.iocoder.yudao.framework.common.exception.YshopException; import co.yixiang.enums.AppFromEnum; @@ -125,7 +126,7 @@ public class WeixinPayService { orderRequest.setOutTradeNo(orderId); orderRequest.setTotalFee(payPrice); orderRequest.setSpbillCreateIp(IpUtil.getLocalIP()); - orderRequest.setNotifyUrl(this.getApiUrl() + "/xiaohuiapp/wechat/notify"); + orderRequest.setNotifyUrl(this.getApiUrl() + "/bxgApp/wechat/notify/"+ TenantContextHolder.getTenantId().toString()); orderRequest.setBody(body); orderRequest.setAttach(attach); @@ -183,7 +184,7 @@ public class WeixinPayService { wxPayRefundRequest.setOutRefundNo(orderSn); //退款金额 wxPayRefundRequest.setRefundFee(refundFee); - wxPayRefundRequest.setNotifyUrl(this.getApiUrl() + "/xiaohuiapp/notify/refund"); + wxPayRefundRequest.setNotifyUrl(this.getApiUrl() + "/bxgApp/notify/refund/"+ TenantContextHolder.getTenantId().toString()); try { wxPayService.refundV2(wxPayRefundRequest); } catch (WxPayException e) { diff --git a/zsw-bxg/src/main/java/co/yixiang/utils/ShopKeyUtils.java b/zsw-bxg/src/main/java/co/yixiang/utils/ShopKeyUtils.java index c59c155f..9e1f764f 100644 --- a/zsw-bxg/src/main/java/co/yixiang/utils/ShopKeyUtils.java +++ b/zsw-bxg/src/main/java/co/yixiang/utils/ShopKeyUtils.java @@ -1,5 +1,6 @@ package co.yixiang.utils; +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import co.yixiang.constant.ShopConstants; import co.yixiang.constant.SystemConfigConstants; @@ -92,7 +93,7 @@ public class ShopKeyUtils { * 微信支付service */ public static String getYshopWeiXinPayService(){ - String yshopWeiXinPayService= ShopConstants.ZSW_WEIXIN_PAY_SERVICE; + String yshopWeiXinPayService= TenantContextHolder.getTenantId().toString() + ":"+ShopConstants.ZSW_WEIXIN_PAY_SERVICE; return yshopWeiXinPayService+getExtendValue(); } /** @@ -120,14 +121,14 @@ public class ShopKeyUtils { * 微信支付小程序service */ public static String getYshopWeiXinMiniPayService(){ - String yshopWeiXinMiniPayService= ShopConstants.ZSW_WEIXIN_MINI_PAY_SERVICE; + String yshopWeiXinMiniPayService= TenantContextHolder.getTenantId().toString() + ":" + ShopConstants.ZSW_WEIXIN_MINI_PAY_SERVICE; return yshopWeiXinMiniPayService+getExtendValue(); } /** * 微信支付app service */ public static String getYshopWeiXinAppPayService(){ - String yshopWeiXinAppPayService= ShopConstants.ZSW_WEIXIN_APP_PAY_SERVICE; + String yshopWeiXinAppPayService= TenantContextHolder.getTenantId().toString() + ":" + ShopConstants.ZSW_WEIXIN_APP_PAY_SERVICE; return yshopWeiXinAppPayService+getExtendValue(); } /** @@ -173,7 +174,7 @@ public class ShopKeyUtils { * @return */ public static String getYshopWeiXinMaSevice() { - String yshopWeiXinMaSevice= ShopConstants.ZSW_WEIXIN_MA_SERVICE; + String yshopWeiXinMaSevice= TenantContextHolder.getTenantId().toString() + ":" + ShopConstants.ZSW_WEIXIN_MA_SERVICE; return yshopWeiXinMaSevice+getExtendValue(); }