ソースを参照

:art: 优化开放平台模块OAuth2服务类的构造方法

Binary Wang 1 年間 前
コミット
2412df32ff

+ 7 - 2
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenOAuth2ServiceImpl.java

@@ -1,6 +1,5 @@
 package me.chanjar.weixin.open.api.impl;
 
-import lombok.AllArgsConstructor;
 import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
 import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
 import me.chanjar.weixin.common.enums.WxType;
@@ -9,6 +8,7 @@ import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.service.WxOAuth2Service;
 import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
 import me.chanjar.weixin.common.util.http.URIUtil;
+import me.chanjar.weixin.open.api.WxOpenConfigStorage;
 import org.apache.commons.lang3.StringUtils;
 
 import java.io.IOException;
@@ -22,11 +22,16 @@ import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.QRCONNECT_URL;
  * @author <a href="https://github.com/binarywang">Binary Wang</a>
  * created on  2020-10-19
  */
-@AllArgsConstructor
 public class WxOpenOAuth2ServiceImpl extends WxOpenServiceImpl implements WxOAuth2Service {
   private final String appId;
   private final String appSecret;
 
+  public WxOpenOAuth2ServiceImpl(String appId, String appSecret, WxOpenConfigStorage openConfigStorage) {
+    this.appId = appId;
+    this.appSecret = appSecret;
+    super.setWxOpenConfigStorage(openConfigStorage);
+  }
+
   @Override
   public String buildAuthorizationUrl(String redirectUri, String scope, String state) {
     return String.format(QRCONNECT_URL.getUrl(null),

+ 3 - 2
weixin-java-open/src/test/java/me/chanjar/weixin/open/api/impl/WxOpenOAuth2ServiceImplTest.java

@@ -12,11 +12,12 @@ import org.testng.annotations.Test;
  * created on  2020-10-19
  */
 public class WxOpenOAuth2ServiceImplTest {
-  private final WxOpenOAuth2ServiceImpl service = new WxOpenOAuth2ServiceImpl("123", "");
+  private final WxOpenOAuth2ServiceImpl service = new WxOpenOAuth2ServiceImpl("123", "",
+    new WxOpenInMemoryConfigStorage());
 
   @BeforeTest
   public void init() {
-    this.service.setWxOpenConfigStorage(new WxOpenInMemoryConfigStorage());
+//    this.service.setWxOpenConfigStorage(new WxOpenInMemoryConfigStorage());
   }
 
   @Test