Skip to content

Commit 035dd04

Browse files
authored
feat: 创建 WxMpOAuth2Service 接口并关联实现类
1 parent 434577e commit 035dd04

6 files changed

Lines changed: 41 additions & 9 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package me.chanjar.weixin.mp.api;
2+
3+
import me.chanjar.weixin.common.service.WxOAuth2Service;
4+
5+
/**
6+
* 微信公众号网页授权(OAuth2)服务接口.
7+
*
8+
* <p>完整文档见:
9+
* <a href="https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html">
10+
* 微信网页授权
11+
* </a>
12+
* </p>
13+
*
14+
* <p>包含以下能力:
15+
* <ul>
16+
* <li>构建网页授权 URL</li>
17+
* <li>通过 code 换取 access_token({@code sns/oauth2/access_token})</li>
18+
* <li>刷新 access_token({@code sns/oauth2/refresh_token})</li>
19+
* <li>获取用户基本信息({@code sns/userinfo})</li>
20+
* <li>校验 access_token 是否有效({@code sns/auth})</li>
21+
* </ul>
22+
* </p>
23+
*
24+
* @author GitHub Copilot
25+
*/
26+
public interface WxMpOAuth2Service extends WxOAuth2Service {
27+
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import me.chanjar.weixin.common.enums.TicketType;
77
import me.chanjar.weixin.common.error.WxErrorException;
88
import me.chanjar.weixin.common.service.WxImgProcService;
9-
import me.chanjar.weixin.common.service.WxOAuth2Service;
109
import me.chanjar.weixin.common.service.WxOcrService;
1110
import me.chanjar.weixin.common.service.WxService;
1211
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
@@ -758,16 +757,16 @@ public interface WxMpService extends WxService {
758757
/**
759758
* 获取OAuth2服务接口
760759
*
761-
* @return WxOAuth2Service OAuth2服务接口
760+
* @return WxMpOAuth2Service OAuth2服务接口
762761
*/
763-
WxOAuth2Service getOAuth2Service();
762+
WxMpOAuth2Service getOAuth2Service();
764763

765764
/**
766765
* 设置OAuth2服务接口
767766
*
768767
* @param oAuth2Service OAuth2服务接口
769768
*/
770-
void setOAuth2Service(WxOAuth2Service oAuth2Service);
769+
void setOAuth2Service(WxMpOAuth2Service oAuth2Service);
771770

772771
/**
773772
* 获取微信导购服务接口

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import me.chanjar.weixin.common.error.WxRuntimeException;
1717
import me.chanjar.weixin.common.executor.CommonUploadRequestExecutor;
1818
import me.chanjar.weixin.common.service.WxImgProcService;
19-
import me.chanjar.weixin.common.service.WxOAuth2Service;
2019
import me.chanjar.weixin.common.service.WxOcrService;
2120
import me.chanjar.weixin.common.session.StandardSessionManager;
2221
import me.chanjar.weixin.common.session.WxSessionManager;
@@ -141,7 +140,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
141140

142141
@Getter
143142
@Setter
144-
private WxOAuth2Service oAuth2Service = new WxMpOAuth2ServiceImpl(this);
143+
private WxMpOAuth2Service oAuth2Service = new WxMpOAuth2ServiceImpl(this);
145144

146145
@Getter
147146
@Setter

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpOAuth2ServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import me.chanjar.weixin.common.util.http.RequestExecutor;
1111
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
1212
import me.chanjar.weixin.common.util.http.URIUtil;
13+
import me.chanjar.weixin.mp.api.WxMpOAuth2Service;
1314
import me.chanjar.weixin.mp.api.WxMpService;
14-
import me.chanjar.weixin.common.service.WxOAuth2Service;
1515
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
1616
import org.apache.commons.lang3.StringUtils;
1717

@@ -26,7 +26,7 @@
2626
* created on 2020-08-08
2727
*/
2828
@RequiredArgsConstructor
29-
public class WxMpOAuth2ServiceImpl implements WxOAuth2Service {
29+
public class WxMpOAuth2ServiceImpl implements WxMpOAuth2Service {
3030
private final WxMpService wxMpService;
3131

3232
@Override

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpOAuth2ServiceImplTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
44
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
55
import me.chanjar.weixin.common.error.WxErrorException;
6+
import me.chanjar.weixin.mp.api.WxMpOAuth2Service;
67
import me.chanjar.weixin.mp.api.WxMpService;
78
import me.chanjar.weixin.mp.api.test.ApiTestModule;
89
import org.testng.annotations.Guice;
@@ -24,6 +25,11 @@ public class WxMpOAuth2ServiceImplTest {
2425
@Inject
2526
private WxMpService mpService;
2627

28+
@Test
29+
public void testGetOAuth2ServiceType() {
30+
assertThat(this.mpService.getOAuth2Service()).isInstanceOf(WxMpOAuth2Service.class);
31+
}
32+
2733
@Test
2834
public void testBuildAuthorizationUrl() {
2935
final String url = this.mpService.getOAuth2Service().buildAuthorizationUrl("http://www.baidu.com", "test", "GOD");

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMpOAuth2ServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import me.chanjar.weixin.common.service.WxOAuth2Service;
66
import me.chanjar.weixin.common.service.WxOAuth2ServiceDecorator;
77
import me.chanjar.weixin.common.util.http.URIUtil;
8+
import me.chanjar.weixin.mp.api.WxMpOAuth2Service;
89
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
910
import me.chanjar.weixin.open.api.WxOpenComponentService;
1011
import org.apache.commons.lang3.StringUtils;
@@ -14,7 +15,7 @@
1415
*
1516
* @author <a href="https://www.sacoc.cn">广州跨界</a>
1617
*/
17-
public class WxOpenMpOAuth2ServiceImpl extends WxOAuth2ServiceDecorator {
18+
public class WxOpenMpOAuth2ServiceImpl extends WxOAuth2ServiceDecorator implements WxMpOAuth2Service {
1819

1920
private final WxOpenComponentService wxOpenComponentService;
2021
private final WxMpConfigStorage wxMpConfigStorage;

0 commit comments

Comments
 (0)