Commit 50cc15fe by 杨树贤

把错误码和提示信息放到配置文件进行维护,并且修改签到接口适应这一改动

parent c124e07c
......@@ -29,14 +29,15 @@ class CheckInController extends Controller
public function add(Request $request)
{
$map = [
'user_id' => 77,
// 'user_id' => $request->user->user_id,
'user_id' => $request->user->user_id,
];
$result = $this->service->addCheckIn($map);
if ($result) {
if ($result['errcode'] === self::SUCCESS) {
return $this->Export(0, 'ok');
}else{
return $this->Export(0,'签到失败');
} elseif ($result['errcode'] === 109001) {
return $this->Export(self::CAN_NOT_CHECK_IN_AGAIN);
} else {
return $this->Export(self::CHECK_IN_FAIL);
}
}
}
\ No newline at end of file
......@@ -7,12 +7,17 @@ use Hprose\Http\Client;
class Controller extends BaseController
{
public function Export( $Errcode=0,$ErrMsg='', $dataArr=[])
{
return Export($Errcode,$ErrMsg, $dataArr);
}
/**
const SUCCESS = 0;
const CAN_NOT_CHECK_IN_AGAIN = 109101;
const CHECK_IN_FAIL = 109102;
public function Export($Errcode = 0, $ErrMsg = '', $dataArr = [])
{
return Export($Errcode, $ErrMsg, $dataArr);
}
/**
* 内部免验证通过
* @return [type] [description]
*/
......@@ -37,20 +42,24 @@ class Controller extends BaseController
{
$token = $request->input('token', '');
if (empty($token)) return $this->_json(ErrorCode(001, 1));
if (empty($token)) {
return $this->_json(ErrorCode(001, 1));
}
try {
$url = config('website.authapi').'/hprose/service';
$url = config('website.authapi') . '/hprose/service';
$user = new Client($url, false);
$user->setHeader("Authorization",'Bearer '.$token);
$user->setHeader("Authorization", 'Bearer ' . $token);
$res = $user->getUserInfo();
$user->close();
} catch (Exception $e) {
return $this->_json(ErrorCode(002, 1));
}
if ($res['errcode'] != 0) return $this->_json(ErrorCode(003, 1));
if ($res['errcode'] != 0) {
return $this->_json(ErrorCode(003, 1));
}
return $this->_json(0, '', $res['data']);
}
......@@ -60,14 +69,14 @@ class Controller extends BaseController
* @param [Integer] $code [状态码]
* @param [String] $message [信息]
* @param [String] $data [数据]
* @return [Json]
* @return [Json]
*/
public function _json($code, $message='', $data=array())
public function _json($code, $message = '', $data = [])
{
if ($code != 0) {
ErrorLog($code, $message); // 记录到logreport
}
return ['errcode'=>$code, 'errmsg'=>$message, 'data'=>$data];
return ['errcode' => $code, 'errmsg' => $message, 'data' => $data];
}
}
......@@ -11,7 +11,7 @@ function ErrorCode($code = 0, $level = 1){
return errCode($code , $level , $systemcode);
}
function Export($Errcode=0,$ErrMsg='', $dataArr=[]){
function Export($Errcode=0, $ErrMsg='', $dataArr=[]){
if(!empty($dataArr) && !is_array($dataArr)) {
$Errcode = -2;
$ErrMsg = '系统错误';
......@@ -19,16 +19,20 @@ function Export($Errcode=0,$ErrMsg='', $dataArr=[]){
$domain = \Illuminate\Support\Facades\Request::server('HTTP_HOST');//获取当前域名
$cofig = config('website.language');
if(!empty($cofig[$domain])){//配置了域名的版本
if(!empty($cofig[$domain])) //配置了域名的版本
$language = $cofig[$domain];
}
else
$language = 'cn';
if(!empty($language)){
if (!$ErrMsg) { // 若不存在,则查找配置文件
$errInfo = config('language.'.$language.'.'.$Errcode);
$ErrMsg = $errInfo;
if(!empty($errInfo)) $ErrMsg = $errInfo;
}
$data=['errcode'=>$Errcode, 'errmsg'=>$ErrMsg];
if(($data['errcode'] < 10000 || $data['errcode'] >= 50000) && $data['errcode'] !==0 )//非正常返回码,上报
ErrorLog($Errcode,$ErrMsg);
......
......@@ -8,43 +8,26 @@
return [
'cn' => [
103001 => '非法操作',
103002 => 'Hprose请求失败',
103003 => '登录失败',
109001 => '非法操作',
109002 => 'Hprose请求失败',
109003 => '登录失败',
109100 => '参数不正确或者缺失,请检查请求的参数',
109101 => '今天已签到过,无法再次签到',
109102 => '签到失败',
// oss 错误码
103200 => '上传成功',
103201 => '参数缺失,请检查传递的参数',
103202 => '内部免验证不通过',
103203 => '上传文件数量超出限制',
103204 => '暂不支持此文件类型上传',
103205 => '请求方法不被允许',
103206 => '文件过大,最大限制为2M,请重新上传',
103207 => '文件过大,最大限制为20M,请重新上传',
103208 => '文件过大,最大限制为50M,请重新上传',
103209 => '文件过大,最大限制为30M,请重新上传',
103210 => '没匹配到文件类型',
103211 => '上传失败,请重新上传',
],
'us' => [
103001 => 'Illegal operation',
103002 => 'Hprose request failed, please check it',
103003 => 'Login failed',
109001 => 'Illegal operation',
109002 => 'Hprose request failed, please check it',
109003 => 'Login failed',
// oss 错误码
109100 => 'Parameter missing, please check the passed parameters',
109101 => 'Checked in today and can not sign in again.',
109102 => 'Check in failed.',
// oss 错误码
103200 => 'Upload success',
103201 => 'Parameter missing, please check the passed parameters',
103202 => 'Internal certification-free fails',
103203 => 'The number of uploaded files exceeds the limit',
103204 => 'This file type upload is not supported for the time being',
103205 => 'Request method is not allowed',
103206 => 'The File is too large, the maximum limit is 2M, please re-upload',
103207 => 'The File is too large, the maximum limit is 20M, please re-upload',
103208 => 'The File is too large, the maximum limit is 50M, please re-upload',
103209 => 'The File is too large, the maximum limit is 30M, please re-upload',
103210 => 'Not matched to file type',
103211 => 'Upload failed, please try again',
],
];
\ No newline at end of file
......@@ -27,7 +27,9 @@ $router->group(['middleware' => ['web', 'login']], function () use ($router) {
//签到
$router->get('/check_in/list', 'CheckInController@index');
$router->post('/check_in/add', 'CheckInController@add');
//红包活动信息
$router->get('/integrals/list', 'IntegralsController@index');
//红包获取流水
$router->get('integral_bills/list', 'IntegralBillsController@index');
//红包兑换流水
......@@ -39,9 +41,7 @@ $router->group(['middleware' => 'web'], function () use ($router) {
});
//红包活动信息
$router->get('/integrals/list', 'IntegralsController@index');
$router->post('/check_in/add', 'CheckInController@add');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment