在做项目的初期,我对这个业务毫无头绪,所以我就询问了贴吧里的大神,但是一开贴广告铺天盖地,大神没有招来,打广告的招来很多,我当时感觉就有点儿不靠谱,想说自己找找看,就百度了关键字短信平台,前五家里面随便找了一家可以试用的,结果接入起来很顺利,还有条数赠送,很适合我这样刚开始做项目的。
我选择的是互亿无线短信平台(www.ihuyi.com)大家可以参考一下
现在我把当时开发的技术源码分享给大家,希望能对大家有所帮助
';print_r($array);
// 发送短信
$data=array('text'=>$text,'apikey'=>$apikey,'mobile'=>$mobile);
$json_data = send($ch,$data);
$array = json_decode($json_data,true);
// echo '';print_r($array);
// 发送模板短信
// 需要对value进行编码
$data = array('tpl_id' => '1', 'tpl_value' => ('#code#').
'='.urlencode($num).
'&'.urlencode('#company#').
'='.urlencode('蒙羊羊'), 'apikey' => $apikey, 'mobile' => $mobile);
// print_r ($data);
$json_data = tpl_send($ch,$data);
$array = json_decode($json_data,true);
echo $num;
// 发送语音验证码
// $data=array('code'=>$num,'apikey'=>$apikey,'mobile'=>$mobile);
// $json_data =voice_send($ch,$data);
// $array = json_decode($json_data,true);
// echo $num;
// 发送语音通知,务必要报备好模板
/*
模板: 课程#name#在#time#开始。 最终发送结果: 课程深度学习在14:00开始
*/
$tpl_id = 'xxxxxxx'; //修改为你自己后台报备的模板id
$tpl_value = urlencode('#time#').'='.urlencode($num).'&'.urlencode('#name#').'='.urlencode('蒙羊羊');
$data=array('tpl_id'=>$tpl_id,'tpl_value'=>$tpl_value,'apikey'=>$apikey,'mobile'=>$mobile);
$json_data = notify_send($ch,$data);
$array = json_decode($json_data,true);
// echo $num;
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 notify_send($ch,$data){
curl_setopt ($ch, CURLOPT_URL, 'https://voice.yunpian.com/v2/voice/tpl_notify.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 '操作完成没有任何错误';
}
}
?>