public function send()
{
$phone=input('phone','');
if(empty($phone))
{
$this->BackResult('4', '手机号不能为空');
}elseif(!preg_match($this->phone,$phone))
{
$this->BackResult('5', '手机号格式不正确');
}
date_default_timezone_set("PRC");
$code=rand('100000','999999');
$host = "https://zwp.market.alicloudapi.com";
$path = "/sms/sendv2";
$method = "GET";
$appcode = Config('app.AppCode');
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$content=urlencode('【IMSSVRD小帮手】您的动态密码为:'.$code.',您正在登录,若非本人操作,请勿泄露。');
$querys = "content={$content}&mobile={$phone}";
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$res=curl_exec($curl);
$res=json_decode($res,true);
if($res['error_code']==0)
{
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
$redis->config("SET","notify-keyspace-events", "Ex");
$seconds =60*60*24;
$redis->setEx($phone,$seconds,$code);
$session=$redis->get($phone);
$this->BackResult('0', '发送成功',$session);
}
}