🆕 #1767 企业微信外部联系人增加修改客户备注信息的接口

This commit is contained in:
Binary Wang 2020-09-20 00:09:40 +08:00
parent 115f910e3c
commit 7261f23689
6 changed files with 205 additions and 28 deletions

View File

@ -132,6 +132,20 @@ public interface WxCpExternalContactService {
*/ */
WxCpUserExternalContactInfo getContactDetail(String userId) throws WxErrorException; WxCpUserExternalContactInfo getContactDetail(String userId) throws WxErrorException;
/**
* 修改客户备注信息.
* <pre>
* 企业可通过此接口修改指定用户添加的客户的备注信息
* 请求方式: POST(HTTP)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remark?access_token=ACCESS_TOKEN
* 文档地址https://work.weixin.qq.com/api/doc/90000/90135/92115
* </pre>
*
* @param request 备注信息请求
* @throws WxErrorException .
*/
void updateRemark(WxCpUpdateRemarkRequest request) throws WxErrorException;
/** /**
* 获取客户列表. * 获取客户列表.
* <pre> * <pre>

View File

@ -8,7 +8,7 @@ import me.chanjar.weixin.common.error.WxCpErrorMsgEnum;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpExternalContactService; import me.chanjar.weixin.cp.api.WxCpExternalContactService;
import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.*; import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.external.*; import me.chanjar.weixin.cp.bean.external.*;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -67,7 +67,7 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
@Override @Override
public WxCpBaseResp deleteContactWay(@NonNull String configId) throws WxErrorException { public WxCpBaseResp deleteContactWay(@NonNull String configId) throws WxErrorException {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
json.addProperty("config_id",configId); json.addProperty("config_id", configId);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_CONTACT_WAY); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_CONTACT_WAY);
String responseContent = this.mainService.post(url, json.toString()); String responseContent = this.mainService.post(url, json.toString());
@ -79,8 +79,8 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
public WxCpBaseResp closeTempChat(@NonNull String userId, @NonNull String externalUserId) throws WxErrorException { public WxCpBaseResp closeTempChat(@NonNull String userId, @NonNull String externalUserId) throws WxErrorException {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
json.addProperty("userid",userId); json.addProperty("userid", userId);
json.addProperty("external_userid",externalUserId); json.addProperty("external_userid", externalUserId);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(CLOSE_TEMP_CHAT); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(CLOSE_TEMP_CHAT);
@ -103,6 +103,12 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
return WxCpUserExternalContactInfo.fromJson(responseContent); return WxCpUserExternalContactInfo.fromJson(responseContent);
} }
@Override
public void updateRemark(WxCpUpdateRemarkRequest request) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_REMARK);
this.mainService.post(url, request.toJson());
}
@Override @Override
public List<String> listExternalContacts(String userId) throws WxErrorException { public List<String> listExternalContacts(String userId) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_EXTERNAL_CONTACT + userId); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_EXTERNAL_CONTACT + userId);
@ -233,66 +239,66 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
@Override @Override
public WxCpUserExternalTagGroupList getCorpTagList(String[] tagId) throws WxErrorException { public WxCpUserExternalTagGroupList getCorpTagList(String[] tagId) throws WxErrorException {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
if(ArrayUtils.isNotEmpty(tagId)){ if (ArrayUtils.isNotEmpty(tagId)) {
json.add("tag_id",new Gson().toJsonTree(tagId).getAsJsonArray()); json.add("tag_id", new Gson().toJsonTree(tagId).getAsJsonArray());
} }
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CORP_TAG_LIST); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CORP_TAG_LIST);
final String result = this.mainService.post(url,json.toString()); final String result = this.mainService.post(url, json.toString());
return WxCpUserExternalTagGroupList.fromJson(result); return WxCpUserExternalTagGroupList.fromJson(result);
} }
@Override @Override
public WxCpUserExternalTagGroupInfo addCorpTag(WxCpUserExternalTagGroupInfo tagGroup) throws WxErrorException{ public WxCpUserExternalTagGroupInfo addCorpTag(WxCpUserExternalTagGroupInfo tagGroup) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_CORP_TAG); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_CORP_TAG);
final String result = this.mainService.post(url,tagGroup.getTagGroup().toJson()); final String result = this.mainService.post(url, tagGroup.getTagGroup().toJson());
return WxCpUserExternalTagGroupInfo.fromJson(result); return WxCpUserExternalTagGroupInfo.fromJson(result);
} }
@Override @Override
public WxCpBaseResp editCorpTag(String id, String name, Integer order) throws WxErrorException{ public WxCpBaseResp editCorpTag(String id, String name, Integer order) throws WxErrorException {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
json.addProperty("id",id); json.addProperty("id", id);
json.addProperty("name",name); json.addProperty("name", name);
json.addProperty("order",order); json.addProperty("order", order);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(EDIT_CORP_TAG); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(EDIT_CORP_TAG);
final String result = this.mainService.post(url,json.toString()); final String result = this.mainService.post(url, json.toString());
return WxCpBaseResp.fromJson(result); return WxCpBaseResp.fromJson(result);
} }
@Override @Override
public WxCpBaseResp delCorpTag(String[] tagId, String[] groupId) throws WxErrorException{ public WxCpBaseResp delCorpTag(String[] tagId, String[] groupId) throws WxErrorException {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
if(ArrayUtils.isNotEmpty(tagId)){ if (ArrayUtils.isNotEmpty(tagId)) {
json.add("tag_id",new Gson().toJsonTree(tagId).getAsJsonArray()); json.add("tag_id", new Gson().toJsonTree(tagId).getAsJsonArray());
} }
if(ArrayUtils.isNotEmpty(groupId)){ if (ArrayUtils.isNotEmpty(groupId)) {
json.add("group_id",new Gson().toJsonTree(groupId).getAsJsonArray()); json.add("group_id", new Gson().toJsonTree(groupId).getAsJsonArray());
} }
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_CORP_TAG); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_CORP_TAG);
final String result = this.mainService.post(url,json.toString()); final String result = this.mainService.post(url, json.toString());
return WxCpBaseResp.fromJson(result); return WxCpBaseResp.fromJson(result);
} }
@Override @Override
public WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag)throws WxErrorException{ public WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag) throws WxErrorException {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
json.addProperty("userid",userid); json.addProperty("userid", userid);
json.addProperty("external_userid",externalUserid); json.addProperty("external_userid", externalUserid);
if(ArrayUtils.isNotEmpty(addTag)){ if (ArrayUtils.isNotEmpty(addTag)) {
json.add("add_tag",new Gson().toJsonTree(addTag).getAsJsonArray()); json.add("add_tag", new Gson().toJsonTree(addTag).getAsJsonArray());
} }
if(ArrayUtils.isNotEmpty(removeTag)){ if (ArrayUtils.isNotEmpty(removeTag)) {
json.add("remove_tag",new Gson().toJsonTree(removeTag).getAsJsonArray()); json.add("remove_tag", new Gson().toJsonTree(removeTag).getAsJsonArray());
} }
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(MARK_TAG); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(MARK_TAG);
final String result = this.mainService.post(url,json.toString()); final String result = this.mainService.post(url, json.toString());
return WxCpBaseResp.fromJson(result); return WxCpBaseResp.fromJson(result);
} }
} }

View File

@ -0,0 +1,101 @@
package me.chanjar.weixin.cp.bean.external;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
/**
* 修改客户备注信息请求.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-09-19
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpUpdateRemarkRequest implements Serializable {
private static final long serialVersionUID = -4960239393895754138L;
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
/**
* <pre>
* 字段名userid
* 是否必须
* 描述企业成员的userid
* </pre>
*/
@SerializedName("userid")
private String userId;
/**
* <pre>
* 字段名external_userid
* 是否必须
* 描述外部联系人userid
* </pre>
*/
@SerializedName("external_userid")
private String externalUserId;
/**
* <pre>
* 字段名remark
* 是否必须
* 描述此用户对外部联系人的备注最多20个字符
* </pre>
*/
@SerializedName("remark")
private String remark;
/**
* <pre>
* 字段名description
* 是否必须
* 描述此用户对外部联系人的描述最多150个字符
* </pre>
*/
@SerializedName("description")
private String description;
/**
* <pre>
* 字段名remark_company
* 是否必须
* 描述此用户对外部联系人备注的所属公司名称最多20个字符
* </pre>
*/
@SerializedName("remark_company")
private String remarkCompany;
/**
* <pre>
* 字段名remark_mobiles
* 是否必须
* 描述此用户对外部联系人备注的手机号
* </pre>
*/
@SerializedName("remark_mobiles")
private String[] remarkMobiles;
/**
* <pre>
* 字段名remark_pic_mediaid
* 是否必须
* 描述备注图片的mediaid
* </pre>
*/
@SerializedName("remark_pic_mediaid")
private String remarkPicMediaId;
}

