| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop100%开源免费商用商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | 商业版本务必购买商业授权,以免引起法律纠纷
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshopTeam
- // +----------------------------------------------------------------------
- namespace app\shopapi\controller;
- use app\common\enum\NoticeEnum;
- use app\common\enum\UserTerminalEnum;
- use app\shopapi\{validate\LoginValidate,
- validate\OaLogicValidate,
- validate\TouTiaoValidate,
- validate\WechatLoginValidate,
- logic\LoginLogic};
- class LoginController extends BaseShopController
- {
- public array $notNeedLogin = [ 'check_mobile_user', 'account', 'logout','codeUrl','oaLogin','silentLogin','authLogin','config', 'captcha', 'toutiaoSilentLogin', 'toutiaoAuthLogin','uninAppLogin'];
-
- /**
- * @notes 检测手机号是否已注册用户
- * @return \think\response\Json
- * @author lbzy
- * @datetime 2023-07-12 09:36:09
- */
- function check_mobile_user()
- {
- $params = (new LoginValidate())->post()->goCheck('checkMobileUser');
-
- return $this->data([ 'has' => (int) LoginLogic::check_mobile_user($params['mobile']) ]);
- }
-
- /**
- * @notes 账号密码/手机号密码/手机号验证码登录
- * @date 2021/6/30 17:01
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author 令狐冲
- */
- public function account()
- {
- $params = (new LoginValidate())->post()->goCheck('account');
- $result = (new LoginLogic())->login($params);
- if ($result === false) {
- return $this->fail(LoginLogic::getError());
- }
- return $this->data($result);
- }
- /**
- * @notes 发送验证码-登录
- * @author Tab
- * @date 2021/8/25 15:47
- */
- public function captcha()
- {
- $params = (new LoginValidate())->post()->goCheck('captcha');
- $code = mt_rand(1000, 9999);
- $result = event('Notice', [
- 'scene_id' => NoticeEnum::LOGIN_CAPTCHA,
- 'params' => [
- 'mobile' => $params['mobile'],
- 'code' => $code,
- ]
- ]);
- if ($result[0] === true) {
- return $this->success('发送成功');
- }
- return $this->fail($result[0], [], 0, 1);
- }
- /**
- * @notes 退出登录
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author 令狐冲
- * @date 2021/7/8 00:36
- */
- public function logout()
- {
- //退出登录情况特殊,只有成功的情况,也不需要token验证
- (new LoginLogic())->logout($this->userInfo);
- return $this->success();
- }
- /**
- * @notes 获取微信请求code的链接
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/31 14:17
- */
- public function codeUrl()
- {
- $url = $this->request->get('url');
- return $this->success('获取成功', ['url' => (new LoginLogic)->codeUrl($url)], 1);
- }
- /**
- * @notes 公众号登录
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/31 14:27
- */
- public function oaLogin()
- {
- $params = (new WechatLoginValidate())->post()->goCheck('oa');
- $res = (new LoginLogic)->oaLogin($params);
- if(false === $res){
- return $this->fail(LoginLogic::getError());
- }
- return $this->success('',$res);
- }
- /**
- * @notes 静默登录
- * @author cjhao
- * @date 2021/7/31 14:41
- */
- public function silentLogin(){
- $params = (new WechatLoginValidate())->post()->goCheck('silent');
- $res = (new LoginLogic)->silentLogin($params);
- if(false === $res){
- return $this->fail(LoginLogic::getError());
- }
- return $this->success('',$res);
- }
- /**
- * @notes 登录接口
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/30 17:47
- */
- public function authLogin()
- {
- $params = (new WechatLoginValidate())->post()->goCheck('auth');
- $res = (new LoginLogic)->authLogin($params);
- if(false === $res){
- return $this->fail(LoginLogic::getError());
- }
- return $this->success('',$res);
- }
- /**
- * @notes uniApp微信登录
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/9/2 11:52
- */
- public function uninAppLogin(){
- $params = (new WechatLoginValidate())->post()->goCheck('uninapp');
- $res = (new LoginLogic)->uninAppLogin($params);
- if(false === $res){
- return $this->fail(LoginLogic::getError());
- }
- return $this->success('',$res);
- }
- /**
- * @notes 字节小程序-静默登录
- * @return \think\response\Json
- * @author Tab
- * @date 2021/11/10 16:57
- */
- public function toutiaoSilentLogin()
- {
- $params = (new TouTiaoValidate())->post()->goCheck("silent");
- $params['terminal'] = UserTerminalEnum::TOUTIAO;
- $result = (new LoginLogic())->toutiaoSilentLogin($params);
- if ($result === false) {
- return $this->fail(LoginLogic::getError());
- }
- return $this->success('', $result);
- }
- /**
- * @notes 字节小程序-授权登录
- * @return \think\response\Json
- * @author Tab
- * @date 2021/11/10 16:57
- */
- public function toutiaoAuthLogin()
- {
- $params = (new TouTiaoValidate())->post()->goCheck("auth");
- $params['terminal'] = UserTerminalEnum::TOUTIAO;
- $result = (new LoginLogic())->toutiaoAuthLogin($params);
- if ($result === false) {
- return $this->fail(LoginLogic::getError());
- }
- return $this->success('', $result);
- }
- /**
- * @notes 小程序绑定微信
- * @return \think\response\Json
- * @author cjhao
- * @date 2022/5/17 15:56
- */
- public function mnpAuthLogin()
- {
- $params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
- $params['user_id'] = $this->userId;
- $result = (new LoginLogic())->mnpAuthLogin($params);
- if ($result === false) {
- return $this->fail(LoginLogic::getError());
- }
- return $this->success('绑定成功',[],1,1);
- }
- /**
- * @notes 公众号绑定微信
- * @return \think\response\Json
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author cjhao
- * @date 2022/5/18 9:11
- */
- public function oaAuthLogin()
- {
- $params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
- $params['user_id'] = $this->userId;
- $result = (new LoginLogic())->oaAuthLogin($params);
- if ($result === false) {
- return $this->fail(LoginLogic::getError());
- }
- return $this->success('绑定成功',[],1,1);
- }
- /**
- * @notes 更新用户头像昵称
- * @return \think\response\Json
- * @throws \think\db\exception\DbException
- * @author ljj
- * @date 2023/2/2 6:36 下午
- */
- public function updateUser()
- {
- $params = (new WechatLoginValidate())->post()->goCheck("updateUser");
- LoginLogic::updateUser($params,$this->userId);
- return $this->success('操作成功',[],1,1);
- }
- }
|