diff --git a/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java b/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java index 5250860..c770306 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java +++ b/Cpop-Core/src/main/java/com/cpop/core/service/impl/CoreServiceImpl.java @@ -1,10 +1,7 @@ package com.cpop.core.service.impl; -import com.cpop.common.constant.Constants; -import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.abstracts.AbstractLoginInfoBuild; import com.cpop.core.base.entity.LoginUser; -import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo; import com.cpop.core.base.enums.OperationLogEnum; import com.cpop.core.base.enums.UserType; import com.cpop.core.base.exception.ServiceException; @@ -16,16 +13,14 @@ import com.cpop.core.service.CoreService; import com.cpop.core.utils.MessageUtils; import com.cpop.core.utils.SecurityUtils; import com.cpop.core.utils.uuid.IdUtils; -import com.mybatisflex.core.row.DbChain; -import com.mybatisflex.core.row.Row; -import com.mybatisflex.core.row.RowUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; -import java.util.stream.Collectors; +import java.util.Arrays; +import java.util.List; +import java.util.Map; /** * @author DB @@ -237,6 +232,7 @@ public class CoreServiceImpl implements CoreService { * @return 登陆用户 */ @Override + @Transactional(rollbackFor = Exception.class) public LoginUser loadUserByPhone(String phoneNumber, UserType userType, Map credentials) { //统一获取系统用户信息 SysUser sysUser = this.getSysUserByPhone(phoneNumber, userType); 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 31e445f..da63733 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 @@ -4,7 +4,7 @@ cpop: profile: E:/Cpop/uploadPath jwt: #白名单 - whiteList: /login,/getCaptcha,/profile/**,/doc.html,/webjars/**,/favicon.ico,/v2/api-docs/**,/swagger-resources + whiteList: /login,/miniLogin,/getCaptcha,/profile/**,/doc.html,/webjars/**,/favicon.ico,/v2/api-docs/**,/swagger-resources gateway: rsa-keypair: # 公钥文件 diff --git a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-test.yml b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-test.yml index af16e46..3a09102 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-test.yml +++ b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-test.yml @@ -4,23 +4,19 @@ cpop: profile: /root/jambox-union/jambox-oam/uploadPath/upload jwt: #白名单 - whiteList: /login,/getCaptcha,/profile/**,/doc.html,/webjars/**,/favicon.ico,/v2/api-docs/**,/swagger-resources,/wxOpen/receiveTicket,/wxOpen/*/callback,/wxOpen/bindOpenAccount/*,/wxCp/portal/* + whiteList: /login,/miniLogin,/getCaptcha,/profile/**,/doc.html,/webjars/**,/favicon.ico,/v2/api-docs/**,/swagger-resources,/wxOpen/receiveTicket,/wxOpen/*/callback,/wxOpen/bindOpenAccount/*,/wxCp/portal/* #拦截 gateway: rsa-keypair: # 公钥文件 - publicKeyFile: /root/jambox-union/jambox-oam/script/secretKey/publicKey + publicKeyFile: D:\WorkSpace\Cpop\Cpop-Union\Cpop-Mall\Cpop-Mall-Web\src\main\resources\static\keyPair\publicKey # 公钥文件 - privateKeyFile: /root/jambox-union/jambox-oam/script/secretKey/privateKey + privateKeyFile: D:\WorkSpace\Cpop\Cpop-Union\Cpop-Mall\Cpop-Mall-Web\src\main\resources\static\keyPair\privateKey # DataSource Config spring: application: name: Cpop-Mall-Test - datasource: - url: jdbc:mysql://sh-cynosdbmysql-grp-fggo83js.sql.tencentcdb.com:20965/cpop-union?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 - username: root - password: Customer0401 #redis配置 redis: #地址 @@ -28,7 +24,7 @@ spring: #端口 port: 6333 #数据库 - database: 5 + database: 10 #密码 password: Jambox.123* #连接超时 @@ -60,7 +56,7 @@ mybatis-flex: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl datasource: mall: - url: jdbc:mysql://sh-cynosdbmysql-grp-fggo83js.sql.tencentcdb.com:20965/cpop-union?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + url: jdbc:mysql://sh-cynosdbmysql-grp-fggo83js.sql.tencentcdb.com:20965/cpop_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: Customer0401 jambox: 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 da158ba..4df2e6c 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml +++ b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml @@ -31,7 +31,7 @@ spring: max-file-size: 1024MB max-request-size: 300MB profiles: - active: dev,mall,system,jambox,sdk + active: test,mall,system,jambox,sdk datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver @@ -124,4 +124,19 @@ xss: logging: level: #swagger日志 - springfox: error \ No newline at end of file + springfox: error + +#微信 +wx: + #微信支付 + pay: + #服务商模式 + #微信公众号或者小程序等的appid + appId: wx1eb0e5fb7dac3c05 + #微信支付商户号 + mchId: 1618884922 + #微信支付商户密钥 + mchKey: JamBox20230919174000000000000002 + apiV3Key: JamBox20230919174000000000000002 + # p12证书的位置,可以指定绝对路径,也可以指定类路径(以classpath:开头) + keyPath: diff --git a/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopMallWebApplicationTests.java b/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopMallWebApplicationTests.java index c2d5657..c96a3de 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopMallWebApplicationTests.java +++ b/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopMallWebApplicationTests.java @@ -1,13 +1,50 @@ package com.cpop.mall.web; +import com.cpop.core.service.CoreService; +import com.cpop.core.utils.RsaUtils; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.util.Map; + @SpringBootTest class CpopMallWebApplicationTests { + @Autowired + private CoreService coreService; + + @Autowired + private RsaUtils rsaUtils; + @Test void contextLoads() { } + /** + * 初始化密钥对 + */ + @Test + public void initKeyPair() { + Map keyPairMap = rsaUtils.initKeyPair(); + String publicKey = keyPairMap.get("publicKey"); + String privateKey = keyPairMap.get("privateKey"); + System.out.println("公钥:"); + System.out.println(publicKey); + System.out.println(); + System.out.println("私钥:"); + System.out.println(privateKey); + System.out.println(); + String source = "Admin@123"; + System.out.println("待加密字符串:"+source); + System.out.println(); + String strEncrypt = rsaUtils.encrypt(source); + System.out.println("加密后的字符串:"); + System.out.println(strEncrypt); + System.out.println(); + String strDecrypt = rsaUtils.decrypt(strEncrypt); + System.out.println("解密后的字符串:"); + System.out.println(strDecrypt); + } + } diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/PlaceOrderBo.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/PlaceOrderBo.java index 7c82f68..2ca8e7c 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/PlaceOrderBo.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/PlaceOrderBo.java @@ -52,6 +52,7 @@ public class PlaceOrderBo implements Serializable { /** * 店铺(校区)id */ + @NotBlank(message = "店铺(校区)id不能为空") @ApiModelProperty("店铺(校区)id") private String storeId; diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/backstage/BackstageProductController.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/backstage/BackstageProductController.java index 637bd9c..d5cd865 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/backstage/BackstageProductController.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/backstage/BackstageProductController.java @@ -2,29 +2,23 @@ package com.cpop.mall.business.controller.backstage; import com.cpop.core.base.R; import com.cpop.core.utils.SpringUtils; -import com.cpop.jambox.business.entity.CardTemplate; import com.cpop.jambox.business.vo.CardTemplateListVo; import com.cpop.mall.business.bo.ProductBo; import com.cpop.mall.business.bo.ProductPageBo; import com.cpop.mall.business.service.ProductRecordService; +import com.cpop.mall.business.service.ProductService; import com.cpop.mall.business.service.ProductSpecificationService; import com.cpop.mall.business.vo.ProductPageVo; +import com.cpop.mall.business.vo.StoreListVo; import com.mybatisflex.core.paginate.Page; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.beans.factory.annotation.Autowired; -import com.cpop.mall.business.service.ProductService; -import org.springframework.web.bind.annotation.RestController; 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.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + import java.io.Serializable; import java.util.List; @@ -59,6 +53,19 @@ public class BackstageProductController { return R.ok(page); } + /** + * @descriptions 下单需要选择店铺/校区 + * @author DB + * @date 2023/10/23 11:56 + * @return: com.cpop.core.base.R> + */ + @GetMapping("/getStoreList") + @ApiOperation("选择品牌下的店铺/校区") + public R> getStoreList() { + List list = productService.getStoreList(); + return R.ok(list); + } + /** * @descriptions 获取果酱课卡模板 * @author DB diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/mini/MiniProductController.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/mini/MiniProductController.java index ee38f34..67c9b81 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/mini/MiniProductController.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/mini/MiniProductController.java @@ -1,14 +1,8 @@ package com.cpop.mall.business.controller.mini; import com.cpop.core.base.R; -import com.cpop.core.utils.SpringUtils; -import com.cpop.jambox.business.vo.CardTemplateListVo; -import com.cpop.mall.business.bo.PlaceOrderBo; -import com.cpop.mall.business.bo.ProductBo; import com.cpop.mall.business.bo.ProductPageBo; -import com.cpop.mall.business.service.ProductRecordService; import com.cpop.mall.business.service.ProductService; -import com.cpop.mall.business.service.ProductSpecificationService; import com.cpop.mall.business.vo.ProductEvaluateVo; import com.cpop.mall.business.vo.ProductPageVo; import com.cpop.mall.business.vo.StoreListVo; @@ -17,16 +11,13 @@ 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.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; -import java.io.Serializable; import java.util.List; -import static com.cpop.mall.business.entity.table.ProductRecordTableDef.PRODUCT_RECORD; -import static com.cpop.mall.business.entity.table.ProductSpecificationTableDef.PRODUCT_SPECIFICATION; - /** * 商城-商品表 控制层。 * @@ -61,10 +52,10 @@ public class MiniProductController { * @date 2023/10/23 11:56 * @return: com.cpop.core.base.R> */ - @GetMapping("/paySelectStore") + @GetMapping("/getStoreList") @ApiOperation("下单需要选择店铺/校区") - public R> paySelectStore() { - List list = productService.paySelectStore(); + public R> getStoreList() { + List list = productService.getStoreList(); return R.ok(list); } diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/ProductService.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/ProductService.java index afe6787..54818d9 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/ProductService.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/ProductService.java @@ -1,15 +1,14 @@ package com.cpop.mall.business.service; -import com.cpop.jambox.business.entity.CardTemplate; import com.cpop.jambox.business.vo.CardTemplateListVo; import com.cpop.mall.business.bo.ProductBo; import com.cpop.mall.business.bo.ProductPageBo; +import com.cpop.mall.business.entity.Product; import com.cpop.mall.business.vo.ProductEvaluateVo; import com.cpop.mall.business.vo.ProductPageVo; import com.cpop.mall.business.vo.StoreListVo; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.service.IService; -import com.cpop.mall.business.entity.Product; import java.util.List; @@ -81,7 +80,7 @@ public interface ProductService extends IService { * @date 2023/10/26 15:34 * @return: java.util.List */ - List paySelectStore(); + List getStoreList(); /** * @descriptions 查询商品评价分页列表 diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/ProductServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/ProductServiceImpl.java index 1463ea0..ce2bdd4 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/ProductServiceImpl.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/ProductServiceImpl.java @@ -5,7 +5,6 @@ import com.cpop.common.utils.StringUtils; import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.base.entity.PageDomain; import com.cpop.core.base.enums.SourceType; -import com.cpop.core.gateway.miniProgram.MiniUserLoginInfoBuild; import com.cpop.core.utils.SecurityUtils; import com.cpop.core.utils.SpringUtils; import com.cpop.core.utils.sql.SqlUtils; @@ -14,43 +13,40 @@ import com.cpop.jambox.business.service.BrandExtendService; import com.cpop.jambox.business.vo.CardTemplateListVo; import com.cpop.mall.business.bo.ProductBo; import com.cpop.mall.business.bo.ProductPageBo; -import com.cpop.mall.business.entity.ProductSpecification; +import com.cpop.mall.business.entity.Product; import com.cpop.mall.business.entity.ProductRecord; +import com.cpop.mall.business.entity.ProductSpecification; +import com.cpop.mall.business.mapper.ProductMapper; import com.cpop.mall.business.service.OrderEvaluateService; import com.cpop.mall.business.service.ProductRecordService; +import com.cpop.mall.business.service.ProductService; import com.cpop.mall.business.service.ProductSpecificationService; import com.cpop.mall.business.vo.ProductEvaluateVo; import com.cpop.mall.business.vo.ProductPageVo; -import com.cpop.mall.business.vo.ProductRecordVo; import com.cpop.mall.business.vo.StoreListVo; -import com.cpop.system.business.entity.Brand; -import com.cpop.system.business.service.BrandService; +import com.cpop.system.business.service.StoreService; import com.mybatisflex.core.datasource.DataSourceKey; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Db; -import com.mybatisflex.core.row.DbChain; import com.mybatisflex.core.row.Row; import com.mybatisflex.core.row.RowUtil; import com.mybatisflex.spring.service.impl.ServiceImpl; -import com.cpop.mall.business.entity.Product; -import com.cpop.mall.business.mapper.ProductMapper; -import com.cpop.mall.business.service.ProductService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import static com.cpop.jambox.business.entity.table.BrandExtendTableDef.BRAND_EXTEND; +import static com.cpop.jambox.business.entity.table.StoreExtendTableDef.STORE_EXTEND; import static com.cpop.mall.business.entity.table.OrderEvaluateTableDef.ORDER_EVALUATE; import static com.cpop.mall.business.entity.table.OrderTableDef.ORDER; import static com.cpop.mall.business.entity.table.ProductRecordTableDef.PRODUCT_RECORD; import static com.cpop.mall.business.entity.table.ProductSpecificationTableDef.PRODUCT_SPECIFICATION; import static com.cpop.mall.business.entity.table.ProductTableDef.PRODUCT; import static com.cpop.system.business.entity.table.BrandTableDef.BRAND; +import static com.cpop.system.business.entity.table.StoreTableDef.STORE; /** * 商城-商品表 服务层实现。 @@ -244,46 +240,53 @@ public class ProductServiceImpl extends ServiceImpl impl * @return: java.util.List */ @Override - public List paySelectStore() { + public List getStoreList() { //获取当前用户信息 JSONObject loginUserInfo = SecurityUtils.getInstance().getLoginUserInfo(); SourceType sourceType = SourceType.valueOf(loginUserInfo.getString("sourceType")); switch (sourceType) { //果酱 case JAMBOX: - BrandExtend brandExtend = SpringUtils.getBean(BrandExtendService.class).queryChain() - .from(BRAND_EXTEND) - .leftJoin(BRAND).on(BRAND.ID.eq(BRAND_EXTEND.BRAND_ID)) - .where(BRAND.ID.eq(loginUserInfo.getString("brandId"))).one(); - return getJamboxStore(brandExtend.getBrandCloudId()); + return getJamboxStore(loginUserInfo); case COMMON: - break; + return getCommonStore(loginUserInfo); default: } return null; } + /** + * @descriptions 获取通用校区信息 + * @author DB + * @date 2023/10/26 15:54 + * @param loginUserInfo 登录用户信息 + * @return: java.util.List + */ + private List getCommonStore(JSONObject loginUserInfo) { + return SpringUtils.getBean(StoreService.class).queryChain() + .select(STORE.STORE_NAME, STORE.ID) + .from(STORE) + .leftJoin(BRAND).on(BRAND.ID.eq(STORE.BRAND_ID)) + .where(BRAND.ID.eq(loginUserInfo.getString("brandId"))) + .listAs(StoreListVo.class); + } + /** * @descriptions 获取果酱校区信息 * @author DB * @date 2023/10/26 15:54 - * @param brandCloudId 云平拍id + * @param loginUserInfo 登录用户信息 * @return: java.util.List */ - private List getJamboxStore(String brandCloudId) { - try { - DataSourceKey.use("jambox"); - //机构表 - List list = DbChain.table("t_mechanism_info") - .select("tmi.mechanism as storeName", "tmi.mechanism_id as id") - .from("t_mechanism_info").as("tmi") - .leftJoin("t_brand_info").as("tbi").on("tbi.id = tmi.brand_id") - .where("tbi.brand_id = ?", brandCloudId) - .list(); - return RowUtil.toEntityList(list,StoreListVo.class); - } finally { - DataSourceKey.clear(); - } + private List getJamboxStore(JSONObject loginUserInfo) { + return SpringUtils.getBean(StoreService.class).queryChain() + .select(STORE.STORE_NAME, STORE.ID) + .select(STORE_EXTEND.STORE_CLOUD_ID.as(StoreListVo::getOutId)) + .from(STORE) + .leftJoin(BRAND).on(BRAND.ID.eq(STORE.BRAND_ID)) + .leftJoin(STORE_EXTEND).on(STORE_EXTEND.STORE_ID.eq(STORE.ID)) + .where(BRAND.ID.eq(loginUserInfo.getString("brandId"))) + .listAs(StoreListVo.class); } /** diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/StoreListVo.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/StoreListVo.java index 58b2d1e..21da582 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/StoreListVo.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/StoreListVo.java @@ -26,4 +26,10 @@ public class StoreListVo { */ @ApiModelProperty("店铺/校区名") private String storeName; + + /** + * 外部id + */ + @ApiModelProperty("外部id") + private String outId; } 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 new file mode 100644 index 0000000..761a8a5 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayConfiguration.java @@ -0,0 +1,66 @@ +package com.cpop.mall.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.setUseSandboxEnv(false); + WxPayService wxPayService = new WxPayServiceImpl(); + wxPayService.setConfig(payConfig); + return wxPayService; + } + + /** + * @descriptions 根据商户appid或商户号获取对应微信支付接口 + * @author DB + * @date 2023/10/18 10:34 + * @param subAppId 子商户appid + * @param subMchId 子商户id + * @return: com.github.binarywang.wxpay.service.WxPayService + */ + public WxPayService getWxService(String subAppId, String subMchId) { + WxPayService wxPayService = wxService(); + WxPayConfig payConfig = wxPayService.getConfig(); + //子商户信息 + payConfig.setSubAppId(StringUtils.trimToNull(subAppId)); + payConfig.setSubMchId(StringUtils.trimToNull(subMchId)); + // 可以指定是否使用沙箱环境 + payConfig.setUseSandboxEnv(false); + wxPayService.setConfig(payConfig); + return wxPayService; + } + +} 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 new file mode 100644 index 0000000..6fc1188 --- /dev/null +++ b/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayProperties.java @@ -0,0 +1,63 @@ +package com.cpop.mall.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; + + /** + * 服务商模式下的子商户公众账号ID,普通模式请不要配置,请在配置文件中将对应项删除 + */ + private String subAppId; + + /** + * 服务商模式下的子商户号,普通模式请不要配置,最好是请在配置文件中将对应项删除 + */ + private String subMchId; + + /** + * 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; +}