當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Json::getErrorMessage方法代碼示例

本文整理匯總了PHP中Json::getErrorMessage方法的典型用法代碼示例。如果您正苦於以下問題:PHP Json::getErrorMessage方法的具體用法?PHP Json::getErrorMessage怎麽用?PHP Json::getErrorMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Json的用法示例。


在下文中一共展示了Json::getErrorMessage方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testGetErrorMessage

 /**
  * Tests getErrorMessage.
  */
 public function testGetErrorMessage()
 {
     $errors = array(JSON_ERROR_NONE => 'No errors', JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', 999999999 => 'Unknown error');
     foreach ($errors as $no => $message) {
         $this->assertSame($message, Json::getErrorMessage($no));
     }
 }
開發者ID:raphhh,項目名稱:trex,代碼行數:10,代碼來源:JsonTest.php

示例2: extendPostRequest

 public function extendPostRequest($aMerchantNo)
 {
     try {
         $this->iLogWriter = new LogWriter();
         $this->iLogWriter->logNewLine("TrustPayClient V3.0.0 交易開始==========================");
         MerchantConfig::getLogWriterObject($this->iLogWriter);
         //0、檢查傳入參數是否合法
         if ($aMerchantNo <= 0 || $aMerchantNo > MerchantConfig::getMerchantNum()) {
             throw new TrxException(TrxException::TRX_EXC_CODE_1008, TrxException::TRX_EXC_MSG_1008, '配置文件中商戶數為' . MerchantConfig::getMerchantNum() . ", 但是請求指定的商戶配置編號為{$aMerchantNo} !");
         }
         //1、檢查交易請求是否合法
         $this->iLogWriter->logNewLine('檢查交易請求是否合法:');
         $this->checkRequest();
         $this->iLogWriter->log('正確');
         //2、取得交易報文
         $tRequestMessage = $this->getRequestMessage();
         //3、組成完整交易報文
         $this->iLogWriter->log("完整交易報文:");
         $tRequestMessage = $this->composeRequestMessage($aMerchantNo, $tRequestMessage);
         $this->iLogWriter->log($tRequestMessage);
         //4、對交易報文進行簽名
         $tRequestMessage = MerchantConfig::signMessage($aMerchantNo, $tRequestMessage);
         //5、發送交易報文至網上支付平台
         $tResponseMessage = $this->sendMessage($tRequestMessage);
         //6、驗證網上支付平台響應報文的簽名
         $this->iLogWriter->logNewLine('驗證網上支付平台響應報文的簽名:');
         MerchantConfig::verifySign($tResponseMessage);
         $this->iLogWriter->log('正確');
         //7、生成交易響應對象
         $this->iLogWriter->logNewLine('生成交易響應對象:');
         $this->iLogWriter->logNewLine('交易結果:[' . $tResponseMessage->getReturnCode() . ']');
         $this->iLogWriter->logNewLine('錯誤信息:[' . $tResponseMessage->getErrorMessage() . ']');
     } catch (TrxException $e) {
         $tResponseMessage = new Json();
         $tResponseMessage->initWithCodeMsg($e->getCode(), $e->getMessage() . " - " . $e->getDetailMessage());
         if ($this->iLogWriter != null) {
             $this->iLogWriter->logNewLine('錯誤代碼:[' + $tResponseMessage->getReturnCode() . ']    錯誤信息:[' . $tResponseMessage->getErrorMessage() . ']');
         }
     } catch (Exception $e) {
         $tResponseMessage = new Json();
         $tResponseMessage->initWithCodeMsg(TrxException::TRX_EXC_CODE_1999, TrxException::TRX_EXC_MSG_1999 . ' - ' . $e->getMessage());
         if ($this->iLogWriter != null) {
             $this->iLogWriter->logNewLine('錯誤代碼:[' . $tResponseMessage->getReturnCode() . ']    錯誤信息:[' . $tResponseMessage->getErrorMessage() . ']');
         }
     }
     if ($this->iLogWriter != null) {
         $this->iLogWriter->logNewLine("交易結束==================================================\n\n\n\n");
         $this->iLogWriter->closeWriter(MerchantConfig::getTrxLogFile());
     }
     return $tResponseMessage;
 }
開發者ID:pqshawn,項目名稱:sparrowPHP,代碼行數:51,代碼來源:TrxRequest.php

示例3: setBody

 /**
  * Set body.
  *
  * @param  mixed $body
  * @return self
  */
 public final function setBody($body) : self
 {
     switch ($this->contentType) {
         // handle xml @todo
         case ContentType::XML:
             break;
             // handle json
         // handle json
         case ContentType::JSON:
             $json = new Json($body);
             // simply check for pretty print
             $app = app();
             if (is_in($app->request->params->get['pp'], ['1', 'true'])) {
                 $body = $json->encode(JSON_PRETTY_PRINT);
             } else {
                 $body = $json->encode();
             }
             if ($json->hasError()) {
                 throw new JsonException($json->getErrorMessage(), $json->getErrorCode());
             }
             break;
             // handle html
         // handle html
         case ContentType::HTML:
             // check for page title
             if ($pageTitle = get_global('page.title')) {
                 $body = preg_replace('~<title>(.*?)</title>~s', '<title>' . html_encode($pageTitle) . '</title>', $body, 1);
             }
             // check page description
             if ($pageDescription = get_global('page.description')) {
                 $body = preg_replace('~<meta\\s+name="description"\\s+content="(.*?)">~', '<meta\\s+name="description"\\s+content="' . html_encode($pageDescription) . '">', $body, 1);
             }
             break;
     }
     // can gzip?
     if (!empty($this->gzipOptions)) {
         $this->gzip->setData($body);
         if ($this->gzip->isDataMinlenOK()) {
             $body = $this->gzip->encode();
             $this->setHeader('Vary', 'Accept-Encoding');
             $this->setHeader('Content-Encoding', 'gzip');
         }
     }
     // content length
     $this->setContentLength(strlen($body));
     $this->body = $body;
     return $this;
 }
開發者ID:froq,項目名稱:froq-beta-archive,代碼行數:54,代碼來源:Response.php

示例4: setBody

 /**
  * Set body.
  * @param  any $body
  * @return self
  */
 public final function setBody($body) : self
 {
     switch ($this->body->content->getType()) {
         case BodyContent::TYPE_XML:
             // @todo
             break;
         case BodyContent::TYPE_JSON:
             $json = new Json($body);
             $body = $json->encode();
             if ($json->hasError()) {
                 throw new JsonException($json->getErrorMessage(), $json->getErrorCode());
             }
             break;
     }
     // gzip
     if (!empty($this->gzipOptions)) {
         $this->gzip->setData($body);
         if ($this->gzip->checkDataMinlen()) {
             $body = $this->gzip->encode();
             $this->setHeader('Vary', 'Accept-Encoding');
             $this->setHeader('Content-Encoding', 'gzip');
         }
     }
     $this->body->content->setData($body);
     $this->body->content->setLength(strlen($body));
     return $this;
 }
開發者ID:froq,項目名稱:froq-http,代碼行數:32,代碼來源:Response.php


注:本文中的Json::getErrorMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。