feat: 开放给第三方接口完善
parent
eb18d24fb4
commit
69e8b41587
|
@ -27,11 +27,13 @@ use app\api\validate\RegisterValidate;
|
|||
use app\api\validate\LoginValidate;
|
||||
use think\exception\ValidateException;
|
||||
use app\api\validate\OaLoginValidate;
|
||||
use think\response\Json;
|
||||
|
||||
class Account extends Api
|
||||
{
|
||||
|
||||
public $like_not_need_login = ['silentLogin', 'authLogin', 'register', 'login','mnplogin', 'codeurl', 'oalogin', 'oplogin','logout','smslogin', 'uinAppLogin', 'silentLogin', 'authLogin', 'scanCode', 'scanLogin'];
|
||||
public $like_not_need_login = ['silentLogin', 'authLogin', 'register', 'login','mnplogin', 'codeurl', 'oalogin',
|
||||
'oplogin','logout','smslogin', 'uinAppLogin', 'silentLogin', 'authLogin', 'scanCode', 'scanLogin', 'apiLogin'];
|
||||
|
||||
/**
|
||||
* 注册
|
||||
|
@ -167,7 +169,7 @@ class Account extends Api
|
|||
|
||||
/***
|
||||
* 短信登录
|
||||
* @return \think\response\Json
|
||||
* @return Json
|
||||
*/
|
||||
public function smsLogin()
|
||||
{
|
||||
|
@ -195,7 +197,7 @@ class Account extends Api
|
|||
|
||||
/**
|
||||
* @notes 扫码登录
|
||||
* @return \think\response\Json
|
||||
* @return Json
|
||||
* @author 段誉
|
||||
* @date 2021/10/29 11:50
|
||||
*/
|
||||
|
@ -211,7 +213,7 @@ class Account extends Api
|
|||
|
||||
/**
|
||||
* @notes PC端扫码登录
|
||||
* @return \think\response\Json
|
||||
* @return Json
|
||||
* @author 段誉
|
||||
* @date 2021/10/29 18:00
|
||||
*/
|
||||
|
@ -225,5 +227,20 @@ class Account extends Api
|
|||
return JsonServer::success('', $result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* AppID登录
|
||||
* 开放给第三方使用
|
||||
*/
|
||||
public function apiLogin(): Json
|
||||
{
|
||||
$post = $this->request->post();
|
||||
if (empty($post['app_id']) || empty($post['app_secret'])) {
|
||||
return JsonServer::error('参数错误');
|
||||
}
|
||||
$data = LoginLogic::apiLogin($post);
|
||||
if (false === $data) {
|
||||
return JsonServer::error(LoginLogic::getError() ?? '未知错误');
|
||||
}
|
||||
return JsonServer::success('登录成功',$data);
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ use app\api\server\UserServer;
|
|||
use app\common\basics\Logic;
|
||||
use app\common\enum\ClientEnum;
|
||||
use app\common\model\distribution\Distribution;
|
||||
use app\common\model\user\UserApi;
|
||||
use app\common\server\WeChatServer;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\model\Client_;
|
||||
|
@ -624,5 +625,45 @@ class LoginLogic extends Logic
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方接口登录 APPID和appSecret
|
||||
*/
|
||||
public static function apiLogin($post)
|
||||
{
|
||||
try {
|
||||
if (!$userApi = UserApi::where('app_id', $post['app_id'])->where('app_secret', $post['app_secret'])->find()) {
|
||||
throw new \Exception('账号错误');
|
||||
}
|
||||
$user = User::field(['id', 'nickname', 'avatar', 'level', 'disable', 'distribution_code', 'is_api', 'del'])
|
||||
->where(['id' => $userApi['id']])
|
||||
->findOrEmpty()->toArray();
|
||||
if ($user['disable'] > 0) {
|
||||
throw new \Exception('账号已禁用');
|
||||
}
|
||||
|
||||
if ($user['del'] == 1) {
|
||||
throw new \Exception('账号异常,请联系管理员');
|
||||
}
|
||||
|
||||
if ($user['is_api'] != 1) {
|
||||
throw new \Exception('账号API授权已关闭');
|
||||
}
|
||||
|
||||
unset($user['del']);
|
||||
|
||||
$user['token'] = self::createSession($user['id'], ClientEnum::api);
|
||||
if (empty($user['avatar'])) {
|
||||
$user['avatar'] = UrlServer::getFileUrl(ConfigServer::get('website', 'user_image'));
|
||||
} else {
|
||||
$user['avatar'] = UrlServer::getFileUrl($user['avatar']);
|
||||
}
|
||||
return $user;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ class ClientEnum
|
|||
const pc = 5;
|
||||
const h5 = 6;//h5(非微信环境h5)
|
||||
const backend = 7;//PC后台
|
||||
const api = 8;//第三方API登录
|
||||
|
||||
function getName($value)
|
||||
{
|
||||
|
@ -54,6 +55,9 @@ class ClientEnum
|
|||
case self::backend:
|
||||
$name = '后台';
|
||||
break;
|
||||
case self::api:
|
||||
$name = 'API';
|
||||
break;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
@ -69,6 +73,7 @@ class ClientEnum
|
|||
self::ios => '苹果APP商城',
|
||||
self::android => '安卓APP商城',
|
||||
self::backend => '后台',
|
||||
self::api => 'API',
|
||||
];
|
||||
if ($type === true) {
|
||||
return $desc;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace app\common\model\user;
|
||||
|
||||
use app\common\basics\Models;
|
||||
|
||||
class UserApi extends Models
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in New Issue