<?php
|
/**
|
* 发送类
|
*/
|
|
class Api_Send extends PhalApi_Api {
|
|
public $alidayu;
|
|
public function __construct(){
|
$this->alidayu = Alidayu_Lite::getInstance();
|
}
|
|
/**
|
* 路由规则
|
* @return [type] [description]
|
*/
|
public function getRules(){
|
return array(
|
'sms' => array(
|
'phone' => array(
|
'name' => 'phone',
|
'type' => 'string',
|
'require' => true,
|
'desc' => '注册手机号'
|
),
|
'type' => array(
|
'name' => 'type',
|
'type' => 'string',
|
'require' => true,
|
'desc' => '短信发送类型'
|
)
|
),
|
);
|
}
|
|
|
/**
|
* 发送短信接口
|
* @desc 发送注册短信
|
* @return bool code 操作码,0表示成功, 1表示失败
|
* @return string msg 返回提示
|
*/
|
public function sms(){
|
$rs = array('code' => 0, 'msg' => '');
|
$sms_service = new Domain_SmsCode();
|
$promit_scene = array('register', 'resetPwd');
|
if(in_array($this->type, $promit_scene)){
|
$scene = $this->type;
|
if($sms_service->check($this->phone, $scene)){
|
$code = Common_Util::random(6, 1);
|
$send_json_data = json_encode(array('mobile_validate' => $code));
|
if($this->alidayu->send($this->phone, $send_json_data, $scene)){
|
$data = array();
|
$time = time();
|
$data['phone'] = $this->phone;
|
$data['code'] = $code;
|
$data['create_time'] = date('Y-m-d H:i:s', $time);
|
$data['expire_time'] = date('Y-m-d H:i:s', $time + 60);
|
$data['scene'] = $scene;
|
$data['status'] = 0;
|
$sms_service->add($data);
|
$rs['msg'] = '发送成功';
|
}
|
else{
|
$rs['code'] = 1;
|
$rs['msg'] = '发送失败';
|
}
|
}
|
else{
|
$rs['code'] = 1;
|
$rs['msg'] = '请勿重复发送短信,间隔时间60秒';
|
}
|
}
|
else{
|
$rs['code'] = 1;
|
$rs['msg'] = '非法的短信类型';
|
}
|
|
return $rs;
|
}
|
}
|