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

企业微信更新通讯录里系统自动生成的人员userid时WxCpUser对象里没有new_userid字段 #1953

Closed
yezw1506 opened this issue Dec 31, 2020 · 5 comments
Milestone

Comments

@yezw1506
Copy link

WxCpUser对象里没有new_userid字段,需要自己项目里创建包含new_userid字段的对象,能否把这个字段添加到WxCpUser对象里,谢谢!

官方文档地址

https://work.weixin.qq.com/api/doc/90000/90135/90197

@binarywang
Copy link
Member

关了?

@yezw1506
Copy link
Author

yezw1506 commented Dec 31, 2020 via email

@binarywang
Copy link
Member

那也不用关闭啊,你可以直接提交PR代码的

@binarywang binarywang reopened this Dec 31, 2020
@binarywang
Copy link
Member

请问楼主是加在哪里的?官方文档写得很模糊,只是简单的一句:特别地,如果userid由系统自动生成,则仅允许修改一次。新值可由new_userid字段指定。
可否自行提交经过测试有效的代码,PR上来?

@binarywang binarywang added this to the 4.0.3 milestone Jan 3, 2021
@yezw1506
Copy link
Author

yezw1506 commented Jan 4, 2021

没拉代码,我是在自己的项目里改的,下面这样加应该就可以
1、WxCpUser对象里加个new_userid字段

package me.chanjar.weixin.cp.bean;
...
public class WxCpUser implements Serializable {

    private static final long serialVersionUID = -5696099236344075582L;

    ...
    private String newUserId;
    ...
}

2、WxCpUserGsonAdapter对象里的serialize方法实现里添加new_userid属性

package me.chanjar.weixin.cp.util.json;
...
public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSerializer<WxCpUser> {
    ...
    public JsonElement serialize(WxCpUser user, Type typeOfSrc, JsonSerializationContext context) {
        JsonObject o = new JsonObject();
        ...
        if (user.getNewUserId() != null) {
            o.addProperty("new_userid", user.getNewUserId());
        }
        ...
        return o;
    }

}

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