Exemplo n.º 1
0
 function adminajaxAction()
 {
     $testEnv = Zend_Registry::get('testEnv');
     if ($testEnv == 0) {
         // fetch msg from gateway
         $smsSpace = new Zend_Session_Namespace('SMS');
         $newclient = new SMS();
         $respxml = $newclient->readSMS();
         $smsSpace->xml = $newclient->sendXML;
         $smsSpace->respxml = $respxml;
         $code = $newclient->getCode();
         $respArr = $newclient->toArray();
         if ($respArr["id"][0] > 0) {
             $sparkSmsModel = new SparkSms();
             $message = $sparkSmsModel->createRow();
             $message->msg = $respArr["msg"];
             $message->sys_id = $respArr["id"][0];
             $message->source = $respArr["src"][0];
             $message->time = $respArr["time"][0];
             $message->text = iconv("GB2312", "UTF-8", base64_decode($respArr["message"][0]));
             $message->err = $respArr["err"][0];
             $db = Zend_Registry::get('db');
             $select = $db->select();
             $select->from('consumer', '*');
             $select->where('consumer.phone = ?', $message->source);
             $consumer = $db->fetchRow($select);
             $message->consumer_id = $consumer['id'];
             $message->save();
             $jsonMsg['name'] = $consumer['name'];
             $jsonMsg["sys_id"] = $message->id;
             $jsonMsg["source"] = $message->source;
             $jsonMsg["time"] = $message->time;
             $jsonMsg["text"] = $message->text;
             $jsonMsg["err"] = $message->err;
             $this->_helper->json($jsonMsg);
         } else {
             $jsonMsg["sys_id"] = -1;
             $this->_helper->json($jsonMsg);
         }
         $this->_helper->layout->disableLayout();
         // store msg into db
     }
 }
Exemplo n.º 2
0
 function smshistoryAction()
 {
     $this->_helper->layout->disableLayout();
     $idValue = explode('&', $this->_request->getParam('uid'));
     $uid = $idValue[0];
     $incomingSmsDataArray = array();
     $sentSmsDataArray = array();
     $sparkSmsModel = new SparkSms();
     $incomingSmsData = $sparkSmsModel->fetchAll('consumer_id=' . $uid);
     $db = Zend_Registry::get('db');
     $sentSmsSelect = $db->select();
     $sentSmsSelect->from('sent_sms', array('sent_sms.*'));
     $sentSmsSelect->join('consumer', 'consumer.phone = sent_sms.to and consumer.id=' . $uid);
     $sentSmsSelect->order('sent_sms.time DESC');
     $sentSmsData = $db->fetchAll($sentSmsSelect);
     if (count($incomingSmsData)) {
         foreach ($incomingSmsData as $data) {
             $incomingSmsDataArray[] = $data->toArray();
         }
     }
     //		if(count($sentSmsData)){
     //			foreach($sentSmsData as $data){
     //				$sentSmsDataArray[] = $data->toArray();
     //			}
     //		}
     //按照时间排序
     $newSmsData = array();
     $count = 0;
     for ($i = count($incomingSmsDataArray) - 1, $j = 0; $i >= 0 || $j < count($sentSmsData);) {
         if ($i < count($incomingSmsDataArray) && $j < count($sentSmsData)) {
             $income_time = $incomingSmsDataArray[$i]['time'];
             $sent_time = $sentSmsData[$j]['time'];
             if ($incomingSmsDataArray[$i]['time'] >= $sentSmsData[$j]['time']) {
                 $newSmsData[$count] = $incomingSmsDataArray[$i];
                 $i--;
             } else {
                 $newSmsData[$count] = $sentSmsData[$j];
                 $j++;
             }
         } elseif ($i >= count($incomingSmsDataArray) && $j < count($sentSmsData)) {
             $newSmsData[$count] = $sentSmsData[$j];
             $j++;
         } elseif ($i < count($incomingSmsDataArray) && $j >= count($sentSmsData)) {
             $newSmsData[$count] = $incomingSmsDataArray[$i];
             $i--;
         }
         $count++;
     }
     $this->view->sms = $newSmsData;
 }