# 客服接口-發消息
## 發送文本消息
```
$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);
```