365体育备用网址报道9.1.1客服接口实现_365体育备用网址官网资讯

当用户和公众号发生特定动作的交互时,微信将会把消息数据推送给开拓者,开拓者能够在一段时间内(当前为48小时)调用客服接口,通过POST一个JSON数据包来发送消息给一般用户。此接口主要用于客服等有人工消息处置环节的功能,方便开拓者为用户提供更加优质的服务。
当前同意的动作列表如下:

  1. 用户发送信息
  2. 点击自定义菜单(仅有点击推事情、扫码推事情、扫码推事情且弹出“消息接收中”提示框这3种菜单类型是会触发客服接口的)
  3. 关切公众号
  4. 扫描二维码
  5. 支付胜利
  6. 用户维权
    我们能够直接构造文本和图文消息回复给用户。而音乐、爱拼在线国际、语音、视频四种消息,需要首先获得素材的media_id,这能够从用户发送过来的消息那获得,也能够通过上传多赛马会 手机版文件来获得。
    发送客服消息的接口如下:
    https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
    发送各种类型的客服消息介绍如下:
  1. 向用户发送文本
    向用户发送文本数据格式如下:
{
    "touser":"OPENID",
    "msgtype":"text",
    "text":
    {
         "content":"Hello World"
    }
}

该数据参数说明如表9-1所示:

表9-1客服接口文本消息参数说明
向用户发送文本消息的代码实现如下:

$access_token = "nFX6GFsspSLBKJLgMQ3kj1YM8_FchRE7vE2ZOIlmfiCOQntZKnBwuOen2GCBpFHBYS4QLGX9fGoVfA36tftME2sRiYsKPzgGQKU-ygU7x8cgy_1tlQ4n1mhSumwQEGy6PK6rDTDo8O8GROuGE3Hiag";
$openid = "o7Lp5t6n59DeX3U0C7Kric9qEx-Q";
$data = '{
    "touser":"'.$openid.'",
    "msgtype":"text",
    "text":
    {
         "content":"Hello World"
    }
}';
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
$result = https_request($url, $data);
var_dump($result);

function https_request($url, $data)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($curl);
    if (curl_errno($curl)) {
        return 'Errno'.curl_error($curl);
    }
    curl_close($curl);
    return $result;
}

上述代码执行后,效果如图9-1所示:

图9-1微信公众账号发送文本消息
2) 向用户发送图文
向用户发送图文时,发送的数据格式如下:

{
    "touser":"OPENID",
    "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"
         }
         ]
    }
}

该数据参数说明如表9-2所示:

表9-2客服接口图文消息参数说明
向用户发送图文消息的代码实现如下:

$access_token = "nFX6GFsspSLBKJLgMQ3kj1YM8_FchRE7vE2ZOIlmfiCOQntZKnBwuOen2GCBpFHBYS4QLGX9fGoVfA36tftME2sRiYsKPzgGQKU-ygU7x8cgy_1tlQ4n1mhSumwQEGy6PK6rdTdo8O8GROuGE3Hiag";
$openid = "o7Lp5t6n59DeX3U0C7Kric9qEx-Q";
$data = '{
    "touser":"'.$openid.'",
    "msgtype":"text",
    "text":
    {
         "content":"Hello World"
    }
}';
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
$result = https_request($url, $data);
var_dump($result);

function https_request($url, $data)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($curl);
    if (curl_errno($curl)) {
        return 'Errno'.curl_error($curl);
    }
    curl_close($curl);
    return $result;
}

上述代码执行后,效果如图9-2所示:

图9-2微信公众账号发送图文消息
3) 向用户发送音乐
向用户发送音乐时,数据格式如下:

{
    "touser":"OPENID",
    "msgtype":"music",
    "music":
    {
      "title":"MUSIC_TITLE",
      "description":"MUSIC_DESCRIPTION",
      "musicurl":"MUSIC_URL",
      "hqmusicurl":"HQ_MUSIC_URL",
      "thumb_media_id":"THUMB_MEDIA_ID" 
    }
}

该数据参数说明如表9-3所示:

表9-3客服接口音乐消息参数说明
发送音乐消息的代码实现如下:

$access_token = "NU7Kr6v9L9TQaqm5NE3OTPctTZx797Wxw4Snd2WL2HHBqLCiXlDVOw2l-Se0I-WmOLLniAYLAwzhbYhXNjbLc_KAA092cxkmpj5FpuqNO0IL7bB0Exz5s5qC9Umypy-rz2y441W9qgfnmNtIZWSjSQ";
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
$openid = "oLVPpjqs9BhvzwPj5A-vTYAX3GLc";

//发送音乐
$data = '{
    "touser": "'.$openid.'", 
    "msgtype": "music", 
    "music": {
        "title": "最炫民族风", 
        "description": "凤凰传奇", 
        "musicurl": "http://122.228.226.40/music/zxmzf.mp3", 
        "hqmusicurl": "http://122.228.226.40/music/zxmzf.mp3", 
        "thumb_media_id": "b8as-GpA_EFqVoPY7vPT3fpVZBWJb27K77De2dc_0FZml-UExlTMP7IVMz89uh3W"
    }
}';
$result = https_request($url,$data);
var_dump($result);

function https_request($url, $data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}

上述代码执行后,效果如图9-3所示:

图9-3微信公众账号发送音乐消息
4) 向用户发送爱拼在线国际
向用户发送爱拼在线国际时,数据格式如下:

{
    "touser":"OPENID",
    "msgtype":"image",
    "image":
    {
      "media_id":"MEDIA_ID"
    }
}