View File

@ -159,6 +159,7 @@ public final class WxCpApiPathConsts {
public static final String CLOSE_TEMP_CHAT = "/cgi-bin/externalcontact/close_temp_chat"; public static final String CLOSE_TEMP_CHAT = "/cgi-bin/externalcontact/close_temp_chat";
public static final String GET_FOLLOW_USER_LIST = "/cgi-bin/externalcontact/get_follow_user_list"; public static final String GET_FOLLOW_USER_LIST = "/cgi-bin/externalcontact/get_follow_user_list";
public static final String GET_CONTACT_DETAIL = "/cgi-bin/externalcontact/get?external_userid="; public static final String GET_CONTACT_DETAIL = "/cgi-bin/externalcontact/get?external_userid=";
public static final String UPDATE_REMARK = "/cgi-bin/externalcontact/remark";
public static final String LIST_EXTERNAL_CONTACT = "/cgi-bin/externalcontact/list?userid="; public static final String LIST_EXTERNAL_CONTACT = "/cgi-bin/externalcontact/list?userid=";
public static final String LIST_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/get_unassigned_list"; public static final String LIST_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/get_unassigned_list";
public static final String TRANSFER_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/transfer"; public static final String TRANSFER_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/transfer";

View File

@ -217,4 +217,17 @@ public class WxCpExternalContactServiceImplTest {
.welcomeCode("abc") .welcomeCode("abc")
.build()); .build());
} }
@Test
public void testUpdateRemark() throws WxErrorException {
this.wxCpService.getExternalContactService().updateRemark(WxCpUpdateRemarkRequest.builder()
.description("abc")
.userId("aaa")
.externalUserId("aaa")
.remark("aa")
.remarkCompany("aaa")
.remarkMobiles(new String[]{"111","222"})
.remarkPicMediaId("aaa")
.build());
}
} }

