Example #1
0
 public static function handle($task)
 {
     echo '<pre>';
     echo date('Y-m-d H:i:s') . ' handle task: ' . $task;
     echo "\r\n";
     switch ($task) {
         case 'sms':
             Sms::model()->send();
             break;
     }
 }
Example #2
0
 /**
  * 新用户注册
  *
  */
 public function actionRegister()
 {
     $this->layout = " ";
     Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery-1.9.1.js');
     Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/login.css');
     $username = Yii::app()->request->getQuery('username', null);
     $phone = Yii::app()->request->getQuery('phone', null);
     $email = Yii::app()->request->getQuery('email', null);
     $model = new User('create');
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         if ($model->validate()) {
             $code_model = Temp::model()->findByPk(trim($model->phone));
             if (!empty($code_model)) {
                 if (time() - $code_model->time <= 180) {
                     if ($model->sms_code == $code_model->code) {
                         if ($model->save()) {
                             $userInfo = new UserInfo();
                             $userInfo->userId = $model->id;
                             $userInfo->username = $model->username;
                             $userInfo->phone = $model->phone;
                             $userInfo->save();
                             $this->redirect(array('registerSuccess'));
                         }
                     } else {
                         $model->addError('sms_code', '验证码不正确');
                     }
                 } else {
                     $model->addError('sms_code', '验证码已失效,请重新获取');
                 }
             } else {
                 $model->addError('sms_code', '验证失败,请重新获取');
             }
         }
     }
     if (!empty($username) && trim($username) != '您的姓名') {
         $model->username = $username;
     }
     if (!empty($phone) && trim($phone) != '您的电话') {
         $model->phone = $phone;
     }
     if (!empty($email) && trim($email) != '您的邮箱') {
         $model->email = $email;
     }
     $sms_list = Sms::model()->findAll();
     $link_list = Link::model()->findAll();
     $this->render('create', array('model' => $model, 'sms_data' => $sms_list[0], 'link_list' => $link_list));
 }
 public function actionReplyMessage()
 {
     if (isset(Yii::app()->params['twilio']['replyMessage']) && Yii::app()->params['twilio']['replyMessage']) {
         file_put_contents(Yii::app()->params['logDirPath'] . '/twilio_request.log', print_r($_REQUEST, true) . "\n\n", FILE_APPEND);
         $phone = str_replace('+44', '', $_REQUEST['From']);
         $client = Client::model()->findByPhone($phone);
         $sms = new Sms();
         $sms->clientId = $client ? $client->cli_id : 0;
         $sms->receive($_REQUEST);
         if ($client) {
             $latestText = Sms::model()->latestTextToClient($client);
         }
         header('content-type: text/xml');
         echo '<Response><Sms><![CDATA[' . Yii::app()->params['twilio']['replyMessage'] . ']]></Sms></Response>';
     }
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Sms::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #5
0
 public function send()
 {
     $criteria = new CDbCriteria();
     $criteria->addCondition('status = 0 AND stime <=' . time());
     $criteria->order = 'id ASC';
     $sms = Sms::model()->findAll($criteria);
     if (!empty($sms)) {
         foreach ($sms as $s) {
             $numbers = array();
             if ($s->send_all == 1) {
                 $criteria = new CDbCriteria();
                 $criteria->addCondition('id != 0 AND resignation = 0 AND disabled = 0 AND is_deleted =0');
                 $users = User::model()->findAll($criteria);
                 if (!empty($users)) {
                     foreach ($users as $u) {
                         $numbers[] = $u->phone;
                     }
                 }
             } else {
                 $users = $s->to_user();
                 if (!empty($users)) {
                     foreach ($users as $u) {
                         $numbers[] = $u->user->phone;
                     }
                 }
             }
             if (!empty($numbers)) {
                 try {
                     if (ISMG::send($s->message, implode(',', $numbers))) {
                         $s->status = 1;
                         $s->save();
                     } else {
                         throw new Exception('Send SMS Error');
                     }
                 } catch (Exception $e) {
                     echo $e->getMessage();
                 }
             }
         }
     }
     return true;
 }
 public function actionTextConversation($clientId)
 {
     $this->layout = '//layouts/fixed';
     $highlightText = null;
     if (isset($_GET['messageId']) && $_GET['messageId']) {
         $highlightText = Sms::model()->findByPk($_GET['messageId']);
         if (!$highlightText) {
             throw new CHttpException(404, 'message [id:' . $_GET['messageId'] . '] not found');
         }
         if (!$highlightText->isRead()) {
             $highlightText->markRead(Yii::app()->user->id);
         }
     }
     $client = Client::model()->findByPk($clientId);
     if (!$client) {
         throw new CHttpException(404, 'client [id : ' . $clientId . '] is not found');
     }
     $this->render('textConversation', array('client' => $client, 'highlightText' => $highlightText));
 }
 /**
  * @param $id
  * @return Sms
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Sms::model()->findByPk($id);
     if (!$model) {
         throw new CHttpException(404, "message [id: " . $id . "] is not found");
     }
     return $model;
 }