*
-41001: encodingAesKey 非法
* -41003: aes 解密失败
* -41004: 解密后得到的buffer非法
* -41005: base64加密失败
* -41016: base64解密失败
*
*/
class ErrorCode
{
public static $OK = 0;
public static $IllegalAesKey = -41001;
public static $IllegalIv = -41002;
public static $IllegalBuffer = -41003;
public static $DecodeBase64Error = -41004;
public static $GameServerFail = -1; // 游戏服务器失败
public static $ParamErr = -98; // 参数异常
public static $NoPlayer = -99; // 找不到玩家
private static $errcodeMsg = null;
/**
* 获取错误码对应的错误信息说明
*/
private static function getErrcodeMsg($errcode)
{
if (ErrorCode::$errcodeMsg == null) {
ErrorCode::$errcodeMsg = array(
ErrorCode::$OK => "ok",
ErrorCode::$GameServerFail => "game server fail",
ErrorCode::$ParamErr => "param error",
ErrorCode::$NoPlayer => "no player",
);
}
if (array_key_exists($errcode, ErrorCode::$errcodeMsg)) {
return ErrorCode::$errcodeMsg[$errcode];
}
return $errcode . "";
}
/**
* 游戏服务器返回成功信息
* @param array $playerData 通知前端需要更新的玩家数据
* @param array $optData 通知前端本次操作数据,业务逻辑自行定义
*/
public static function retOK($playerData = [], $optData = [])
{
// gserrcode 游戏服务器处理结果
$code = ErrorCode::$OK;
$ret = ["gserrcode" => $code, "gserrmsg" => ErrorCode::getErrcodeMsg($code)];
// 同步更新的玩家数据
if ($playerData) {
$ret["playerData"] = $playerData;
}
// 操作数据
if ($optData) {
$ret["optData"] = $optData;
}
\Logging\LogInfo('retOK: ' . print_r($ret, true));
return $ret;
}
/**
* 游戏服务器返回错误信息
* @param mixed $code 错误码
* @param string $errInfo 错误附加信息,自定义内容,会添加在errmsg后
*/
public static function retErr($code, $errInfo = "")
{
if ($errInfo) {
$errInfo = " => " . $errInfo;
}
$ret = ["gserrcode" => $code, "gserrmsg" => ErrorCode::getErrcodeMsg($code) . $errInfo];
\Logging\LogInfo('retErr: ' . print_r($ret, true));
return $ret;
}
}