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

企业微信,获取用户时信息报空指针错误 #1619

Closed
sdlszjb opened this issue Jun 12, 2020 · 1 comment
Closed

企业微信,获取用户时信息报空指针错误 #1619

sdlszjb opened this issue Jun 12, 2020 · 1 comment

Comments

@sdlszjb
Copy link

sdlszjb commented Jun 12, 2020

简要描述

我用的企业微信是中油定制的企业微信。在获取数据的时候,我的extattr中没有type属性。因此在解析的时候,type是Null,就在

  private void buildExtraAttrs(JsonObject o, WxCpUser user) {
    JsonArray attrJsonElements = o.get(EXTRA_ATTR).getAsJsonObject().get("attrs").getAsJsonArray();
    for (JsonElement attrJsonElement : attrJsonElements) {
      final Integer type = GsonHelper.getInteger(attrJsonElement.getAsJsonObject(), "type");
      ---》 这里报错 final WxCpUser.Attr attr = new WxCpUser.Attr().setType(type)
        .setName(GsonHelper.getString(attrJsonElement.getAsJsonObject(), "name"));
      user.getExtAttrs().add(attr);

      switch (type) {
        case 0: {
          attr.setTextValue(GsonHelper.getString(attrJsonElement.getAsJsonObject().get("text").getAsJsonObject(), "value"));
          break;
        }
        case 1: {
          final JsonObject web = attrJsonElement.getAsJsonObject().get("web").getAsJsonObject();
          attr.setWebTitle(GsonHelper.getString(web, "title"))
            .setWebUrl(GsonHelper.getString(web, "url"));
          break;
        }
        default://ignored
      }
    }
  }

模块版本情况

        <dependency>
            <groupId>com.github.binarywang</groupId>
            <artifactId>weixin-java-cp</artifactId>
            <version>3.8.0</version>
        </dependency>

详细描述

经过测试:

    @Test
    void testAttr() {
        Integer type = null;
        WxCpUser.Attr attr = new WxCpUser.Attr();
        attr.setType(type);
    }

在传递的type为Null的时候,就会报空指针错误。

而我用的中油即时通的cgi-bin/user/get api的时候,response中extattr":{"attrs":[{"name":"员工编号","value":"xxxxx"}]}就只有这样,没有type或者咱们sdk中所写的那些attr,希望能修改一下。

即时通API

{
   "errcode": 0,
   "errmsg": "ok",
   "userid": "zhangsan",
   "name": "李四",
   "department": [1, 2],
   "order": [2, 10],
   "position": "后台工程师1",
   "positions": ["后台工程师1","后台工程师2"],
   "mobile": "15913215421",
   "hide_mobile": 0,
   "gender": "1",
   "email": "[email protected]",
   "is_leader_in_dept": [1, 0],
   "avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0",
   "telephone": "020-123456",
   "english_name": "jackzhang",
   "extattr": {"attrs":[{"name":"爱好","value":"旅游"},{"name":"卡号","value":"1234567234"}]}
   "status": 1,
   "enable": 0,
   "qr_code": "https://wwlocal.qq.com/wework_admin/userQRCode?vcode=vc2140a8b3c6207c74&lvc=vcf6f1acfdc4b45088"
}

日志

https://paste.ubuntu.com/p/ZXVyfxmmtm/

@binarywang
Copy link
Owner

这个错误看起来还挺简单的,其实楼主可以直接提供PR修复代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants