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

This commit is contained in:
Binary Wang 2023-12-07 16:36:17 +08:00
parent 08196cfeb9
commit 2412df32ff
2 changed files with 10 additions and 4 deletions
weixin-java-open/src
main/java/me/chanjar/weixin/open/api/impl
test/java/me/chanjar/weixin/open/api/impl

View File

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

View File

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