企业微信第三方服务 WxCpTpUserServiceImpl,在调用 `getUserId` 接口时缺少 access_token
简要描述
企业微信第三方服务 WxCpTpUserServiceImpl,在调用 getUserId 接口时,是需要传 cropAccessToken 的,但在项目代码中,并没有进行设置 access 的地方,导致无法正常调用 API.
模块版本情况
- WxJava 模块名: weixin-java-cp
- WxJava 版本号: 4.4.0
详细描述
该接口的代码
@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 是可以成功的。