public static function getFirstRecordCarSmsCode($phone_num, $sms_code) { $criteria = new CDbCriteria(); $criteria->condition = "receive_phone='" . $phone_num . "' and sms_code='" . $sms_code . "'"; $criteria->order = "time DESC"; $record = CarSmsCode::model()->find($criteria); return $record; }
public function actionGetSmsCode() { header('Content-Type: application/javascript'); $callback = $_REQUEST['callback']; $phone_num = $_REQUEST['phone_num']; $sms_code = ToolManager::gen_sms_code(6, 1); $sms_send_api = 'https://106.ihuyi.com/webservice/sms.php?method=Submit'; $api_key = '26b83c917f3963660656779b87ebf099'; $account = 'cf_ecar'; $post_data = array('account' => $account, 'password' => $api_key, 'mobile' => $phone_num, 'content' => '您的验证码是:' . $sms_code . '。请不要把验证码泄露给其他人。'); $result = ToolManager::post($sms_send_api, $post_data); $result = ToolManager::xml_to_array($result); try { $status = $result['SubmitResult']['code']; } catch (Exception $e) { $status = 0; } if ($status == 2) { $record = new CarSmsCode(); if ($record != null) { $record->receive_phone = $phone_num; $record->sms_code = $sms_code; $cur_time = date('Y-m-d H:i:s', time()); $record->time = date("Y-m-d H:i:s", strtotime($cur_time)); $record->save(); } $ret_json = array('status' => 0, 'message' => '发送验证码成功', 'data' => array(array('waitTime' => 60))); } else { $ret_json = array('status' => 1, 'message' => '发送验证码失败', 'data' => array()); } echo $callback . "(" . CJSON::encode($ret_json) . ");"; }