<?php
class InterfaceBase
{
public function getParams()
{
$input = json_decode(file_get_contents('php://input'), true);
return $input;
}
public function getErrorMsg($errorCode)
{
$errors = array(
'8001' => '账号不存在',
'8002' => '登录已过期,请重新登录',
'8003' => '登录密码错误',
'8004' => '账号已锁定或注销,请联系管理员',
'8005' => '登录失败,请重试',
'8006' => '登出失败,Token不能为空',
'8007' => '登出失败,请重试',
'8008' => '登录账号不能为空',
'8009' => '登录密码不能为空',
'8010' => '原始密码不正确',
'8011' => '修改密码失败,请重试'
);
if(!$errors[$errorCode]){
return '未知错误:'.$errorCode;
}
return $errors[$errorCode];
}
public function success($data, $errMsg='')
{
return $this->result(true, 0, $errMsg, $data);
}
public function fail($errCode, $errMsg='', $data=null)
{
return $this->result(false, $errCode, $errMsg, $data);
}
public function result($success = true, $errCode = 0, $errMsg = '', $data = null)
{
if($errCode and !$errMsg){
$errMsg = $this->getErrorMsg($errCode);
}
return array(
'Success'=>$success,
'Errcode'=>intval($errCode),
'Errmsg'=>$errMsg,
'Data'=>$data
);
}
public function echoRet($data)
{
$responseTmp = $data;
$responseTmp['Data'] = json_encode($responseTmp['Data']);
WeUtility::logging('canteen_api.response', $responseTmp);
echo json_encode($data, 256|64);
exit;
}
}