all(); $apiKey = request()->post('api_key',''); if(!$apiInfo = ApiService::make()->checkApi($apiKey)){ return message(ApiService::make()->getError(), false); } $apiId = isset($apiInfo['id'])? $apiInfo['id'] : 0; if($apiId<=0){ return message(6002, false); } // 若为外汇平台,不需要登录直接 $userType = isset($params['user_type'])? intval($params['user_type']) : 3; if($userType == 3){ $token = 'TK'.strtoupper(md5($apiId . $apiKey).rand(100,999)); RedisService::set("apis:tokens:{$token}", ['id' => 0, 'api_id'=> $apiId, 'info' => [], 'token' => $token], 48 * 3600); return message(2004, true, [ 'token' => $token, 'api_id' => $apiId, ]); } $params = $validator->check($params, 'apiLogin'); if(!is_array($params)){ return message($params, false); } if(!$result = MemberService::make()->apiLogin($apiId,$params)){ return message(MemberService::make()->getError(), false); } $token = isset($result['token'])? $result['token'] : ''; return message($token?2004:2029, true, $result); } public function register(MemberValidator $validator) { $params = request()->all(); $params = $validator->check($params, 'apiRegister'); if(!is_array($params)){ return message($params, false); } $apiKey = request()->post('api_key',''); if(!$apiInfo = ApiService::make()->checkApi($apiKey)){ return message(ApiService::make()->getError(), false); } $apiId = isset($apiInfo['id'])? $apiInfo['id'] : 0; if($apiId<=0){ return message(6002, false); } if(!$result = MemberService::make()->apiRegister($apiId,$params)){ return message(MemberService::make()->getError(), false); } return message(2008, true); } }