feat(weixin-java-mp): 新增 WxMpOAuth2Service 接口,修复网页授权能力缺失#4041
Conversation
There was a problem hiding this comment.
Pull request overview
新增 WxMpOAuth2Service 作为公众号专属的网页授权服务接口(继承自公共 WxOAuth2Service),并将 WxMpService.getOAuth2Service()/setOAuth2Service() 的类型从公共接口收窄到该子接口,以便在 mp 模块层面扩展或替换 OAuth2 实现。WxMpOAuth2ServiceImpl 与 open 模块的 WxOpenMpOAuth2ServiceImpl 已同步实现新接口。
Changes:
- 新增
WxMpOAuth2Service子接口(目前无新增方法,仅作类型标识/未来扩展点)。 WxMpService的 getter/setter 与BaseWxMpServiceImpl字段类型同步收窄;WxMpOAuth2ServiceImpl、WxOpenMpOAuth2ServiceImpl实现新接口。- 测试
WxMpOAuth2ServiceImplTest新增testGetOAuth2ServiceType校验返回类型。
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| weixin-java-mp/.../api/WxMpOAuth2Service.java | 新建 mp 模块专属 OAuth2 服务接口(继承 WxOAuth2Service,暂无新方法)。 |
| weixin-java-mp/.../api/WxMpService.java | getOAuth2Service/setOAuth2Service 类型收窄为 WxMpOAuth2Service。 |
| weixin-java-mp/.../impl/BaseWxMpServiceImpl.java | oAuth2Service 字段类型同步收窄。 |
| weixin-java-mp/.../impl/WxMpOAuth2ServiceImpl.java | 改为 implements WxMpOAuth2Service。 |
| weixin-java-open/.../impl/WxOpenMpOAuth2ServiceImpl.java | 增加 implements WxMpOAuth2Service 以维持子类编译兼容。 |
| weixin-java-mp/.../impl/WxMpOAuth2ServiceImplTest.java | 新增类型断言测试。 |
| * @param oAuth2Service OAuth2服务接口 | ||
| */ | ||
| void setOAuth2Service(WxOAuth2Service oAuth2Service); | ||
| void setOAuth2Service(WxMpOAuth2Service oAuth2Service); |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 035dd04e0e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| * @return WxMpOAuth2Service OAuth2服务接口 | ||
| */ | ||
| WxOAuth2Service getOAuth2Service(); | ||
| WxMpOAuth2Service getOAuth2Service(); |
There was a problem hiding this comment.
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 👍 / 👎.
weixin-java-mp模块缺少公众号专属的 OAuth2 服务接口,导致WxMpService.getOAuth2Service()只能返回公共模块的WxOAuth2Service,无法在 mp 模块层面扩展或替换 OAuth2 实现。变更
新增接口
WxMpOAuth2Service:继承WxOAuth2Service,作为 mp 模块专属的网页授权服务接口,覆盖全部四个官方 API:sns/oauth2/access_token、sns/oauth2/refresh_token、sns/userinfo、sns/auth更新实现与声明
WxMpOAuth2ServiceImpl:改为实现WxMpOAuth2ServiceWxMpService:getOAuth2Service()返回类型收窄为WxMpOAuth2Service,setOAuth2Service()参数同步更新BaseWxMpServiceImpl:oAuth2Service字段类型改为WxMpOAuth2ServiceWxOpenMpOAuth2ServiceImpl(weixin-java-open):补充implements WxMpOAuth2Service声明,维持编译兼容测试
WxMpOAuth2ServiceImplTest:新增testGetOAuth2ServiceType,断言getOAuth2Service()返回值是WxMpOAuth2Service实例兼容性
WxMpOAuth2Service是WxOAuth2Service的子类型,所有持有WxOAuth2Service引用的调用方无需修改,完全向后兼容。