外部联系人管理

获取实例

  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. $data = [
  2. "userid"=>'员工id',
  3. "external_userid"=>'客户id',
  4. "remark"=> '新备注',
  5. "description"=>'新描述',
  6. "remark_company"=>'新公司',
  7. "remark_mobiles"=>[ '电话1','电话2'],
  8. "remark_pic_mediaid"=> "MEDIAID"
  9. ];
  10. $app->external_contact->remark($data);

获取离职成员的客户列表

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

分配成员的客户(离职或在职)

  1. $externalUserId = 'woAJ2GCAAAXtWyujaWJHDDGi0mACH71w';
  2. $handoverUserId = 'zhangsan';
  3. $takeoverUserId = 'lisi';
  4. $transferSuccessMessage = '您好,您的服务已升级,后续将由我的同事张三@腾讯接替我的工作,继续为您服务。'; //不填则使用默认文案
  5. $app->external_contact->transfer($externalUserId, $handoverUserId, $takeoverUserId, $transferSuccessMessage);

离职成员的群再分配

  1. $chatIds = ['群聊id1', '群聊id2'];
  2. $takeoverUserId = '接替群主userid';
  3. $app->external_contact->transferGroupChat($chatIds, $takeoverUserId);

查询客户接替结果

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

客户群管理

获取客户群列表

  1. $params = [
  2. "status_filter" => 0,
  3. "owner_filter" => [
  4. "userid_list" => ["abel"],
  5. "partyid_list" => [7]
  6. ],
  7. "offset" => 0,
  8. "limit" => 100
  9. ];
  10. $app->external_contact->getGroupChats(array $params);

获取客户群详情

  1. $chatId = 'wrOgQhDgAAMYQiS5ol9G7gK9JVAAAA';
  2. $app->external_contact->getGroupChat(string $chatId);

客户标签管理

注意: 对于添加/删除/编辑企业客户标签接口,目前仅支持使用“客户联系”secret所获取的accesstoken来调用。 原文: https://work.weixin.qq.com/api/doc/90000/90135/92117

获取企业标签库

  1. $tagIds = [
  2. "etXXXXXXXXXX",
  3. "etYYYYYYYYYY"
  4. ];
  5. $app->external_contact->getCorpTags(array $tagIds=[]);

添加企业客户标签

  1. $params = [
  2. "group_id" => "GROUP_ID",
  3. "group_name" => "GROUP_NAME",
  4. "order" => 1,
  5. "tag" => [
  6. [
  7. "name" => "TAG_NAME_1",
  8. "order" => 1
  9. ],
  10. [
  11. "name" => "TAG_NAME_2",
  12. "order" => 2
  13. ]
  14. ]
  15. ];
  16. $app->external_contact->addCorpTag(array $params);

编辑企业客户标签

  1. $id = 'TAG_ID';
  2. $name = 'NEW_TAG_NAME';
  3. $order = 1;
  4. $app->external_contact->updateCorpTag(string $id, string $name, int $order = 1);

删除企业客户标签

  1. $tagId = [
  2. 'TAG_ID_1',
  3. 'TAG_ID_2'
  4. ];
  5. $groupId = [
  6. 'GROUP_ID_1',
  7. 'GROUP_ID_2'
  8. ];
  9. $app->external_contact->deleteCorpTag(array $tagId,array $groupId);

编辑客户企业标签

  1. $params = [
  2. "userid" => "zhangsan",
  3. "external_userid" => "woAJ2GCAAAd1NPGHKSD4wKmE8Aabj9AAA",
  4. "add_tag" => ["TAGID1", "TAGID2"],
  5. "remove_tag" => ["TAGID3", "TAGID4"]
  6. ];
  7. $app->external_contact->markTags(array $params);

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

{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);