Skip to content

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

Description

@Mengds

问题描述 (Problem Description)

根据微信小程序官方文档,获取手机号接口 POST https://api.weixin.qq.com/wxa/business/getuserphonenumber 的 Request Payload 参数除了必填的 code 之外,还支持选填参数 openid

  • openid(选填):用户 openid,填入后微信服务端会校验 openid 和 code 的绑定关系,并在不匹配时直接报错返回。

但在目前 weixin-java-miniappWxMaUserService 中,仅提供了单参数方法:
WxMaPhoneNumberInfo getPhoneNumber(String code)

由于缺少 openid 参数的传递,当开发者直接使用该方法时,无法触发微信服务端的 openid <-> code 匹配校验,在部分业务场景下可能存在越权安全隐患。

官方文档参考 (References)

建议与改进方案 (Proposed Solution)

建议在 WxMaUserService 接口及其实现类 WxMaUserServiceImpl 中增加重载方法,允许传入 openid

  1. 接口定义
    /**
     * 获取手机号信息
     *
     * @param code 手机号获取凭证
     * @param openid 用户 openid(选填,填入后会校验 openid 和 code 的绑定关系)
     * @return 手机号信息
     */
    WxMaPhoneNumberInfo getPhoneNumber(String code, String openid) throws WxErrorException;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions