# 客服接口-发消息
[toc]
## 发送文本消息
```php
$data = [
"touser" => "粉丝的OPENID",
"msgtype" => "text",
"text" => [
"content" => "我是消息内容哟",
],
];
$res = WeChat::instance('CustomService')->send($data);
```
## 发送图片消息
```php
$data = [
"touser" => "粉丝的OPENID",
"msgtype" => "image",
"image" => [
"media_id" => "素材编号",
],
];
$res = WeChat::instance('CustomService')->send($data);
```
## 发送语音消息
```php
$data = [
"touser" => "oGiQGuMR-fR_WeD6gLRKnqgMxYGo",
"msgtype" => "voice",
"voice" => [
"media_id" => "素材编号",
],
];
$res = WeChat::instance('CustomService')->send($data);
```
## 发送视频消息
```php
$data = [
"touser" => "oGiQGuMR-fR_WeD6gLRKnqgMxYGo",
"msgtype" => "video",
"video" => [
"media_id"=>"视频素材编号",
"thumb_media_id"=>"图片素材编号",
"title":"TITLE",
"description"=>"DESCRIPTION"
],
];
$res = WeChat::instance('CustomService')->send($data);
```
## 发送音乐消息
```php
$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,则将会无响应。
```php
$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,则将会无响应。
```php
$data = [
"touser" => "oGiQGuMR-fR_WeD6gLRKnqgMxYGo",
"msgtype" => "mpnews",
"mpnews" =>['media_id'=>'MEDIA_ID']
];
$res = WeChat::instance('CustomService')->send($data);
```
## 发送卡券
发送图文消息(点击跳转到图文消息页面) 图文消息条数限制在8条以内,注意,如果图文数超过8,则将会无响应。
```php
$data = [
"touser" => "oGiQGuMR-fR_WeD6gLRKnqgMxYGo",
"msgtype" => "wxcard",
"wxcard" =>["card_id"=>"123dsdajkasd231jhksad"]
];
$res = WeChat::instance('CustomService')->send($data);
```
## 指定客服帐号发送消息
如果需要以某个客服帐号来发消息(在微信6.0.2及以上版本中显示自定义头像),则需在JSON数据包的后半部分加入customservice参数,例如发送文本消息则改为:
```php
$data = [
"touser" => "粉丝的OPENID",
"msgtype" => "text",
"text" => [
"content" => "我是消息内容哟",
],
"customservice"=>[
"kf_account"=>"xxx@163.com"
]
];
$res = WeChat::instance('CustomService')->send($data);
```