Exemplo n.º 1
0
 /**
  * Index Action - "http://SERVER/internal"   
  * This is where the internal's POST Messages will point to.- 
  * aFirst step get the parameters in POST
  * 
  */
 public function indexAction()
 {
     $params = Application_Model_General::getParamsArray($this->getRequest()->getParams());
     // backward compatability
     if (isset($params['NUMBER'])) {
         $params['PHONE_NUMBER'] = $params['NUMBER'];
         unset($params['NUMBER']);
     }
     if (isset($params['TO'])) {
         $params['TO_PROVIDER'] = $params['TO'];
         unset($params['TO']);
     }
     if (isset($params['FROM'])) {
         $params['FROM_PROVIDER'] = $params['FROM'];
         unset($params['FROM']);
     }
     //		error_log(print_R($params, 1));
     $this->AddParamsToInternalReq($params);
     $model = new Application_Model_Internal($params);
     $obj = new stdClass();
     $obj->status = $model->Execute();
     $request_params = $model->getParams();
     if (isset($request_params)) {
         $obj->reqId = isset($request_params['REQUEST_ID']) ? $request_params['REQUEST_ID'] : '';
         $obj->msgType = isset($request_params['MSG_TYPE']) ? $request_params['MSG_TYPE'] : '';
     }
     $desc = $model->getErrorMsg();
     if (!empty($desc)) {
         $obj->msgDesc = $obj->desc = $desc;
     } else {
         $obj->msgDesc = $obj->desc = '';
     }
     $this->view->ack = $obj;
     // log the request and response
     $logContentRequest = "Receive from internal " . PHP_EOL . print_R($this->getRequest()->getParams(), 1) . PHP_EOL;
     Application_Model_General::logRequest($logContentRequest, $obj->reqId);
     $logContentResponse = "Response to internal " . PHP_EOL . print_R($obj, 1) . PHP_EOL;
     Application_Model_General::logRequest($logContentResponse, $obj->reqId);
 }
Exemplo n.º 2
0
 /**
  * send http request to internal RPC and return response string.
  * 
  * @return string
  */
 public function SendRequestToInternal(Np_Method $request)
 {
     Application_Model_General::virtualSleep();
     // used to write to log to be in order
     $data = $this->createPostData($request);
     $url = Application_Model_General::getSettings('UrlToInternalResponse');
     $auth = Application_Model_General::getSettings('InternalAuth');
     $method = self::getMethodName($this->params['MSG_TYPE']);
     if ($this->protocal == 'http') {
         $client = new Zend_Http_Client();
         $client->setUri($url);
         $client->setParameterGet('method', $method);
         if (is_numeric($timeout = Application_Model_General::getSettings('InternalAuth'))) {
             $client->setConfig(array('timeout' => $timeout));
         }
         $client->setParameterPost($data);
         if (isset($auth['user'])) {
             $user = (string) $auth['user'];
             if (isset($auth['password'])) {
                 $password = (string) $auth['password'];
                 $client->setAuth($user, $password);
             }
             $client->setAuth($user);
         }
         $logContentRequest = "Send to internal " . PHP_EOL . print_R(array_merge(array('method' => $method), $data), 1) . PHP_EOL;
         Application_Model_General::logRequest($logContentRequest, $data['reqId']);
         $client->setMethod(Zend_Http_Client::POST);
         $response = $client->request();
         $ret = $response->getBody();
         $logContentResponse = "Response from internal " . PHP_EOL . $ret . PHP_EOL . PHP_EOL . PHP_EOL;
         Application_Model_General::logRequest($logContentResponse, $data['reqId']);
     } elseif ($this->protocal == 'soap') {
         $client = new Zend_Soap_Client();
         $client->setUri($url);
         $ret = call_user_func_array(array($client, $method), $data);
     }
     return $ret;
 }
Exemplo n.º 3
0
 /**
  * checks PostValidate()
  * if TRUE
  * saves data to db.
  * send request to internal and returns response ack.
  * if FALSE 
  * puts FALSE in ACK
  * send response via CreateMethodResponse
  */
 public function ExecuteRequest($manual = false)
 {
     $validate = $this->request->PostValidate();
     $internalModel = new Application_Model_Internal($this->data);
     if ($validate === TRUE || strtolower($validate) === 'ack00') {
         // ack00 check is for b/c
         $this->saveDB();
         $content = $internalModel->SendRequestToInternal($this->request);
         if (empty($content)) {
             Application_Model_General::logRequest($this->request->getHeaderField('REQUEST_ID'), "ExecuteRequest: Internal CRM error");
             return FALSE;
         }
         $response = Zend_Json::decode($content, Zend_Json::TYPE_OBJECT);
         if (!isset($response->status)) {
             $response->status = "";
         } elseif ($response->status == "FALSE") {
             $response->status = "";
         }
     } else {
         $this->saveTransactionsDB();
         if ($validate === FALSE) {
             $validate = "Inv02";
         }
         $response = new stdClass();
         $response->status = $validate;
     }
     $internalModel->CreateMethodResponse($response, $manual);
 }