CRM客户群操作流程
流程简介
1.
openGroupSetId
。2.
openGroupSetId
进行客户群组管理操作。openGroupSetId
,调用服务端API-更新客户群组接口,进行更新客户群组。openGroupSetId
,调用服务端API-获取单个客户群组详情接口,进行查询单个客户群组详情。3.
步骤一:创建企业内部应用
步骤二:获取AppKey和AppSecret

步骤三:添加接口权限

步骤四:获取应用访问凭证accessToken
public void getAccessToken() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkoauth2_1_0.Client client = new com.aliyun.dingtalkoauth2_1_0.Client(config);
GetAccessTokenRequest accessTokenRequest = new GetAccessTokenRequest()
.setAppKey("din*********hgn")
.setAppSecret("9G_O************mBkhgGIO");
GetAccessTokenResponse accessToken = client.getAccessToken(accessTokenRequest);
System.out.println(JSON.toJSONString(accessToken.getBody()));
}
步骤五:调用服务端客户群组、客户群相关API
客户群组相关API:
1.
public void createCustomerGroupSet() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkcrm_1_0.Client client = new com.aliyun.dingtalkcrm_1_0.Client(config);
CreateGroupSetHeaders createGroupSetHeaders = new CreateGroupSetHeaders();
createGroupSetHeaders.xAcsDingtalkAccessToken = "<your access token>";
CreateGroupSetRequest createGroupSetRequest = new CreateGroupSetRequest()
.setName("群组名")
.setOwnerUserId("301227837930")
.setCreatorUserId("301227837930")
.setMemberQuota(100)
.setManagerUserIds("301227837930,301227837935")
.setNotice("公告")
.setNoticeToped(1)
.setRelationType("crm_customer_personal")
.setWelcome("欢迎加入");
try {
CreateGroupSetResponse groupSetWithOptions = client.createGroupSetWithOptions(createGroupSetRequest, createGroupSetHeaders, new RuntimeOptions());
System.out.println(JSON.toJSONString(groupSetWithOptions.getBody()));
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
}
}
2.
openGroupSetId
进行客户群组管理操作。 public void updateCustomerGroupSet() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkcrm_1_0.Client client = new com.aliyun.dingtalkcrm_1_0.Client(config);
UpdateGroupSetHeaders updateGroupSetHeaders = new UpdateGroupSetHeaders();
updateGroupSetHeaders.xAcsDingtalkAccessToken = "<your access token>";
UpdateGroupSetRequest updateGroupSetRequest = new UpdateGroupSetRequest()
.setOpenGroupSetId("dfgfghfghdsfdsf")
.setName("营销群")
.setMemberQuota(200)
.setOwnerUserId("301227837938")
.setManagerUserIds("301227837938")
.setNotice("公告")
.setNoticeToped(1)
.setWelcome("欢迎入群");
try {
UpdateGroupSetResponse updateGroupSetResponse = client.updateGroupSetWithOptions(updateGroupSetRequest, updateGroupSetHeaders, new RuntimeOptions());
System.out.println(JSON.toJSONString(updateGroupSetResponse.getBody()));
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
}
}
openGroupSetId
,调用服务端API-获取单个客户群组详情接口,进行查询单个客户群组详情。 public void getCustomerGroupSet() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkcrm_1_0.Client client = new com.aliyun.dingtalkcrm_1_0.Client(config);
GetGroupSetHeaders getGroupSetHeaders = new GetGroupSetHeaders();
getGroupSetHeaders.xAcsDingtalkAccessToken = "<your access token>";
GetGroupSetRequest getGroupSetRequest = new GetGroupSetRequest()
.setOpenGroupSetId("OkldZxxxx");
try {
GetGroupSetResponse groupSetWithOptions = client.getGroupSetWithOptions(getGroupSetRequest, getGroupSetHeaders, new RuntimeOptions());
System.out.println(JSON.toJSONString(groupSetWithOptions.getBody()));
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
}
}
3.
public void queryCustomerGroupSets() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkcrm_1_0.Client client = new com.aliyun.dingtalkcrm_1_0.Client(config);
ListGroupSetHeaders listGroupSetHeaders = new ListGroupSetHeaders();
listGroupSetHeaders.xAcsDingtalkAccessToken = "<your access token>";
ListGroupSetRequest listGroupSetRequest = new ListGroupSetRequest()
.setNextToken("fasafsafsd")
.setMaxResults(10)
.setQueryDsl("{\"queryGroupList\":[{\"logicType\":\"AND\",\"queryObjectList\":[{\"filterType\":\"SEARCH\",\"value\":\"XX\",\"fieldId\":\"name\"}]}]}")
.setRelationType("crm_customer_personal");
try {
ListGroupSetResponse listGroupSetResponse = client.listGroupSetWithOptions(listGroupSetRequest, listGroupSetHeaders, new RuntimeOptions());
System.out.println(JSON.toJSONString(listGroupSetResponse.getBody()));
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
}
}
客户群相关API:
1.
public void createCustomerGroup() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkcrm_1_0.Client client = new com.aliyun.dingtalkcrm_1_0.Client(config);
CreateGroupHeaders createGroupHeaders = new CreateGroupHeaders();
createGroupHeaders.xAcsDingtalkAccessToken = "<your access token>";
CreateGroupRequest createGroupRequest = new CreateGroupRequest()
.setGroupName("abc")
.setOwnerUserId("abc123")
.setMemberUserIds("a,b,c")
.setRelationType("abc");
try {
CreateGroupResponse groupWithOptions = client.createGroupWithOptions(createGroupRequest, createGroupHeaders, new RuntimeOptions());
System.out.println(JSON.toJSONString(groupWithOptions.getBody()));
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
}
}
2.
openConversationId
进行客户群管理操作。 public void getCustomerGroup() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkcrm_1_0.Client client = new com.aliyun.dingtalkcrm_1_0.Client(config);
GetCrmGroupChatSingleHeaders getCrmGroupChatSingleHeaders = new GetCrmGroupChatSingleHeaders();
getCrmGroupChatSingleHeaders.xAcsDingtalkAccessToken = "<your access token>";
GetCrmGroupChatSingleRequest getCrmGroupChatSingleRequest = new GetCrmGroupChatSingleRequest()
.setOpenConversationId("afasd1321");
try {
GetCrmGroupChatSingleResponse crmGroupChatSingleWithOptions = client.getCrmGroupChatSingleWithOptions(getCrmGroupChatSingleRequest, getCrmGroupChatSingleHeaders, new RuntimeOptions());
System.out.println(JSON.toJSONString(crmGroupChatSingleWithOptions.getBody()));
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
}
}
openConversationId
,调用服务端API-批量查询客户群接口,进行批量批量查询客户群详情。 public void batchGetCustomerGroups() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkcrm_1_0.Client client = new com.aliyun.dingtalkcrm_1_0.Client(config);
GetCrmGroupChatMultiHeaders getCrmGroupChatMultiHeaders = new GetCrmGroupChatMultiHeaders();
getCrmGroupChatMultiHeaders.xAcsDingtalkAccessToken = "<your access token>";
GetCrmGroupChatMultiRequest getCrmGroupChatMultiRequest = new GetCrmGroupChatMultiRequest()
.setOpenConversationIds(java.util.Arrays.asList(
"cidQJKDN****=="
));
try {
GetCrmGroupChatMultiResponse crmGroupChatMultiWithOptions = client.getCrmGroupChatMultiWithOptions(getCrmGroupChatMultiRequest, getCrmGroupChatMultiHeaders, new RuntimeOptions());
System.out.println(JSON.toJSONString(crmGroupChatMultiWithOptions.getBody()));
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
}
}
3.
public void queryCustomerGroups() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkcrm_1_0.Client client = new com.aliyun.dingtalkcrm_1_0.Client(config);
QueryCrmGroupChatsHeaders queryCrmGroupChatsHeaders = new QueryCrmGroupChatsHeaders();
queryCrmGroupChatsHeaders.xAcsDingtalkAccessToken = "<your access token>";
QueryCrmGroupChatsRequest queryCrmGroupChatsRequest = new QueryCrmGroupChatsRequest()
.setRelationType("crm_customer_personal")
.setNextToken("fasdfs1")
.setMaxResults(10)
.setQueryDsl("{\"queryGroupList\":[{\"logicType\":\"AND\",\"queryObjectList\":[{\"filterType\":\"SEARCH\",\"value\":\"测试客户群\",\"fieldId\":\"name\"},{\"filterType\":\"LT\",\"value\":\"2640002249001\",\"fieldId\":\"gmtCreate\"}]}],\"orderByFields\":[{\"orderByFieldId\":\"gmtCreate\",\"orderByDirection\":\"ASC\"}]}");
try {
QueryCrmGroupChatsResponse queryCrmGroupChatsResponse = client.queryCrmGroupChatsWithOptions(queryCrmGroupChatsRequest, queryCrmGroupChatsHeaders, new RuntimeOptions());
System.out.println(JSON.toJSONString(queryCrmGroupChatsResponse.getBody()));
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
System.out.println(err.code);
System.out.println(err.message);
}
}
}
修改于 2024-01-18 07:15:57