Skip to content

feat: 小程序获取手机号支持openid校验 - #4078

Merged
binarywang merged 2 commits into
developfrom
fix/4076-miniapp-phone-number-openid
Jul 30, 2026
Merged

feat: 小程序获取手机号支持openid校验#4078
binarywang merged 2 commits into
developfrom
fix/4076-miniapp-phone-number-openid

Conversation

@binarywang

Copy link
Copy Markdown
Owner

概述

WxMaUserService#getPhoneNumber 增加可选 openid 参数,使调用方可请求微信服务端校验 openid 与手机号获取凭证 code 的绑定关系。

变更

  • 新增 getPhoneNumber(String code, String openid) 重载。
  • 保留原单参数方法,并委托到新方法,维持现有行为与兼容性。
  • 新增单元测试,验证请求体同时包含 codeopenid

验证

  • java -cp "weixin-java-miniapp/target/test-classes:weixin-java-miniapp/target/classes:$(< /tmp/wxjava-miniapp-test-classpath)" org.testng.TestNG -testclass cn.binarywang.wx.miniapp.api.impl.WxMaUserServiceImplPhoneNumberTest

Fixes #4076

@binarywang
binarywang marked this pull request as ready for review July 30, 2026 03:38
Copilot AI review requested due to automatic review settings July 30, 2026 03:38
@augmentcode

augmentcode Bot commented Jul 30, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: 本 PR 为小程序用户服务的“手机号快速验证”接口增加了可选的 openid 校验能力,以支持微信服务端校验 openid 与手机号凭证 code 的绑定关系。

Changes:

  • WxMaUserService 新增 getPhoneNumber(String code, String openid) 重载
  • 保留原 getPhoneNumber(String code),并委托到新重载以维持原有调用方式
  • WxMaUserServiceImpl 组装请求体时按需附带 openid
  • 新增单元测试验证请求体同时包含 codeopenid
Technical Notes: 仍使用原有 GET_PHONE_NUMBER_URL 端点与 JSON 请求体,新增字段仅在传入 openid 时发送。

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

本 PR 针对小程序“获取手机号”接口补齐微信服务端可选的 openid 参数传递能力,使调用方能够触发微信服务端对 openidcode 绑定关系的校验,从而满足防越权校验需求(关联 #4076)。

Changes:

  • WxMaUserService 新增 getPhoneNumber(String code, String openid) 重载方法声明。
  • WxMaUserServiceImpl 中实现重载方法:请求体在 openid 非空时追加 openid 字段;原单参方法委托到新方法以保持行为一致。
  • 新增单元测试 WxMaUserServiceImplPhoneNumberTest,验证请求体包含 code + openid

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaUserService.java 新增获取手机号接口的 openid 重载声明(建议用 default 方法避免对外实现的二进制不兼容)。
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaUserServiceImpl.java 构造请求 JSON 时可选加入 openid,并保持原方法兼容。
weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaUserServiceImplPhoneNumberTest.java 新增测试验证请求体包含 openid(当前存在 unused import 导致编译失败,需修复)。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 701070b954

ℹ️ 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".

@binarywang
binarywang merged commit bdf947e into develop Jul 30, 2026
1 check passed
@binarywang
binarywang deleted the fix/4076-miniapp-phone-number-openid branch July 30, 2026 16:17
@binarywang binarywang added this to the 4.8.6 milestone Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature/Bug] WxMaUserService.getPhoneNumber 建议增加 openid 重载参数以支持微信防越权校验

2 participants