///////////////////////语音验证/////////////////////////////
/**
* 发送短信(语音验证码)云片语音服务
* @param $apikey 用户唯一标识 32位(9b11127a9701975c734b8aee81ee3526)
* @param $mobile 用户手机号码
*
*/
function phoneVoiceMessage() {
//$code = $code=rand(1000, 9999);///语音播报的验证码
//$url = "https://voice.yunpian.com/v2/voice/send.json";////语音发送接口地址
$apikey = "8f9885ef60499210d9ba7c39a8043267";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8')); // 设置验证方式
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 设置返回结果为流
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 设置超时时间
curl_setopt($ch, CURLOPT_POST, 1); // 设置通信方式
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 发送模板短信
// 需要对value进行编码
$mobile = 18673305936; // 接收短信的手机号
//$code = $this->getRandomCheckCode(); // 要发送的验证码
$code = 1234; // 要发送的验证码
$data=array(
'code' =>$code,
'apikey' => $apikey,
'mobile' =>$mobile
);
curl_setopt ($ch, CURLOPT_URL, 'https://voice.yunpian.com/v2/voice/send.json');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$send_result = json_decode(curl_exec($ch), true);
curl_close($ch);
if(0 == $send_result['code']) { // 成功
return "success";
} else { // 失败
return "error";
}
$this->ajaxReturn($data);
}
///////////////////////云片--语音验证/////////////////////////////
///////////////////////云片--短信验证/////////////////////////////
function notes() {
$apikey = "********填入APPKEY********";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8')); // 设置验证方式
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 设置返回结果为流
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 设置超时时间
curl_setopt($ch, CURLOPT_POST, 1); // 设置通信方式
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 发送模板短信
// 需要对value进行编码
$mobile = 12345678910; // 接收短信的手机号
$code = $this->getRandomCheckCode(); // 要发送的验证码
$data=array(
'tpl_id' => 5, // 此处为模板id,不设置时默认为1
'tpl_value' => urlencode('#code#').'='.urlencode($code)
.'&'.urlencode('#company#').'='.urlencode('公司名称')
.'&'.urlencode('#app#').'='.urlencode('app名称'),
'apikey' => $apikey,
'mobile' =>$mobile
);
curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v1/sms/tpl_send.json');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$send_result = json_decode(curl_exec($ch), true);
curl_close($ch);
if(0 == $send_result['code']) { // 成功
} else { // 失败
}
}
////////验证码生成函数
function getRandomCheckCode() {
$chars = '0123456789';
mt_srand((double)microtime()*1000000*getmypid());
$CheckCode="";
while(strlen($CheckCode)<6)
$CheckCode.=substr($chars,(mt_rand()%strlen($chars)),1);
return $CheckCode;
}
///////////////////////短信验证/////////////////////////////
|