77 lines
1.6 KiB
PHP
77 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace app\common\library\live\message;
|
|
|
|
/**
|
|
* 消息服务统一返回结构
|
|
* 用于标准化各服务商的返回结果,便于业务层无差别处理
|
|
*/
|
|
class Result
|
|
{
|
|
/**
|
|
* @var bool 是否成功
|
|
*/
|
|
public $success;
|
|
|
|
/**
|
|
* @var mixed 业务数据
|
|
*/
|
|
public $data;
|
|
|
|
/**
|
|
* @var string 错误信息(失败时填充)
|
|
*/
|
|
public $error;
|
|
|
|
/**
|
|
* @var mixed 服务商原始返回(用于调试与排查)
|
|
*/
|
|
public $rawResponse;
|
|
|
|
/**
|
|
* 构造函数
|
|
* @param bool $success 是否成功
|
|
* @param mixed $data 业务数据
|
|
* @param string $error 错误信息
|
|
* @param mixed $rawResponse 原始返回
|
|
*/
|
|
public function __construct($success = true, $data = null, $error = '', $rawResponse = null)
|
|
{
|
|
$this->success = $success;
|
|
$this->data = $data;
|
|
$this->error = $error;
|
|
$this->rawResponse = $rawResponse;
|
|
}
|
|
|
|
/**
|
|
* 构造成功结果
|
|
* @param mixed $data 业务数据
|
|
* @param mixed $rawResponse 原始返回
|
|
* @return Result
|
|
*/
|
|
public static function success($data = null, $rawResponse = null)
|
|
{
|
|
return new self(true, $data, '', $rawResponse);
|
|
}
|
|
|
|
/**
|
|
* 构造失败结果
|
|
* @param string $error 错误信息
|
|
* @param mixed $rawResponse 原始返回
|
|
* @return Result
|
|
*/
|
|
public static function fail($error, $rawResponse = null)
|
|
{
|
|
return new self(false, null, $error, $rawResponse);
|
|
}
|
|
|
|
/**
|
|
* 是否成功
|
|
* @return bool
|
|
*/
|
|
public function isSuccess()
|
|
{
|
|
return $this->success === true;
|
|
}
|
|
}
|