curl_setopt($ch, CURLOPT_POSTFIELDS, "uid=$uid&pas=$pas&mob=$mob&cid=$cid&p1=$p1&p2=$p2&type=json");
$res = curl_exec( $ch );
curl_close( $ch );
$arr = json_decode($res,true);
if($arr['code'] == 0){
saveCode($mob,$p1);
return "短信发送成功!";
}
return "短信发送失败!";
}else{
return "短信发送频繁,请稍后再发送!";
}
}
//生成随机字符串
//$len 要生成的随机字符串长度
//$type 随机码类型:0,数字+大小写字母;1,数字;2,小写字母;3,大写字母;4,特殊字符;-1,数字+大小写字母+特殊字符
function createRandomCoder($len,$type = '0')
{
$arr = array(1 => "0123456789", 2 => "abcdefghijklmnopqrstuvwxyz", 3 => "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 4 => "~@#$%^&*(){}[]|");
if ($type == 0) {
array_pop($arr);
$string = implode("", $arr);
} elseif ($type == "-1") {
$string = implode("", $arr);
} else {
$string = $arr[$type];
}
$count = strlen($string) - 1;
$code = '';
for ($i = 0; $i < $len; $i++) {
$code .= $string[rand(0, $count)];
}
return $code;
}
//保存验证码
function saveCode($phone,$code,$time = 5)
{
global $dsql;
$created_at = time();
$expire_at = time() + ($time * 60);
$code = strtolower($code);