| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Http\Controllers\Oapi;
- use App\Http\Validator\MemberValidator;
- use App\Models\ApiModel;
- use App\Services\Api\MemberService;
- use App\Services\Common\ApiService;
- use App\Services\RedisService;
- /**
- * 登陆注册
- * Class LoginController
- * @package App\Http\Controllers\Oapi
- */
- class LoginController extends webApp
- {
- /**
- * 登录
- */
- public function login(MemberValidator $validator)
- {
- $params = request()->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, 'login');
- if(!is_array($params)){
- return message($params, false);
- }
- if(!$result = MemberService::make()->apiLogin($apiId,$params)){
- return message(MemberService::make()->getError(), false);
- }
- return message(2004, true, $result);
- }
- public function register(MemberValidator $validator)
- {
- $params = request()->all();
- $params = $validator->check($params, 'reg');
- 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(2004, true, $result);
- }
- }
|