Skip to content

Commit

Permalink
🆕 #1767 企业微信外部联系人增加修改客户备注信息的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Sep 19, 2020
1 parent 115f910 commit 7261f23
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ public interface WxCpExternalContactService {
*/
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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<String> listExternalContacts(String userId) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_EXTERNAL_CONTACT + userId);
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 7261f23

Please sign in to comment.