PHP DEMO


功能說(shuō)明:該接口要求提前在云片后臺(tái)添加模板,提交短信時(shí),系統(tǒng)會(huì)自動(dòng)匹配審核通過(guò)的模板,匹配成功任意一個(gè)模板即可發(fā)送。系統(tǒng)已提供的默認(rèn)模板添加簽名后可以直接使用。


<?php
header("Content-Type:text/html;charset=utf-8");
$apikey = "xxxxxxxxxxx"; //修改為您的apikey(http://www.ssjdyy2.com)登錄官網(wǎng)后獲取
$mobile = "xxxxxxxxxxx"; //請(qǐng)用自己的手機(jī)號(hào)代替
$text="【云片網(wǎng)】您的驗(yàn)證碼是1234,5分鐘內(nèi)有效。";
$ch = curl_init();

/* 設(shè)置驗(yàn)證方式 */
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
    'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
/* 設(shè)置返回結(jié)果為流 */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

/* 設(shè)置超時(shí)時(shí)間*/
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

/* 設(shè)置通信方式 */
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// 取得用戶信息
$json_data = get_user($ch,$apikey);
$array = json_decode($json_data,true);
echo '
<pre>';print_r($array);

// 發(fā)送短信
$data=array('text'=>$text,'apikey'=>$apikey,'mobile'=>$mobile);
$json_data = send($ch,$data);
$array = json_decode($json_data,true);
echo '
<pre>';print_r($array);

// 發(fā)送模板短信
// 需要對(duì)value進(jìn)行編碼
$data = array('tpl_id' => '365741', 'tpl_value' => ('#code#').
    '='.urlencode('1234').
    '&'.urlencode('#min#').
    '='.urlencode('5'), 'apikey' => $apikey, 'mobile' => $mobile);
print_r ($data);
$json_data = tpl_send($ch,$data);
$array = json_decode($json_data,true);
echo '
<pre>';print_r($array);

// 發(fā)送語(yǔ)音驗(yàn)證碼
$data=array('code'=>'9876','apikey'=>$apikey,'mobile'=>$mobile);
$json_data =voice_send($ch,$data);
$array = json_decode($json_data,true);
echo '
<pre>';print_r($array);

 curl_close($ch);


/************************************************************************************/
//獲得賬戶
function get_user($ch,$apikey){
    curl_setopt($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/user/get.json');
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('apikey' => $apikey)));
    $result = curl_exec($ch);
    $error = curl_error($ch);
    checkErr($result,$error);
    return $result;
}
function send($ch,$data){
    curl_setopt($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json');
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    $result = curl_exec($ch);
    $error = curl_error($ch);
    checkErr($result,$error);
    return $result;
}
function tpl_send($ch,$data){
    curl_setopt($ch, CURLOPT_URL,
        'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    $result = curl_exec($ch);
    $error = curl_error($ch);
    checkErr($result,$error);
    return $result;
}
function voice_send($ch,$data){
    curl_setopt($ch, CURLOPT_URL, 'http://voice.yunpian.com/v2/voice/send.json');
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    $result = curl_exec($ch);
    $error = curl_error($ch);
    checkErr($result,$error);
    return $result;
}
function checkErr($result,$error) {
    if($result === false)
    {
        echo 'Curl error: ' . $error;
    }
    else
    {
        //echo '操作完成沒(méi)有任何錯(cuò)誤';
    }
}

?>
特黄人与动人物视频A级毛片,久久婷婷五月色综合蜜芽,亚洲AV永久无码区成人网站,精品无码成人网站久久久久久无码 ,日本动漫爆乳H动漫啪啪免费,成年女人毛片免费视频喷潮,一本之道高清在线观看免费,一级A片无遮挡,18禁美女挤奶水视频免费,欧美牲交A欧美牲交AⅤ电影