Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.chanjar.weixin.mp.api;

import me.chanjar.weixin.common.service.WxOAuth2Service;

/**
* 微信公众号网页授权(OAuth2)服务接口.
*
* <p>完整文档见:
* <a href="https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html">
* 微信网页授权
* </a>
* </p>
*
* <p>包含以下能力:
* <ul>
* <li>构建网页授权 URL</li>
* <li>通过 code 换取 access_token({@code sns/oauth2/access_token})</li>
* <li>刷新 access_token({@code sns/oauth2/refresh_token})</li>
* <li>获取用户基本信息({@code sns/userinfo})</li>
* <li>校验 access_token 是否有效({@code sns/auth})</li>
* </ul>
* </p>
*
* @author GitHub Copilot
*/
public interface WxMpOAuth2Service extends WxOAuth2Service {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import me.chanjar.weixin.common.enums.TicketType;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.service.WxImgProcService;
import me.chanjar.weixin.common.service.WxOAuth2Service;
import me.chanjar.weixin.common.service.WxOcrService;
import me.chanjar.weixin.common.service.WxService;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
Expand Down Expand Up @@ -758,16 +757,16 @@ public interface WxMpService extends WxService {
/**
* 获取OAuth2服务接口
*
* @return WxOAuth2Service OAuth2服务接口
* @return WxMpOAuth2Service OAuth2服务接口
*/
WxOAuth2Service getOAuth2Service();
WxMpOAuth2Service getOAuth2Service();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the old OAuth2 getter descriptor

Changing this public interface method from returning WxOAuth2Service to WxMpOAuth2Service changes the JVM method descriptor. Applications or extensions compiled against the previous release will still invoke WxMpService.getOAuth2Service()Lme/chanjar/weixin/common/service/WxOAuth2Service;, but the upgraded interface no longer declares that method, so a jar-only upgrade can fail at runtime with NoSuchMethodError even though the new return value is assignable to the old type. Keep the old descriptor available (or avoid narrowing the interface signature) if this is intended to be backward compatible.

Useful? React with 👍 / 👎.


/**
* 设置OAuth2服务接口
*
* @param oAuth2Service OAuth2服务接口
*/
void setOAuth2Service(WxOAuth2Service oAuth2Service);
void setOAuth2Service(WxMpOAuth2Service oAuth2Service);

/**
* 获取微信导购服务接口
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import me.chanjar.weixin.common.error.WxRuntimeException;
import me.chanjar.weixin.common.executor.CommonUploadRequestExecutor;
import me.chanjar.weixin.common.service.WxImgProcService;
import me.chanjar.weixin.common.service.WxOAuth2Service;
import me.chanjar.weixin.common.service.WxOcrService;
import me.chanjar.weixin.common.session.StandardSessionManager;
import me.chanjar.weixin.common.session.WxSessionManager;
Expand Down Expand Up @@ -141,7 +140,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH

@Getter
@Setter
private WxOAuth2Service oAuth2Service = new WxMpOAuth2ServiceImpl(this);
private WxMpOAuth2Service oAuth2Service = new WxMpOAuth2ServiceImpl(this);

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.mp.api.WxMpOAuth2Service;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.common.service.WxOAuth2Service;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -26,7 +26,7 @@
* created on 2020-08-08
*/
@RequiredArgsConstructor
public class WxMpOAuth2ServiceImpl implements WxOAuth2Service {
public class WxMpOAuth2ServiceImpl implements WxMpOAuth2Service {
private final WxMpService wxMpService;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpOAuth2Service;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import org.testng.annotations.Guice;
Expand All @@ -24,6 +25,11 @@ public class WxMpOAuth2ServiceImplTest {
@Inject
private WxMpService mpService;

@Test
public void testGetOAuth2ServiceType() {
assertThat(this.mpService.getOAuth2Service()).isInstanceOf(WxMpOAuth2Service.class);
}

@Test
public void testBuildAuthorizationUrl() {
final String url = this.mpService.getOAuth2Service().buildAuthorizationUrl("http://www.baidu.com", "test", "GOD");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.chanjar.weixin.common.service.WxOAuth2Service;
import me.chanjar.weixin.common.service.WxOAuth2ServiceDecorator;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.mp.api.WxMpOAuth2Service;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.open.api.WxOpenComponentService;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -14,7 +15,7 @@
*
* @author <a href="https://www.sacoc.cn">广州跨界</a>
*/
public class WxOpenMpOAuth2ServiceImpl extends WxOAuth2ServiceDecorator {
public class WxOpenMpOAuth2ServiceImpl extends WxOAuth2ServiceDecorator implements WxMpOAuth2Service {

private final WxOpenComponentService wxOpenComponentService;
private final WxMpConfigStorage wxMpConfigStorage;
Expand Down