# 客服管理

# 添加帐号

 $data = [
 	//完整客服账号,格式为:账号前缀@公众号微信号
	'kf_account' => 'hdxj@aihoudun',
	'nickname'   => '测试客服',
	'password'   => md5('admin888'),
];
$res  = WeChat::instance('CustomService')->addCustomer($data);

返回说明

[
	"errcode" =>0,
	"errmsg" =>"ok",
]

# 修改帐号

开发者可以通过本接口为公众号修改客服账号。

 $data = [
 	//完整客服账号,格式为:账号前缀@公众号微信号
	'kf_account' => 'hdxj@aihoudun',
	'nickname'   => '客服',
	'password'   => md5('admin888'),
];
$res  = WeChat::instance('CustomService')->updateCustomer($data);

返回说明

[
	"errcode" =>0,
	"errmsg" =>"ok",
]

# 删除帐号

开发者可以通过该接口为公众号删除客服帐号。

$res  = WeChat::instance('CustomService')->delCustomer('xj@aihoudun');

返回说明

[
	"errcode" =>0,
	"errmsg" =>"ok",
]

# 设置头像

开发者可调用本接口来上传图片作为客服人员的头像,头像图片文件必须是jpg格式,推荐使用640*640大小的图片以达到最佳效果。

$data = [
	'kf_account' => 'hdxj@aihoudun',
	'file'       		=> 'tests/images/user.jpg',
];
$res  = WeChat::instance('CustomService')->uploadheadimg($data);

返回说明

[
	"errcode" =>0,
	"errmsg" =>"ok",
]

# 获取账号

开发者通过本接口,获取公众号中所设置的客服基本信息,包括客服工号、客服昵称、客服登录账号。

$res = WeChat::instance('CustomService')->getkflist();

# 发送消息

# 发送文本消息

$data = [
	"touser"  => "粉丝的OPENID",
	"msgtype" => "text",
	"text"    => [
		"content" => "后盾人 人人做后盾",
	],
];
$res  = WeChat::instance('CustomService')->send($data);

# 发送图片消息

$data = [
	"touser"  => "粉丝的OPENID",
	"msgtype" => "image",
	"image"    => [
		"media_id" => "素材编号",
	],
];
$res  = WeChat::instance('CustomService')->send($data);

# 发送语音消息

$data = [
	"touser"  => "oGiQGuMR-fR_WeD6gLRKnqgMxYGo",
	"msgtype" => "voice",
	"voice"    => [
		"media_id" => "素材编号",
	],
];
$res  = WeChat::instance('CustomService')->send($data);

# 发送视频消息

$data = [
	"touser"  => "oGiQGuMR-fR_WeD6gLRKnqgMxYGo",
	"msgtype" => "video",
	"video"    => [
		"media_id"=>"视频素材编号",
		"thumb_media_id"=>"图片素材编号",
		"title":"TITLE",
		"description"=>"DESCRIPTION"
	],
];
$res  = WeChat::instance('CustomService')->send($data);

# 发送音乐消息

$data = [
	"touser"  => "oGiQGuMR-fR_WeD6gLRKnqgMxYGo",
	"msgtype" => "music",
	"music"    => [
		 "title"=>"MUSIC_TITLE",
		"description"=>"MUSIC_DESCRIPTION",
		"musicurl"=>"MUSIC_URL",
		"hqmusicurl"=>"HQ_MUSIC_URL",
		"thumb_media_id"=>"THUMB_MEDIA_ID" 
	],
];
$res  = WeChat::instance('CustomService')->send($data);

# 发送图文消息

图文消息条数限制在8条以内,注意,如果图文数超过8,则将会无响应(点击跳转到外链)。

$data = [
	"touser"  => "oGiQGuMR-fR_WeD6gLRKnqgMxYGo",
	"msgtype" => "news",
	"news"    => [
		"articles": [
			[
				"title":"Happy Day",
				"description":"Is Really A Happy Day",
				"url":"URL",
				"picurl":"PIC_URL"
			],
			[
				"title":"Happy Day",
				"description":"Is Really A Happy Day",
				"url":"URL",
				"picurl":"PIC_URL"
			]
		]
	]
];
$res  = WeChat::instance('CustomService')->send($data);

# 发送图文消息

发送图文消息(点击跳转到图文消息页面) 图文消息条数限制在8条以内,注意,如果图文数超过8,则将会无响应(点击跳转到图文消息页面)。

$data = [
	"touser"  => "oGiQGuMR-fR_WeD6gLRKnqgMxYGo",
	"msgtype" => "mpnews",
	"mpnews"    =>['media_id'=>'MEDIA_ID']
];
$res  = WeChat::instance('CustomService')->send($data);

# 发送卡券

发送图文消息(点击跳转到图文消息页面) 图文消息条数限制在8条以内,注意,如果图文数超过8,则将会无响应。

$data = [
	"touser"  => "oGiQGuMR-fR_WeD6gLRKnqgMxYGo",
	"msgtype" => "wxcard",
	"wxcard"    =>["card_id"=>"123dsdajkasd231jhksad"]
];
$res  = WeChat::instance('CustomService')->send($data);

# 指定帐号发送消息

如果需要以某个客服帐号来发消息(在微信6.0.2及以上版本中显示自定义头像),则需在JSON数据包的后半部分加入customservice参数,例如发送文本消息则改为:

$data = [
	"touser"  => "粉丝的OPENID",
	"msgtype" => "text",
	"text"    => [
		"content" => "后盾人 人人做后盾",
	],
    "customservice"=>[
    	"kf_account"=>"hdxj@aihoudun"
    ]
];
$res  = WeChat::instance('CustomService')->send($data);