DEMO: Voice/Send - 语音呼叫


代码示例

<?php
    /*****************
     * 非加密请求 示例代码
     ******************/
    //appid参数 appkey参数在     语音-创建/管理AppID中获取
    //手机号支持单个
    //语音内容    详细规则查看语音-模板管理
    $appid = '6***3';                                                               //appid参数
    $appkey = '5d****************************58';                                   //appkey参数
    $to = '150********';                                                            //收信人 手机号码
    $content = '尊敬的用户,我是SUBMAIL';                                               //内容

    $post_data = array(
        "appid"     => $appid,
        "signature" => $appkey,
        "to"        => $to,
        "content"   => $content,
    );

    $ch = curl_init();
    curl_setopt_array($ch , array(
        CURLOPT_URL             => 'https://api-v4.mysubmail.com/voice/send.json' ,
        CURLOPT_RETURNTRANSFER  => 1 ,
        CURLOPT_POST            => 1 ,
        CURLOPT_POSTFIELDS      => $post_data
    ));
    $output = curl_exec($ch);
    curl_close($ch);

    echo json_encode($output);




    /*****************
     * 加密请求 示例代码
     ******************/
    //appid参数 appkey参数在     语音-创建/管理AppID中获取
    //手机号支持单个
    //语音内容    详细规则查看语音-模板管理
    $appid = '6***3';                                                               //appid参数
    $appkey = '5d****************************58';                                   //appkey参数
    $to = '150********';                                                            //收信人 手机号码
    $content = '尊敬的用户,我是SUBMAIL';                                               //内容

    //通过接口获取时间戳
    $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL            => 'https://api-v4.mysubmail.com/service/timestamp.json',
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_POST           => 0,
    ));
    $output = curl_exec($ch);
    curl_close($ch);
    $output = json_decode($output, true);
    $timestamp = $output['timestamp'];

    $post_data = array(
        "appid"         => $appid,
        "to"            => $to,
        "timestamp"     => $timestamp,
        "sign_type"     => 'md5',
        "sign_version"  => 2,
        "content"       => $content,
    );

    $temp = $post_data;
    unset($temp['content']);
    ksort($temp);
    reset($temp);
    $tempStr = "";
    foreach ($temp as $key => $value) {
        $tempStr.=$key."=".$value."&";
    }
    $tempStr = substr($tempStr,0,-1);
    //生成签名
    $post_data['signature'] = md5($appid.$appkey.$tempStr.$appid.$appkey);

    $ch = curl_init();
    curl_setopt_array($ch , array(
        CURLOPT_URL             => 'https://api-v4.mysubmail.com/voice/send.json' ,
        CURLOPT_RETURNTRANSFER  => 1 ,
        CURLOPT_POST            => 1 ,
        CURLOPT_POSTFIELDS      => $post_data
    ));
    $output = curl_exec($ch);
    curl_close($ch);

    echo json_encode($output);