LoginController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\controller;
  20. use app\common\enum\NoticeEnum;
  21. use app\common\enum\UserTerminalEnum;
  22. use app\shopapi\{validate\LoginValidate,
  23. validate\OaLogicValidate,
  24. validate\TouTiaoValidate,
  25. validate\WechatLoginValidate,
  26. logic\LoginLogic};
  27. class LoginController extends BaseShopController
  28. {
  29. public array $notNeedLogin = [ 'check_mobile_user', 'account', 'logout','codeUrl','oaLogin','silentLogin','authLogin','config', 'captcha', 'toutiaoSilentLogin', 'toutiaoAuthLogin','uninAppLogin'];
  30. /**
  31. * @notes 检测手机号是否已注册用户
  32. * @return \think\response\Json
  33. * @author lbzy
  34. * @datetime 2023-07-12 09:36:09
  35. */
  36. function check_mobile_user()
  37. {
  38. $params = (new LoginValidate())->post()->goCheck('checkMobileUser');
  39. return $this->data([ 'has' => (int) LoginLogic::check_mobile_user($params['mobile']) ]);
  40. }
  41. /**
  42. * @notes 账号密码/手机号密码/手机号验证码登录
  43. * @date 2021/6/30 17:01
  44. * @return \think\response\Json
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. * @author 令狐冲
  49. */
  50. public function account()
  51. {
  52. $params = (new LoginValidate())->post()->goCheck('account');
  53. $result = (new LoginLogic())->login($params);
  54. if ($result === false) {
  55. return $this->fail(LoginLogic::getError());
  56. }
  57. return $this->data($result);
  58. }
  59. /**
  60. * @notes 发送验证码-登录
  61. * @author Tab
  62. * @date 2021/8/25 15:47
  63. */
  64. public function captcha()
  65. {
  66. $params = (new LoginValidate())->post()->goCheck('captcha');
  67. $code = mt_rand(1000, 9999);
  68. $result = event('Notice', [
  69. 'scene_id' => NoticeEnum::LOGIN_CAPTCHA,
  70. 'params' => [
  71. 'mobile' => $params['mobile'],
  72. 'code' => $code,
  73. ]
  74. ]);
  75. if ($result[0] === true) {
  76. return $this->success('发送成功');
  77. }
  78. return $this->fail($result[0], [], 0, 1);
  79. }
  80. /**
  81. * @notes 退出登录
  82. * @return \think\response\Json
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\DbException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. * @author 令狐冲
  87. * @date 2021/7/8 00:36
  88. */
  89. public function logout()
  90. {
  91. //退出登录情况特殊,只有成功的情况,也不需要token验证
  92. (new LoginLogic())->logout($this->userInfo);
  93. return $this->success();
  94. }
  95. /**
  96. * @notes 获取微信请求code的链接
  97. * @return \think\response\Json
  98. * @author cjhao
  99. * @date 2021/7/31 14:17
  100. */
  101. public function codeUrl()
  102. {
  103. $url = $this->request->get('url');
  104. return $this->success('获取成功', ['url' => (new LoginLogic)->codeUrl($url)], 1);
  105. }
  106. /**
  107. * @notes 公众号登录
  108. * @return \think\response\Json
  109. * @author cjhao
  110. * @date 2021/7/31 14:27
  111. */
  112. public function oaLogin()
  113. {
  114. $params = (new WechatLoginValidate())->post()->goCheck('oa');
  115. $res = (new LoginLogic)->oaLogin($params);
  116. if(false === $res){
  117. return $this->fail(LoginLogic::getError());
  118. }
  119. return $this->success('',$res);
  120. }
  121. /**
  122. * @notes 静默登录
  123. * @author cjhao
  124. * @date 2021/7/31 14:41
  125. */
  126. public function silentLogin(){
  127. $params = (new WechatLoginValidate())->post()->goCheck('silent');
  128. $res = (new LoginLogic)->silentLogin($params);
  129. if(false === $res){
  130. return $this->fail(LoginLogic::getError());
  131. }
  132. return $this->success('',$res);
  133. }
  134. /**
  135. * @notes 登录接口
  136. * @return \think\response\Json
  137. * @author cjhao
  138. * @date 2021/7/30 17:47
  139. */
  140. public function authLogin()
  141. {
  142. $params = (new WechatLoginValidate())->post()->goCheck('auth');
  143. $res = (new LoginLogic)->authLogin($params);
  144. if(false === $res){
  145. return $this->fail(LoginLogic::getError());
  146. }
  147. return $this->success('',$res);
  148. }
  149. /**
  150. * @notes uniApp微信登录
  151. * @return \think\response\Json
  152. * @author cjhao
  153. * @date 2021/9/2 11:52
  154. */
  155. public function uninAppLogin(){
  156. $params = (new WechatLoginValidate())->post()->goCheck('uninapp');
  157. $res = (new LoginLogic)->uninAppLogin($params);
  158. if(false === $res){
  159. return $this->fail(LoginLogic::getError());
  160. }
  161. return $this->success('',$res);
  162. }
  163. /**
  164. * @notes 字节小程序-静默登录
  165. * @return \think\response\Json
  166. * @author Tab
  167. * @date 2021/11/10 16:57
  168. */
  169. public function toutiaoSilentLogin()
  170. {
  171. $params = (new TouTiaoValidate())->post()->goCheck("silent");
  172. $params['terminal'] = UserTerminalEnum::TOUTIAO;
  173. $result = (new LoginLogic())->toutiaoSilentLogin($params);
  174. if ($result === false) {
  175. return $this->fail(LoginLogic::getError());
  176. }
  177. return $this->success('', $result);
  178. }
  179. /**
  180. * @notes 字节小程序-授权登录
  181. * @return \think\response\Json
  182. * @author Tab
  183. * @date 2021/11/10 16:57
  184. */
  185. public function toutiaoAuthLogin()
  186. {
  187. $params = (new TouTiaoValidate())->post()->goCheck("auth");
  188. $params['terminal'] = UserTerminalEnum::TOUTIAO;
  189. $result = (new LoginLogic())->toutiaoAuthLogin($params);
  190. if ($result === false) {
  191. return $this->fail(LoginLogic::getError());
  192. }
  193. return $this->success('', $result);
  194. }
  195. /**
  196. * @notes 小程序绑定微信
  197. * @return \think\response\Json
  198. * @author cjhao
  199. * @date 2022/5/17 15:56
  200. */
  201. public function mnpAuthLogin()
  202. {
  203. $params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
  204. $params['user_id'] = $this->userId;
  205. $result = (new LoginLogic())->mnpAuthLogin($params);
  206. if ($result === false) {
  207. return $this->fail(LoginLogic::getError());
  208. }
  209. return $this->success('绑定成功',[],1,1);
  210. }
  211. /**
  212. * @notes 公众号绑定微信
  213. * @return \think\response\Json
  214. * @throws \GuzzleHttp\Exception\GuzzleException
  215. * @throws \think\db\exception\DataNotFoundException
  216. * @throws \think\db\exception\DbException
  217. * @throws \think\db\exception\ModelNotFoundException
  218. * @author cjhao
  219. * @date 2022/5/18 9:11
  220. */
  221. public function oaAuthLogin()
  222. {
  223. $params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
  224. $params['user_id'] = $this->userId;
  225. $result = (new LoginLogic())->oaAuthLogin($params);
  226. if ($result === false) {
  227. return $this->fail(LoginLogic::getError());
  228. }
  229. return $this->success('绑定成功',[],1,1);
  230. }
  231. /**
  232. * @notes 更新用户头像昵称
  233. * @return \think\response\Json
  234. * @throws \think\db\exception\DbException
  235. * @author ljj
  236. * @date 2023/2/2 6:36 下午
  237. */
  238. public function updateUser()
  239. {
  240. $params = (new WechatLoginValidate())->post()->goCheck("updateUser");
  241. LoginLogic::updateUser($params,$this->userId);
  242. return $this->success('操作成功',[],1,1);
  243. }
  244. }