diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/AbstractApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/AbstractApi.java index 063dbfd..ea24a0d 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/AbstractApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/AbstractApi.java @@ -31,15 +31,15 @@ public abstract class AbstractApi { return mapper; } - public WechatPayClient getWechatPayClient() { + public WechatPayClient client() { return wechatPayClient; } - public WechatMetaBean getWechatMetaBean() { + public WechatMetaBean meta() { return wechatMetaBean; } - protected RequestEntity postRequestEntity(URI uri, Object params) { + protected RequestEntity post(URI uri, Object params) { try { return RequestEntity.post(uri) .body(mapper.writeValueAsString(params)); diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingApi.java index fd98f90..707c0a4 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingApi.java @@ -54,7 +54,7 @@ public class WechatMarketingApi extends AbstractApi { */ public WechatResponseEntity createStock(StocksCreateParams params) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.getWechatPayClient().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_COUPON_STOCKS, params) + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_COUPON_STOCKS, params) .function(this::createStocksFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -62,12 +62,12 @@ public class WechatMarketingApi extends AbstractApi { } private RequestEntity createStocksFunction(WechatPayV3Type type, StocksCreateParams params) { - WechatPayProperties.V3 v3 = this.getWechatMetaBean().getWechatPayProperties().getV3(); + WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); String mchId = v3.getMchId(); String httpUrl = type.uri(WeChatServer.CHINA); URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().toUri(); params.setBelongMerchant(mchId); - return postRequestEntity(uri, params); + return post(uri, params); } /** @@ -78,7 +78,7 @@ public class WechatMarketingApi extends AbstractApi { */ public WechatResponseEntity startStock(String stockId) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.getWechatPayClient().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_START, stockId) + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_START, stockId) .function(this::startAndRestartStockFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -93,7 +93,7 @@ public class WechatMarketingApi extends AbstractApi { */ public WechatResponseEntity restartStock(String stockId) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.getWechatPayClient().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_RESTART, stockId) + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_RESTART, stockId) .function(this::startAndRestartStockFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -101,13 +101,13 @@ public class WechatMarketingApi extends AbstractApi { } private RequestEntity startAndRestartStockFunction(WechatPayV3Type type, String stockId) { - WechatPayProperties.V3 v3 = this.getWechatMetaBean().getWechatPayProperties().getV3(); + WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); String mchId = v3.getMchId(); Map body = new HashMap<>(); body.put("stock_creator_mchid", mchId); String httpUrl = type.uri(WeChatServer.CHINA); URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().expand(stockId).toUri(); - return postRequestEntity(uri, body); + return post(uri, body); } /** @@ -118,7 +118,7 @@ public class WechatMarketingApi extends AbstractApi { */ public WechatResponseEntity queryStockDetail(String stockId) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.getWechatPayClient().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_DETAIL, stockId) + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_DETAIL, stockId) .function(this::stockDetailFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -127,7 +127,7 @@ public class WechatMarketingApi extends AbstractApi { private RequestEntity stockDetailFunction(WechatPayV3Type type, String stockId) { - WechatPayProperties.V3 v3 = this.getWechatMetaBean().getWechatPayProperties().getV3(); + WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); String httpUrl = type.uri(WeChatServer.CHINA); @@ -147,7 +147,7 @@ public class WechatMarketingApi extends AbstractApi { */ public WechatResponseEntity queryMerchantsByStockId(StocksQueryParams params) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.getWechatPayClient().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_MERCHANTS, params) + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_MERCHANTS, params) .function(this::queryStocksFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -164,7 +164,7 @@ public class WechatMarketingApi extends AbstractApi { */ public WechatResponseEntity queryStocksByMch(StocksQueryParams params) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.getWechatPayClient().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS, params) + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS, params) .function(this::queryStocksFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -178,7 +178,7 @@ public class WechatMarketingApi extends AbstractApi { MultiValueMap queryParams = new LinkedMultiValueMap<>(); queryParams.add("offset", String.valueOf(params.getOffset())); queryParams.add("limit", String.valueOf(params.getLimit())); - WechatPayProperties.V3 v3 = this.getWechatMetaBean().getWechatPayProperties().getV3(); + WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); queryParams.add("stock_creator_mchid", v3.getMchId()); LocalDateTime createStartTime = params.getCreateStartTime(); if (Objects.nonNull(createStartTime)) { @@ -220,7 +220,7 @@ public class WechatMarketingApi extends AbstractApi { */ public WechatResponseEntity sendStock(StocksSendParams params) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.getWechatPayClient().withType(WechatPayV3Type.MARKETING_FAVOR_USERS_COUPONS, params) + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_USERS_COUPONS, params) .function(this::sendStocksFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -229,14 +229,14 @@ public class WechatMarketingApi extends AbstractApi { private RequestEntity sendStocksFunction(WechatPayV3Type type, StocksSendParams params) { - WechatPayProperties.V3 v3 = this.getWechatMetaBean().getWechatPayProperties().getV3(); + WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); // 服务号 params.setAppid(v3.getMp().getAppId()); params.setStockCreatorMchid(v3.getMchId()); String httpUrl = type.uri(WeChatServer.CHINA); URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().expand(params.getOpenid()).toUri(); params.setOpenid(null); - return postRequestEntity(uri, params); + return post(uri, params); } /** @@ -247,7 +247,7 @@ public class WechatMarketingApi extends AbstractApi { */ public WechatResponseEntity marketingImageUpload(MultipartFile file) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.getWechatPayClient().withType(WechatPayV3Type.MARKETING_IMAGE_UPLOAD, file) + this.client().withType(WechatPayV3Type.MARKETING_IMAGE_UPLOAD, file) .function(this::marketingImageUploadFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -284,7 +284,7 @@ public class WechatMarketingApi extends AbstractApi { */ public WechatResponseEntity marketingFavorCallback(String notifyUrl) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.getWechatPayClient().withType(WechatPayV3Type.MARKETING_FAVOR_CALLBACKS, notifyUrl) + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_CALLBACKS, notifyUrl) .function(this::marketingFavorCallbackFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -292,14 +292,14 @@ public class WechatMarketingApi extends AbstractApi { } private RequestEntity marketingFavorCallbackFunction(WechatPayV3Type type, String notifyUrl) { - WechatPayProperties.V3 v3 = this.getWechatMetaBean().getWechatPayProperties().getV3(); + WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); Map body = new HashMap<>(3); body.put("mchid", v3.getMchId()); body.put("notify_url", notifyUrl); body.put("switch", true); String httpUrl = type.uri(WeChatServer.CHINA); URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().toUri(); - return postRequestEntity(uri, body); + return post(uri, body); } } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayApi.java index 521096a..f76083f 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayApi.java @@ -31,7 +31,7 @@ public class WechatPayApi extends AbstractApi { */ public WechatResponseEntity appPay(AppPayParams payParams) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.getWechatPayClient().withType(WechatPayV3Type.APP, payParams) + this.client().withType(WechatPayV3Type.APP, payParams) .function(this::appPayFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -39,11 +39,11 @@ public class WechatPayApi extends AbstractApi { } private RequestEntity appPayFunction(WechatPayV3Type type, AppPayParams payParams) { - WechatPayProperties.V3 v3 = this.getWechatMetaBean().getWechatPayProperties().getV3(); + WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); payParams.setAppid(v3.getAppId()); payParams.setMchid(v3.getMchId()); String httpUrl = type.uri(WeChatServer.CHINA); URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().toUri(); - return postRequestEntity(uri, payParams); + return post(uri, payParams); } }