From 299bc55db798b149e388c7181d4a95a188e0621c Mon Sep 17 00:00:00 2001 From: DB <2502523450@qq.com> Date: Wed, 15 Nov 2023 16:33:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=93=81=E7=89=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=95=86=E5=9F=8E=E5=BC=80=E5=90=AF=E7=AE=A1=E7=90=86?= =?UTF-8?q?;=E8=B0=83=E6=95=B4=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=8C=85=E5=AD=98=E6=94=BE=E4=BD=8D=E7=BD=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/handler/GlobalExceptionHandler.java | 6 +- .../json/StringToArraySerializer.java | 2 +- .../strategy/login/MiniLoginStrategy.java | 24 +++-- Cpop-Jambox/pom.xml | 5 + .../src/main/resources/application-dev.yml | 6 +- .../src/main/resources/application.yml | 1 + Cpop-Mall/pom.xml | 5 - .../service/impl/OrderServiceImpl.java | 15 ++- .../config/wxPay/WxPayConfiguration.java | 10 -- .../config/wxPay/WxPayProperties.java | 5 + .../src/main/resources/application-dev.yml | 12 ++- .../src/main/resources/application-prod.yml | 12 ++- .../src/main/resources/application-test.yml | 12 ++- .../src/main/resources/application.yml | 14 ++- .../business/controller/WxPayController.java | 95 +++++++++++++++++++ .../config/wxPay/WxPayConfiguration.java | 51 ++++++++++ .../config/wxPay/WxPayProperties.java | 78 +++++++++++++++ .../com/cpop/system/business/bo/BrandBo.java | 21 +--- .../business/bo/ChangeWechatSharingBo.java | 33 +++++++ .../cpop/system/business/entity/Brand.java | 20 +--- .../system/business/service/BrandService.java | 3 +- .../service/impl/BrandServiceImpl.java | 11 +-- .../cpop/system/business/vo/BrandPageVo.java | 6 ++ 23 files changed, 360 insertions(+), 87 deletions(-) create mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxPayController.java create mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayConfiguration.java create mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayProperties.java create mode 100644 Cpop-System/src/main/java/com/cpop/system/business/bo/ChangeWechatSharingBo.java diff --git a/Cpop-Core/src/main/java/com/cpop/core/handler/GlobalExceptionHandler.java b/Cpop-Core/src/main/java/com/cpop/core/handler/GlobalExceptionHandler.java index 635bc5c..0986737 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/handler/GlobalExceptionHandler.java +++ b/Cpop-Core/src/main/java/com/cpop/core/handler/GlobalExceptionHandler.java @@ -6,11 +6,16 @@ import com.cpop.common.enums.ErrorCodeEnum; import io.jsonwebtoken.JwtException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.core.MethodParameter; +import org.springframework.http.MediaType; +import org.springframework.http.server.ServerHttpRequest; +import org.springframework.http.server.ServerHttpResponse; import org.springframework.security.access.AccessDeniedException; import org.springframework.validation.BindException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; import javax.servlet.http.HttpServletRequest; import java.util.Objects; @@ -24,7 +29,6 @@ import java.util.Objects; public class GlobalExceptionHandler { private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); - /** * 业务异常 */ diff --git a/Cpop-Core/src/main/java/com/cpop/core/strategy/json/StringToArraySerializer.java b/Cpop-Core/src/main/java/com/cpop/core/strategy/json/StringToArraySerializer.java index 95043ad..d3d146b 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/strategy/json/StringToArraySerializer.java +++ b/Cpop-Core/src/main/java/com/cpop/core/strategy/json/StringToArraySerializer.java @@ -19,7 +19,7 @@ public class StringToArraySerializer extends JsonSerializer { @Override public void serialize(String str, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { - if (StringUtils.isNotBlank(str)) { + if (null != str) { String[] split = str.split(","); jsonGenerator.writeArray(split, 0, split.length); } diff --git a/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MiniLoginStrategy.java b/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MiniLoginStrategy.java index 3f88ca1..364539a 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MiniLoginStrategy.java +++ b/Cpop-Core/src/main/java/com/cpop/core/strategy/login/MiniLoginStrategy.java @@ -5,6 +5,7 @@ import com.cpop.core.base.entity.LoginUser; import com.cpop.core.base.entity.loginInfo.MiniUserLoginInfo; import com.cpop.core.base.enums.SourceType; import com.cpop.core.base.enums.UserType; +import com.cpop.core.base.exception.CpopAuthenticationException; import com.cpop.core.base.exception.ServiceException; import com.cpop.core.base.table.SysUser; import com.mybatisflex.core.row.Db; @@ -87,6 +88,19 @@ public class MiniLoginStrategy implements LoginStrategy { * @return: void */ private void changeJamboxUser(MiniUserLoginInfo loginInfo, Map credentials, SourceType sourceType) { + //获取品牌表 + Row brand = DbChain.table("cp_sys_brand") + .select("csb.id", "csb.is_open_sharing") + .from("cp_sys_brand").as("csb") + .leftJoin("cp_j_brand_extend").as("cjbe").on("cjbe.brand_id = csb.id") + .and("cjbe.brand_cloud_id = ?", credentials.get("brandId")) + .one(); + if (brand == null) { + throw new CpopAuthenticationException("用户登陆失败,果酱品牌暂未录入系统"); + } + if (!brand.getBoolean("isOpenSharing")){ + throw new CpopAuthenticationException("用户登陆失败,当前品牌暂未开通分账"); + } //构建用户信息 Row row = DbChain.table("cp_mini_user") .select("cmu.id","cmu.open_id","cmu.app_id","cmu.user_id","cmu.brand_id","cmu.nick_name","cmu.avatar","cmu.source_type") @@ -101,16 +115,6 @@ public class MiniLoginStrategy implements LoginStrategy { .and("cmu.is_delete = 0") .one(); if (row == null) { - //获取品牌表 - Row brand = DbChain.table("cp_sys_brand") - .select("csb.id") - .from("cp_sys_brand").as("csb") - .leftJoin("cp_j_brand_extend").as("cjbe").on("cjbe.brand_id = csb.id") - .and("cjbe.brand_cloud_id = ?", credentials.get("brandId")) - .one(); - if (brand == null) { - throw new ServiceException("用户登陆失败,果酱品牌暂未录入系统"); - } //保存小程序用户信息 LocalDateTime now = LocalDateTime.now(); Row miniUser = Row.ofKey(RowKey.SNOW_FLAKE_ID); diff --git a/Cpop-Jambox/pom.xml b/Cpop-Jambox/pom.xml index baea947..bb6d4e4 100644 --- a/Cpop-Jambox/pom.xml +++ b/Cpop-Jambox/pom.xml @@ -18,6 +18,11 @@ com.cpop Cpop-Core + + + com.github.binarywang + weixin-java-pay + diff --git a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml index b9865a8..0ee745f 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml +++ b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml @@ -115,11 +115,11 @@ mall: wx: pay: # p12证书的位置,可以指定绝对路径,也可以指定类路径(以classpath:开头) - keyPath: E:/Cpop/Cpop-Union/Cpop-Mall/Cpop-Mall-Web/src/main/resources/static/keyPair/wxPay_cert.p12 + keyPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_cert.p12 # 私钥证书 - privateKeyPath: E:/Cpop/Cpop-Union/Cpop-Mall/Cpop-Mall-Web/src/main/resources/static/keyPair/wxPay_key.pem + privateKeyPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_key.pem # 私钥文件 - privateCertPath: E:/Cpop/Cpop-Union/Cpop-Mall/Cpop-Mall-Web/src/main/resources/static/keyPair/wxPay_cert.pem + privateCertPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_cert.pem #支付通知地址 notifyUrl: https://frp-oak.top:11899/Cpop-Mall/wxPay/callback/notify/order #退款通知地址 diff --git a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml index fe5bc9e..dc2e707 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml +++ b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml @@ -139,3 +139,4 @@ wx: apiV3Key: JamBox20230919174000000000000002 #分账服务商账号 sharingAccount: 1618884922 + sharingAccountName: 果酱盒子 diff --git a/Cpop-Mall/pom.xml b/Cpop-Mall/pom.xml index 9b45910..a79fb39 100644 --- a/Cpop-Mall/pom.xml +++ b/Cpop-Mall/pom.xml @@ -27,11 +27,6 @@ com.cpop Cpop-Jambox - - - com.github.binarywang - weixin-java-pay - diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java index c8ef212..b8f3f9e 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java @@ -304,7 +304,8 @@ public class OrderServiceImpl extends ServiceImpl implements //查询是否是服务商系品牌 String brandId = loginUserInfo.getString("brandId"); Brand brand = SpringUtils.getBean(BrandService.class).getById(brandId); - if (StringUtils.isBlank(brand.getWxAppId()) || !StringUtils.equals(brand.getWxAppId(), wxPayService.getConfig().getAppId())) { + //需要分账 + if (order.getTotalAmount().scaleByPowerOfTen(2).intValue() >= 10) { //需要分账 orderRequest.setProfitSharing("Y"); } @@ -529,11 +530,9 @@ public class OrderServiceImpl extends ServiceImpl implements Order order = this.getById(orderId); //获取订单品牌信息 Brand brand = SpringUtils.getBean(BrandService.class).getById(order.getBrandId()); - if (StringUtils.isBlank(brand.getWxAppId()) || !StringUtils.equals(brand.getWxAppId(), wxPayService.getConfig().getAppId())) { - //需要分账 - if (notifyResult.getTotalFee() >= 10) { - wxPayAsyncTask.asyncWxPayProfitSharing(orderId, notifyResult, wxPayService); - } + //需要分账 + if (notifyResult.getTotalFee() >= 10) { + wxPayAsyncTask.asyncWxPayProfitSharing(orderId, notifyResult, wxPayService); } //异步更新 SpringUtils.getBean(ProductRecordSyncStockTask.class).asyncUpdateRecords(orderNumMap); @@ -639,7 +638,8 @@ public class OrderServiceImpl extends ServiceImpl implements //查询是否是服务商系品牌 String brandId = loginUserInfo.getString("brandId"); Brand brand = SpringUtils.getBean(BrandService.class).getById(brandId); - if (StringUtils.isBlank(brand.getWxAppId()) || !StringUtils.equals(brand.getWxAppId(), wxPayService.getConfig().getAppId())) { + //需要分账 + if (order.getTotalAmount().scaleByPowerOfTen(2).intValue() >= 10) { //需要分账 orderRequest.setProfitSharing("Y"); } @@ -653,7 +653,6 @@ public class OrderServiceImpl extends ServiceImpl implements //元转分 .setTotalFee(order.getTotalAmount().scaleByPowerOfTen(2).intValue()) .setTradeType("JSAPI"); - return wxPayService.createOrder(orderRequest); } else { return pointPay(recordNumIsEnough, order, loginUserInfo); diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayConfiguration.java b/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayConfiguration.java index 52e4e90..16a6fbe 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayConfiguration.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayConfiguration.java @@ -45,14 +45,4 @@ public class WxPayConfiguration { return wxPayService; } - - /** - * @descriptions 读取微信支付配置文件 - * @author DB - * @date 2023/11/01 17:27 - * @return: com.cpop.mall.framework.config.wxPay.WxPayProperties - */ - public WxPayProperties getProperties() { - return properties; - } } diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayProperties.java b/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayProperties.java index bd28bc5..e2899a8 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayProperties.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayProperties.java @@ -66,6 +66,11 @@ public class WxPayProperties { */ private String sharingAccount; + /** + * 分账账号名 + */ + private String sharingAccountName; + /** * 分账通知 */ diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml index 24aa6eb..08704ab 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml @@ -82,4 +82,14 @@ knife4j: group-name: Oam api-rule: package api-rule-resources: - - com.cpop.oam \ No newline at end of file + - com.cpop.oam + +#微信支付 +wx: + pay: + # p12证书的位置,可以指定绝对路径,也可以指定类路径(以classpath:开头) + keyPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_cert.p12 + # 私钥证书 + privateKeyPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_key.pem + # 私钥文件 + privateCertPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_cert.pem \ No newline at end of file diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-prod.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-prod.yml index f03b9f0..39ba9d0 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-prod.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-prod.yml @@ -62,4 +62,14 @@ mybatis-flex: jambox: url: jdbc:mysql://sh-cynosdbmysql-grp-fggo83js.sql.tencentcdb.com:20965/jambox_association?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true username: root - password: Customer0401 \ No newline at end of file + password: Customer0401 + +#微信支付 +wx: + pay: + # p12证书的位置,可以指定绝对路径,也可以指定类路径(以classpath:开头) + keyPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_cert.p12 + # 私钥证书 + privateKeyPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_key.pem + # 私钥文件 + privateCertPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_cert.pem \ No newline at end of file diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-test.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-test.yml index dfea3c3..6280a8a 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-test.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-test.yml @@ -83,4 +83,14 @@ knife4j: group-name: Oam api-rule: package api-rule-resources: - - com.cpop.oam \ No newline at end of file + - com.cpop.oam + +#微信支付 +wx: + pay: + # p12证书的位置,可以指定绝对路径,也可以指定类路径(以classpath:开头) + keyPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_cert.p12 + # 私钥证书 + privateKeyPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_key.pem + # 私钥文件 + privateCertPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_cert.pem \ No newline at end of file diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml index d08df99..d09bfc0 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml @@ -147,4 +147,16 @@ wx: componentSecret: fc2e9457aaa32342751cc655b5a1d273 componentToken: jambox componentAesKey: 1a3NBxmCFwkCJvfoQ7WhJHB6iX3qHPsc9JbaDznE1i0 - redirectUri: https://empower.oamapi.cpopsz.com/test/openPlatform/thirdPartyPlatform/redirectUrl \ No newline at end of file + redirectUri: https://empower.oamapi.cpopsz.com/test/openPlatform/thirdPartyPlatform/redirectUrl + #微信支付 + pay: + #微信公众号或者小程序等的appid + appId: wx20853d18c455e874 + #微信支付商户号 + mchId: 1618884922 + #微信支付商户密钥 + mchKey: JamBox20230919174000000000000002 + apiV3Key: JamBox20230919174000000000000002 + #分账服务商账号 + sharingAccount: 1618884922 + sharingAccountName: 果酱盒子 \ No newline at end of file diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxPayController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxPayController.java new file mode 100644 index 0000000..b640be8 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxPayController.java @@ -0,0 +1,95 @@ +package com.cpop.oam.business.controller; + +import com.alibaba.fastjson.JSONObject; +import com.cpop.common.utils.StringUtils; +import com.cpop.core.base.R; +import com.cpop.core.base.exception.ServiceException; +import com.cpop.oam.framework.config.wxPay.WxPayConfiguration; +import com.cpop.system.business.bo.ChangeWechatSharingBo; +import com.cpop.system.business.entity.Brand; +import com.cpop.system.business.service.BrandService; +import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingReceiverRequest; +import com.github.binarywang.wxpay.config.WxPayConfig; +import com.github.binarywang.wxpay.exception.WxPayException; +import com.github.binarywang.wxpay.service.WxPayService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.Map; + +import static com.cpop.system.business.entity.table.BrandTableDef.BRAND; + +/** + * @author DB + * @createTime 2023/11/15 11:21 + * @description + */ +@RestController +@Api(tags = "微信支付模块") +@RequestMapping("/wxPay") +public class WxPayController { + + @Autowired + private WxPayConfiguration wxPayConfiguration; + + @Autowired + private WxPayService wxPayService; + + @Autowired + private BrandService brandService; + + /** + * @descriptions 开通微信分账 + * @author DB + * @date 2023/11/15 11:06 + * @return: com.cpop.core.base.R + */ + @PreAuthorize("@aps.hasPermission('brandStore:brand:update')") + @ApiOperation("开通品牌商城") + @PutMapping("/changeBrandMall") + public R changeWechatSharing(@RequestBody @Validated ChangeWechatSharingBo bo) { + //获取品牌下属商户 + Brand brand = brandService.getById(bo.getBrandId()); + if (StringUtils.isBlank(brand.getWxMchId())) { + throw new ServiceException("当前品牌暂未绑定系统,请联系相关人员绑定"); + } + //固定商户信息 + Map mapReceiver = new HashMap<>(4); + mapReceiver.put("type", "MERCHANT_ID"); + mapReceiver.put("account", wxPayConfiguration.getProperties().getSharingAccount()); + //添加分账接收方 + ProfitSharingReceiverRequest profitSharingReceiver = new ProfitSharingReceiverRequest(); + //开启 + if (bo.getIsOpenMall()) { + mapReceiver.put("relation_type", "SERVICE_PROVIDER"); + mapReceiver.put("name", wxPayConfiguration.getProperties().getSharingAccountName()); + profitSharingReceiver.setReceiver(JSONObject.toJSONString(mapReceiver)); + WxPayConfig config = wxPayService.getConfig(); + + config.setSubMchId(brand.getWxMchId()); + try { + wxPayService.getProfitSharingService().addReceiver(profitSharingReceiver); + } catch (WxPayException e) { + throw new ServiceException(e.getMessage()); + } + } else { + //关闭 + profitSharingReceiver.setReceiver(JSONObject.toJSONString(mapReceiver)); + WxPayConfig config = wxPayService.getConfig(); + config.setSubMchId(brand.getWxMchId()); + try { + wxPayService.getProfitSharingService().removeReceiver(profitSharingReceiver); + } catch (WxPayException e) { + throw new ServiceException(e.getMessage()); + } + } + brandService.updateChain().set(BRAND.IS_OPEN_MALL, bo.getIsOpenMall()).where(BRAND.ID.eq(bo.getBrandId())).update(); + return R.ok(); + } +} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayConfiguration.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayConfiguration.java new file mode 100644 index 0000000..c7331dd --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayConfiguration.java @@ -0,0 +1,51 @@ +package com.cpop.oam.framework.config.wxPay; + +import com.cpop.common.utils.StringUtils; +import com.github.binarywang.wxpay.config.WxPayConfig; +import com.github.binarywang.wxpay.service.WxPayService; +import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; +import lombok.AllArgsConstructor; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author DB + * @Description: + * @create 2023-10-26 22:38 + */ +@Configuration +@ConditionalOnClass(WxPayService.class) +@EnableConfigurationProperties(WxPayProperties.class) +@AllArgsConstructor +public class WxPayConfiguration { + private WxPayProperties properties; + + @Bean + @ConditionalOnMissingBean + public WxPayService wxService() { + WxPayConfig payConfig = new WxPayConfig(); + payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId())); + payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId())); + payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey())); + //服务商模式微信支付 + payConfig.setApiV3Key(this.properties.getApiV3Key()); + payConfig.setCertSerialNo(this.properties.getCertSerialNo()); + payConfig.setKeyPath(this.properties.getKeyPath()); + payConfig.setPrivateKeyPath(this.properties.getPrivateKeyPath()); + payConfig.setPrivateCertPath(this.properties.getPrivateCertPath()); + //通知地址 + payConfig.setNotifyUrl(this.properties.getNotifyUrl()); + // 可以指定是否使用沙箱环境 + payConfig.setUseSandboxEnv(false); + WxPayService wxPayService = new WxPayServiceImpl(); + wxPayService.setConfig(payConfig); + return wxPayService; + } + + public WxPayProperties getProperties() { + return properties; + } +} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayProperties.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayProperties.java new file mode 100644 index 0000000..bc3755c --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayProperties.java @@ -0,0 +1,78 @@ +package com.cpop.oam.framework.config.wxPay; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * @author DB + * @Description: + * @create 2023-10-26 22:39 + */ +@Data +@ConfigurationProperties(prefix = "wx.pay") +public class WxPayProperties { + /** + * 设置微信公众号或者小程序等的appid + */ + private String appId; + + /** + * 微信支付商户号 + */ + private String mchId; + + /** + * 微信支付商户密钥 + */ + private String mchKey; + + /** + * apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定 + */ + private String keyPath; + + /** + * apiV3 秘钥值 + */ + private String apiV3Key; + + /** + * apiclient_key.pem证书文件的绝对路径或者以classpath:开头的类路径 + */ + private String privateKeyPath; + + /** + * apiclient_cert.pem证书文件的绝对路径或者以classpath:开头的类路径 + */ + private String privateCertPath; + + /** + * apiV3 证书序列号值 + */ + private String certSerialNo; + + /** + * 支付通知地址 + */ + private String notifyUrl; + + /** + * 退款通知 + */ + private String notifyRefund; + + /** + * 分账账号 + */ + private String sharingAccount; + + /** + * 分账账号名 + */ + private String sharingAccountName; + + /** + * 分账通知 + */ + private String notifySharing; +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandBo.java b/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandBo.java index af0973b..7390aa3 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandBo.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/bo/BrandBo.java @@ -33,28 +33,9 @@ public class BrandBo { /** * 微信商户号 */ - @NotBlank(message = "商户号不能为空") - @ApiModelProperty(value = "微信商户号",required = true) + @ApiModelProperty(value = "微信商户号") private String wxMchId; - /** - * 微信Appid - */ - @ApiModelProperty("微信Appid") - private String wxAppId; - - /** - * 微信支付密钥 - */ - @ApiModelProperty("微信支付密钥") - private String wxMchKey; - - /** - * 微信支付keypath - */ - @ApiModelProperty("微信支付keypath") - private String wxKeyPath; - /** * 背景图 */ diff --git a/Cpop-System/src/main/java/com/cpop/system/business/bo/ChangeWechatSharingBo.java b/Cpop-System/src/main/java/com/cpop/system/business/bo/ChangeWechatSharingBo.java new file mode 100644 index 0000000..b687581 --- /dev/null +++ b/Cpop-System/src/main/java/com/cpop/system/business/bo/ChangeWechatSharingBo.java @@ -0,0 +1,33 @@ +package com.cpop.system.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * @author DB + * @createTime 2023/11/15 11:52 + * @description + */ +@Data +@ApiModel(value = "微信分账相关参数") +public class ChangeWechatSharingBo implements Serializable { + + /** + * 品牌id + */ + @NotBlank(message = "不能为空") + @ApiModelProperty(value = "品牌id",required = true) + private String brandId; + + /** + * 是否开启分账 + */ + @NotNull(message = "是否开启商城不能为空") + @ApiModelProperty(value = "是否开启商城",required = true) + private Boolean isOpenMall; +} diff --git a/Cpop-System/src/main/java/com/cpop/system/business/entity/Brand.java b/Cpop-System/src/main/java/com/cpop/system/business/entity/Brand.java index e09d229..e016198 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/entity/Brand.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/entity/Brand.java @@ -40,26 +40,11 @@ public class Brand extends BaseEntity implements Serializable { */ private String brandName; - /** - * 微信appid - */ - private String wxAppId; - /** * 微信商户号 */ private String wxMchId; - /** - * 微信支付密钥 - */ - private String wxMchKey; - - /** - * 微信支付keypath - */ - private String wxKeyPath; - /** * 数据来源 */ @@ -70,6 +55,11 @@ public class Brand extends BaseEntity implements Serializable { */ private String backgroundUrl; + /** + * 是否开通商城 + */ + private Boolean isOpenMall; + /** * 逻辑删除(0否1是) */ diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/BrandService.java b/Cpop-System/src/main/java/com/cpop/system/business/service/BrandService.java index 1eb4a0a..00aebfd 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/service/BrandService.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/BrandService.java @@ -26,7 +26,7 @@ public interface BrandService extends IService { * @descriptions 查询品牌分页列表 * @author DB * @date 2023/10/25 17:32 - * @param bo 请求参数 + * @param brandName 请求参数 * @return: com.mybatisflex.core.paginate.Page */ Page getBrandPage(String brandName); @@ -39,4 +39,5 @@ public interface BrandService extends IService { * @return: void */ void removeBrandById(String id); + } diff --git a/Cpop-System/src/main/java/com/cpop/system/business/service/impl/BrandServiceImpl.java b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/BrandServiceImpl.java index eaffe89..8b380b5 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/service/impl/BrandServiceImpl.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/service/impl/BrandServiceImpl.java @@ -1,7 +1,6 @@ package com.cpop.system.business.service.impl; import com.cpop.common.utils.StringUtils; -import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.base.entity.LoginUser; import com.cpop.core.base.entity.PageDomain; import com.cpop.core.base.enums.SourceType; @@ -24,10 +23,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import static com.cpop.system.business.entity.table.BrandTableDef.BRAND; @@ -76,10 +72,7 @@ public class BrandServiceImpl extends ServiceImpl implements } Brand sysBrand = new Brand(); sysBrand.setBrandName(brand.getString("name")) - .setWxAppId(brand.getString("appid")) .setWxMchId(brand.getString("wxMchId")) - .setWxMchKey(brand.getString("wxMchKey")) - .setWxKeyPath(brand.getString("wxKeyPath")) .setBackgroundUrl(brand.getString("brandBg")) .setSourceType(SourceType.JAMBOX.toString()); this.save(sysBrand); @@ -159,7 +152,7 @@ public class BrandServiceImpl extends ServiceImpl implements PageDomain pageDomain = SqlUtils.getInstance().getPageDomain(); return this.mapper.paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), QueryWrapper.create() - .select(BRAND.ID, BRAND.BRAND_NAME, BRAND.WX_MCH_ID, BRAND.CREATE_TIME, BRAND.BACKGROUND_URL, BRAND.WX_APP_ID, BRAND.WX_MCH_KEY, BRAND.WX_KEY_PATH) + .select(BRAND.ID, BRAND.BRAND_NAME, BRAND.WX_MCH_ID, BRAND.CREATE_TIME, BRAND.BACKGROUND_URL, BRAND.IS_OPEN_MALL) .and(BRAND.BRAND_NAME.like(brandName)), BrandPageVo.class); } diff --git a/Cpop-System/src/main/java/com/cpop/system/business/vo/BrandPageVo.java b/Cpop-System/src/main/java/com/cpop/system/business/vo/BrandPageVo.java index 47d9917..947e39e 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/vo/BrandPageVo.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/vo/BrandPageVo.java @@ -65,6 +65,12 @@ public class BrandPageVo implements Serializable { @ApiModelProperty("背景图") private String backgroundUrl; + /** + * 是否开通微信分账 + */ + @ApiModelProperty("是否开通微信分账") + private Boolean isOpenSharing; + /** * 创建时间 */