View File

@ -0,0 +1,42 @@
package me.chanjar.weixin.cp.bean.external;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* 单元测试.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-09-20
*/
public class WxCpUpdateRemarkRequestTest {
@Test
public void testToJson() {
String json = "{\n" +
" \"userid\":\"zhangsan\",\n" +
" \"external_userid\":\"woAJ2GCAAAd1asdasdjO4wKmE8Aabj9AAA\",\n" +
" \"remark\":\"备注信息\",\n" +
" \"description\":\"描述信息\",\n" +
" \"remark_company\":\"腾讯科技\",\n" +
" \"remark_mobiles\":[\n" +
" \"13800000001\",\n" +
" \"13800000002\"\n" +
" ],\n" +
" \"remark_pic_mediaid\":\"MEDIAID\"\n" +
"}\n";
WxCpUpdateRemarkRequest request = WxCpUpdateRemarkRequest.builder()
.description("描述信息")
.userId("zhangsan")
.externalUserId("woAJ2GCAAAd1asdasdjO4wKmE8Aabj9AAA")
.remark("备注信息")
.remarkCompany("腾讯科技")
.remarkMobiles(new String[]{"13800000001","13800000002"})
.remarkPicMediaId("MEDIAID")
.build();
assertThat(request.toJson()).isEqualTo(GsonParser.parse(json).toString());
}
}