diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java index a386b0ead2..3f5ee36773 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java @@ -132,6 +132,20 @@ public interface WxCpExternalContactService { */ WxCpUserExternalContactInfo getContactDetail(String userId) throws WxErrorException; + /** + * 修改客户备注信息. + *
+   * 企业可通过此接口修改指定用户添加的客户的备注信息。
+   * 请求方式: 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
+   * 
+ * + * @param request 备注信息请求 + * @throws WxErrorException . + */ + void updateRemark(WxCpUpdateRemarkRequest request) throws WxErrorException; + /** * 获取客户列表. *
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java
index b64ec0e870..2fa5da03e2 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java
@@ -8,7 +8,7 @@
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.cp.api.WxCpExternalContactService;
 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 org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -67,7 +67,7 @@ public WxCpBaseResp updateContactWay(@NonNull WxCpContactWayInfo info) throws Wx
   @Override
   public WxCpBaseResp deleteContactWay(@NonNull String configId) throws WxErrorException {
     JsonObject json = new JsonObject();
-    json.addProperty("config_id",configId);
+    json.addProperty("config_id", configId);
 
     final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_CONTACT_WAY);
     String responseContent = this.mainService.post(url, json.toString());
@@ -79,8 +79,8 @@ public WxCpBaseResp deleteContactWay(@NonNull String configId) throws WxErrorExc
   public WxCpBaseResp closeTempChat(@NonNull String userId, @NonNull String externalUserId) throws WxErrorException {
 
     JsonObject json = new JsonObject();
-    json.addProperty("userid",userId);
-    json.addProperty("external_userid",externalUserId);
+    json.addProperty("userid", userId);
+    json.addProperty("external_userid", externalUserId);
 
 
     final String url = this.mainService.getWxCpConfigStorage().getApiUrl(CLOSE_TEMP_CHAT);
@@ -103,6 +103,12 @@ public WxCpUserExternalContactInfo getContactDetail(String userId) throws WxErro
     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
   public List listExternalContacts(String userId) throws WxErrorException {
     final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_EXTERNAL_CONTACT + userId);
@@ -233,66 +239,66 @@ public void sendWelcomeMsg(WxCpWelcomeMsg msg) throws WxErrorException {
   @Override
   public WxCpUserExternalTagGroupList getCorpTagList(String[] tagId) throws WxErrorException {
     JsonObject json = new JsonObject();
-    if(ArrayUtils.isNotEmpty(tagId)){
-      json.add("tag_id",new Gson().toJsonTree(tagId).getAsJsonArray());
+    if (ArrayUtils.isNotEmpty(tagId)) {
+      json.add("tag_id", new Gson().toJsonTree(tagId).getAsJsonArray());
     }
     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);
   }
 
   @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 result = this.mainService.post(url,tagGroup.getTagGroup().toJson());
+    final String result = this.mainService.post(url, tagGroup.getTagGroup().toJson());
     return WxCpUserExternalTagGroupInfo.fromJson(result);
   }
 
   @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();
-    json.addProperty("id",id);
-    json.addProperty("name",name);
-    json.addProperty("order",order);
+    json.addProperty("id", id);
+    json.addProperty("name", name);
+    json.addProperty("order", order);
     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);
   }
 
   @Override
-  public WxCpBaseResp delCorpTag(String[] tagId, String[] groupId) throws WxErrorException{
+  public WxCpBaseResp delCorpTag(String[] tagId, String[] groupId) throws WxErrorException {
     JsonObject json = new JsonObject();
-    if(ArrayUtils.isNotEmpty(tagId)){
-      json.add("tag_id",new Gson().toJsonTree(tagId).getAsJsonArray());
+    if (ArrayUtils.isNotEmpty(tagId)) {
+      json.add("tag_id", new Gson().toJsonTree(tagId).getAsJsonArray());
     }
-    if(ArrayUtils.isNotEmpty(groupId)){
-      json.add("group_id",new Gson().toJsonTree(groupId).getAsJsonArray());
+    if (ArrayUtils.isNotEmpty(groupId)) {
+      json.add("group_id", new Gson().toJsonTree(groupId).getAsJsonArray());
     }
 
     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);
   }
 
   @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();
-    json.addProperty("userid",userid);
-    json.addProperty("external_userid",externalUserid);
+    json.addProperty("userid", userid);
+    json.addProperty("external_userid", externalUserid);
 
-    if(ArrayUtils.isNotEmpty(addTag)){
-      json.add("add_tag",new Gson().toJsonTree(addTag).getAsJsonArray());
+    if (ArrayUtils.isNotEmpty(addTag)) {
+      json.add("add_tag", new Gson().toJsonTree(addTag).getAsJsonArray());
     }
-    if(ArrayUtils.isNotEmpty(removeTag)){
-      json.add("remove_tag",new Gson().toJsonTree(removeTag).getAsJsonArray());
+    if (ArrayUtils.isNotEmpty(removeTag)) {
+      json.add("remove_tag", new Gson().toJsonTree(removeTag).getAsJsonArray());
     }
 
     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);
   }
 }
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequest.java
new file mode 100644
index 0000000000..678995590b
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequest.java
@@ -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 Binary Wang
+ * @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);
+  }
+
+  /**
+   * 
+   * 字段名:userid
+   * 是否必须:是
+   * 描述:企业成员的userid
+   * 
+ */ + @SerializedName("userid") + private String userId; + + /** + *
+   * 字段名:external_userid
+   * 是否必须:是
+   * 描述:外部联系人userid
+   * 
+ */ + @SerializedName("external_userid") + private String externalUserId; + + /** + *
+   * 字段名:remark
+   * 是否必须:否
+   * 描述:此用户对外部联系人的备注,最多20个字符
+   * 
+ */ + @SerializedName("remark") + private String remark; + + /** + *
+   * 字段名:description
+   * 是否必须:否
+   * 描述:此用户对外部联系人的描述,最多150个字符
+   * 
+ */ + @SerializedName("description") + private String description; + + /** + *
+   * 字段名:remark_company
+   * 是否必须:否
+   * 描述:此用户对外部联系人备注的所属公司名称,最多20个字符
+   * 
+ */ + @SerializedName("remark_company") + private String remarkCompany; + + /** + *
+   * 字段名:remark_mobiles
+   * 是否必须:否
+   * 描述:此用户对外部联系人备注的手机号
+   * 
+ */ + @SerializedName("remark_mobiles") + private String[] remarkMobiles; + + /** + *
+   * 字段名:remark_pic_mediaid
+   * 是否必须:否
+   * 描述:备注图片的mediaid,
+   * 
+ */ + @SerializedName("remark_pic_mediaid") + private String remarkPicMediaId; + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index 6fd219ff06..6e5e52a146 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -159,6 +159,7 @@ public static class ExternalContact { 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_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_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/get_unassigned_list"; public static final String TRANSFER_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/transfer"; diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java index 9a0fbdbd3d..8cace0fe3e 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java @@ -217,4 +217,17 @@ public void testSendWelcomeMsg() throws WxErrorException { .welcomeCode("abc") .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()); + } } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequestTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequestTest.java new file mode 100644 index 0000000000..9564cdf9bc --- /dev/null +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequestTest.java @@ -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 Binary Wang + * @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()); + } +}