本文整理汇总了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));
}
}
示例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;
}
示例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;
}
示例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;
}