当前位置: 首页>>代码示例>>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;未经允许,请勿转载。