Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

企业微信第三方服务 WxCpTpUserServiceImpl,在调用 getUserId 接口时缺少 access_token #2799

Closed
lanvige opened this issue Aug 27, 2022 · 1 comment · Fixed by #2843

Comments

@lanvige
Copy link

lanvige commented Aug 27, 2022

简要描述

企业微信第三方服务 WxCpTpUserServiceImpl,在调用 getUserId 接口时,是需要传 cropAccessToken 的,但在项目代码中,并没有进行设置 access 的地方,导致无法正常调用 API.

模块版本情况

  • WxJava 模块名: weixin-java-cp
  • WxJava 版本号: 4.4.0

详细描述

该接口的代码

https://github.com/Wechat-Group/WxJava/blob/develop/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpUserServiceImpl.java#L189

 @Override
  public String getUserId(String mobile) throws WxErrorException {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("mobile", mobile);
    String url = mainService.getWxCpTpConfigStorage().getApiUrl(GET_USER_ID);
    String responseContent = this.mainService.post(url, jsonObject.toString());
    JsonObject tmpJsonElement = GsonParser.parse(responseContent);
    return tmpJsonElement.getAsJsonObject().get("userid").getAsString();
  }

使用 WxJava 中的方法来调用:

 WxCpTpService wxCpTpService = new WxCpTpServiceImpl();
wxCpTpService.setWxCpTpConfigStorage(wecomSaasDefaultConfig);

String wecomUserId = wxCpTpService.getWxCpTpUserService().getUserId("13000000000");
WxCpUser wecomUser2 = wxCpTpService.getWxCpTpUserService().getById(wecomUserId, enterpriseCorpConfig.getCorpId());

会报错误:

错误代码:41001, 错误信息:缺少access_token参数,微信原始报文:{"errcode":41001,"errmsg":"access_token missing, hint: [1661569918531331035431592]

手工调用

  JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("mobile", staff.getPhoneNumber());

String userJson = wxCpTpService.post("https://qyapi.weixin.qq.com/cgi-bin/user/getuserid?access_token=" + accessToken, jsonObject.toString());

这样手工拼接 url 是可以成功的。

@binarywang
Copy link
Member

欢迎直接PR代码进行修复

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 a pull request may close this issue.

2 participants