苏州网站建设在使用短信发送平台的时候,最先开始选择的是阿里大鱼短信平台,不过客户说他们有八信通的账号,并且他们公司为了方便统一管理,就要求我们也得使用这个平台,无奈,只能使用这个来试试看了。废话不多说,接下来是代码:
封装函数:
/**
* 八信通短信发送
* @param $sms_mobile 手机号码
* @param $sms_content 短信内容
* @param $sms_time 短信定时发送时间,格式不对或小于当前时间时立即发送. 定时时间标准格式为:yyyy-MM-dd HH:mm:ss
* @param $msgid 该批信息id,用于接收发送状态、回执时匹配,填0时由系统自动生成
* @return bool
* @author wusn <message@jswusn.com>
*/
function SendSms($sms_mobile,$sms_content,$sms_time,$msgid = 0){
$sms_user = C('DXUser');
$pas = C('DXPas');
$url='http://18dx.cn/API/Services.aspx?action=msgsend&user='.$sms_user.'&mobile='.$sms_mobile.'&content='.$sms_content.'&time='.$sms_time.'&msgid='.$msgid.'&hashcode='.$pas;
$file_contents = DXGet($url);
$arr = explode('&',$file_contents);
if((int)($arr[0]) == 1){
return true;
}else{
// $msg['err_code'] = $arr[0];
// $msg['err_msg'] = $arr[6];
return false;
}
}
function DXGet($url){
if(function_exists('file_get_contents'))
{
$file_contents = file_get_contents($url);
}
else
{
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
return $file_contents;
}调用函数:
/**
* 八信通短信发送验证码
* @author wusn <message@jswusn.com>
*/
public function send_sms_reg(){
$mobile = I('mobile');
$validate=array(
array('mobile','require','手机号必填!'),
array('mobile', '/^1[3-5,8]{1}[0-9]{9}$|^([0-9]{3,4}-)?[0-9]{7,8}$/', '手机号码格式不正确', 1, 'regex', 3),
array('mobile', '', '手机号码被占用', 0, 'unique', 1)
);
$table = M('member');
if(!$table->validate($validate)->create(array('mobile'=>$mobile))){
$this->error($table->getError());
}else {
$sms_code = get_random(6);
$content = '提醒您正在进行身份验证,验证码:' . $sms_code . ',验证码10分钟内有效。提示:请勿泄露短信验证码!';
$content = htmlspecialchars($content);
S($mobile, $sms_code,600);
if (SendSms($mobile, $content)) {
S($mobile, $sms_code,600);
$this->success('发送成功!');
} else {
$this->error('发送失败!');
}
}
}
以上是苏州网站建设分享关于ThinkPHP利用八信通短信平台发送短信验证码使用,如果你也有一些新颖的想法,可以跟苏州网站建设交流下。









