外部联系人管理

获取实例

  1. $config = [
  2. 'corp_id' => 'xxxxxxxxxxxxxxxxx',
  3. 'secret' => 'xxxxxxxxxx',
  4. ...
  5. ];
  6. $app = Factory::work($config);
  7. // 基础接口
  8. $app->external_contact;
  9. // 「联系我」
  10. $app->contact_way;
  11. // 消息管理
  12. $app->external_contact_message;
  13. // 数据统计
  14. $app->external_contact_statistics;

基础接口

获取配置了客户联系功能的成员列表

  1. $app->external_contact->getFollowUsers();

获取外部联系人列表

  1. $userId = 'zhangsan';
  2. $app->external_contact->list($userId);

获取外部联系人详情

  1. $externalUserId = 'woAJ2GCAAAXtWyujaWJHDDGi0mACH71w';
  2. $app->external_contact->get($externalUserId);

获取离职成员的客户列表

  1. $pageId = 0;
  2. $pageSize = 1000;
  3. $app->external_contact->getUnassigned($pageId, $pageSize);

离职成员的外部联系人再分配

  1. $externalUserId = 'woAJ2GCAAAXtWyujaWJHDDGi0mACH71w';
  2. $handoverUserId = 'zhangsan';
  3. $takeoverUserId = 'lisi';
  4. $app->external_contact->transfer($externalUserId, $handoverUserId, $takeoverUserId);

配置客户联系「联系我」方式

{warning} 注意:

  1. 通过API添加的「联系我」不会在管理端进行展示。
  2. 每个企业可通过API最多配置10万个「联系我」。
  3. 截止 2019-06-21 官方文档没有提供获取所有「联系我」列表的接口,请开发者注意自行保管处理 configId,避免无法溯源。

增加「联系我」方式

  1. $type = 1;
  2. $scene = 1;
  3. $config = [
  4. 'style' => 1,
  5. 'remark' => '渠道客户',
  6. 'skip_verify' => true,
  7. 'state' => 'teststate',
  8. 'user' => ['UserID1', 'UserID2', 'UserID3'],
  9. ];
  10. $app->contact_way->create($type, $scene, $config);
  11. // {
  12. // "errcode": 0,
  13. // "errmsg": "ok",
  14. // "config_id":"42b34949e138eb6e027c123cba77fad7"  
  15. // }

获取「联系我」方式

  1. $configId = '42b34949e138eb6e027c123cba77fad7';
  2. $app->contact_way->get($configId);

更新「联系我」方式

  1. $configId = '42b34949e138eb6e027c123cba77fad7';
  2. $config = [
  3. 'style' => 1,
  4. 'remark' => '渠道客户2',
  5. 'skip_verify' => true,
  6. 'state' => 'teststate2',
  7. 'user' => ['UserID4', 'UserID5', 'UserID6'],
  8. ];
  9. $app->contact_way->update($configId, $config);

删除「联系我」方式

  1. $configId = '42b34949e138eb6e027c123cba77fad7';
  2. $app->contact_way->delete($configId);

消息管理

添加企业群发消息模板

  1. $msg = [
  2. 'external_userid' => [
  3. 'woAJ2GCAAAXtWyujaWJHDDGi0mACas1w',
  4. 'wmqfasd1e1927831291723123109r712',
  5. ],
  6. 'sender' => 'zhangsan',
  7. 'text' => [
  8. 'content' => '文本消息内容',
  9. ],
  10. 'image' => [
  11. 'media_id' => 'MEDIA_ID',
  12. ],
  13. 'link' => [
  14. 'title' => '消息标题',
  15. 'picurl' => 'https://example.pic.com/path',
  16. 'desc' => '消息描述',
  17. 'url' => 'https://example.link.com/path',
  18. ],
  19. 'miniprogram' => [
  20. 'title' => '消息标题',
  21. 'pic_media_id' => 'MEDIA_ID',
  22. 'appid' => 'wx8bd80126147df384',
  23. 'page' => '/path/index',
  24. ],
  25. ];
  26. $app->external_contact_message->submit($msg);
  27. // {
  28. // "errcode": 0,
  29. // "errmsg": "ok",
  30. // "fail_list":["wmqfasd1e19278asdasdasd"],
  31. // "msgid":"msgGCAAAXtWyujaWJHDDGi0mACas1w"
  32. // }

获取企业群发消息发送结果

  1. $msgId = 'msgGCAAAXtWyujaWJHDDGi0mACas1w';
  2. $app->external_contact_message->get($msgId);

发送新客户欢迎语

  1. $welcomeCode = 'WELCOMECODE';
  2. $msg = [
  3. 'text' => [
  4. 'content' => '文本消息内容',
  5. ],
  6. 'image' => [
  7. 'media_id' => 'MEDIA_ID',
  8. ],
  9. 'link' => [
  10. 'title' => '消息标题',
  11. 'picurl' => 'https://example.pic.com/path',
  12. 'desc' => '消息描述',
  13. 'url' => 'https://example.link.com/path',
  14. ],
  15. 'miniprogram' => [
  16. 'title' => '消息标题',
  17. 'pic_media_id' => 'MEDIA_ID',
  18. 'appid' => 'wx8bd80126147df384',
  19. 'page' => '/path/index',
  20. ],
  21. ];
  22. $app->external_contact_message->sendWelcome($welcomeCode, $msg);

数据统计

获取员工行为数据

  1. $userIds = [
  2. 'zhangsan',
  3. 'lisi'
  4. ];
  5. $from = 1536508800;
  6. $to = 1536940800;
  7. $app->external_contact_statistics->userBehavior($userIds, $from, $to);