### 简要描述 企业微信第三方服务 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 ``` java @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 中的方法来调用: ``` java 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] ``` ### 手工调用 ``` java 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 是可以成功的。
Activity
binarywang commentedon Sep 5, 2022
欢迎直接PR代码进行修复
fix [ 企业微信第三方服务调用getUserId接口时缺少 access_token. issues binarywang#2799 ]
fix [ 企业微信第三方服务调用getUserId接口时缺少 access_token. issues binarywang#2799 ]
fix [ 企业微信第三方服务调用getUserId接口时缺少 access_token. issues binarywang#2799 ]
🐛 #2799 [ 企业微信】修复第三方服务调用getUserId接口时缺少access_token的问题