多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 客服接口-发消息 ## 发送文本消息 ``` $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); ```