该数据参数说明如表9-4所示:

表9-4客服接口爱拼在线国际消息参数说明
发送爱拼在线国际消息的代码实现如下:

$access_token = "NU7Kr6v9L9TQaqm5NE3OTPctTZx797Wxw4Snd2WL2HHBqLCiXlDVOw2l-Se0I-WmOLLniAYLAwzhbYhXNjbLc_KAA092cxkmpj5FpuqNO0IL7bB0Exz5s5qC9Umypy-rz2y441W9qgfnmNtIZWSjSQ";
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
$openid = "oLVPpjqs9BhvzwPj5A-vTYAX3GLc";

//发送爱拼在线国际
$data = '{
    "touser":"'.$openid.'",
    "msgtype":"image",
    "image":
    {
      "media_id":"jViS8sQUXIh6rTdkz2qUOD5pvChYpp50i9rsLR4YnCm-pqdpiHhz6xbN2KAboScV"
    }
}';
$result = https_request($url,$data);
var_dump($result);

function https_request($url, $data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}

代码执行后,效果如图9-4所示:

图9-4微信公众账号发送爱拼在线国际消息
5) 向用户发送语音
向用户发送语音时,数据格式如下:

{
    "touser":"OPENID",
    "msgtype":"voice",
    "voice":
    {
      "media_id":"MEDIA_ID"
    }
}

该数据参数说明如表9-5所示:

表9-5客服接口语音消息参数说明
向用户发送语音消息的代码实现如下:

$access_token = "NU7Kr6v9L9TQaqm5NE3OTPctTZx797Wxw4Snd2WL2HHBqLCiXlDVOw2l-Se0I-WmOLLniAYLAwzhbYhXNjbLc_KAA092cxkmpj5FpuqNO0IL7bB0Exz5s5qC9Umypy-rz2y441W9qgfnmNtIZWSjSQ";
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
$openid = "oLVPpjqs9BhvzwPj5A-vTYAX3GLc";

//发送语音
$data= '
{
    "touser": "'.$openid.'", 
    "msgtype": "voice", 
    "voice": {
        "media_id": "gAn8fV1hQB8mtLf6X2YTN-3ySaBMlzvbCLAzFUhPQDRVrWA1o9tRCnzxa4bEzUiM"
    }
}';
$result = https_request($url,$data);
var_dump($result);

function https_request($url, $data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}

上述代码执行后,效果如图9-5所示:

图9-5微信公众账号发送语音消息
6) 向用户发送视频
向用户发送视频时,数据格式如下:

{
    "touser":"OPENID",
    "msgtype":"video",
    "video":
    {
      "media_id":"MEDIA_ID",
      "title":"TITLE",
      "description":"DESCRIPTION"
    }
}

该数据参数说明如表9-6所示:

表9-6客服接口视频消息参数说明
向用户发送视频消息的代码实现如下:

$access_token = "NU7Kr6v9L9TQaqm5NE3OTPctTZx797Wxw4Snd2WL2HHBqLCiXlDVOw2l-Se0I-WmOLLniAYLAwzhbYhXNjbLc_KAA092cxkmpj5FpuqNO0IL7bB0Exz5s5qC9Umypy-rz2y441W9qgfnmNtIZWSjSQ";
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
$openid = "oLVPpjqs9BhvzwPj5A-vTYAX3GLc";

//发送视频
$data = '{
    "touser": "'.$openid.'", 
    "msgtype": "video", 
    "video": {
        "media_id": "zbpy8wXj2UtIKB_56QUddCYLmWPLVeHoKqE94h2-nB9weSU65nVKTpE909Mvi8b5", 
        "thumb_media_id": "b8as-GpA_EFqVoPY7vPT3fpVZBWJb27K77De2dc_0FZml-UExlTMP7IVMz89uh3W"
    }
}';
$result = https_request($url,$data);
var_dump($result);

function https_request($url, $data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}

上述代码执行后,效果如图9-6所示:

图9-6微信公众账号发送视频消息
7) 向用户发送卡券
向用户发送卡券时,数据格式如下:

{
    "touser":"oiPuduCHIBb2aHvZoqSm1t7KbXtw",
    "msgtype":"wxcard",
    "wxcard":{
        "card_id":"piPuduM3NHSnSMYgWS-oqGFQbBjM"
    }
}

该数据参数说明如表9-7所示:

表9-7客服接口卡券消息参数说明
向用户发送视频消息的代码实现如下:

$access_token = "O1AEwCSSQQlPjGlDdI-f_yd8u2mRmpYY_knJaqQ5t5Wl9Wr_TXeWaI0--JPwU3hcjX1GdtpjHn4tAJFmgKeJKOH9K4GPVjcyhR1utGkEAd4RSNiAAAXYT";
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
$openid = "oiPuduCHIBb2aHvZoqSm1t7KbXtw";

//发送卡券
$data = '{
    "touser":"'.$openid.'",
    "msgtype":"wxcard",
    "wxcard":{
        "card_id":"piPuduM3NHSnSMYgWS-oqGFQbBjM"
    }
}';
$result = https_request($url,$data);
var_dump($result);

function https_request($url, $data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}

上述代码执行后,效果如图9-7所示:

图9-7微信公众账号发送卡券消息

------分隔线----------------------------

公布评论 (176人察看0条评论)
请自觉遵守互联网相关的政策法规,严禁公布色情、暴力、反动的言论。
用户名: 验证码: 点击我更换爱拼在线国际
最新评论