xieruidong 2 years ago
parent
commit
1d90c3f1a1
3 changed files with 45 additions and 25 deletions
  1. 1 1
      app/data/controller/api/Auth.php
  2. 34 24
      app/data/controller/api/Login.php
  3. 10 0
      app/data/service/SmsSvc.php

+ 1 - 1
app/data/controller/api/Auth.php

@@ -67,7 +67,7 @@ abstract class Auth extends Controller
     {
         try {
             if (empty($this->uuid)) {
-                $token = $this->request->header('api-token');
+                $token = $this->request->header('api-token','');
                 if($this->needLogin()) {
                     if (empty($token)) $this->error('登录认证不能为空!');
                 }

+ 34 - 24
app/data/controller/api/Login.php

@@ -7,36 +7,14 @@ use app\data\service\MessageService;
 use app\data\service\UserAdminService;
 use hg\apidoc\annotation\Method;
 use hg\apidoc\annotation\Param;
-use hg\apidoc\annotation\Returned;
 use hg\apidoc\annotation\Title;
-use think\admin\Controller;
 
 /**
  * @Title("用户登录注册接口")
  */
-class Login extends Controller
+class Login extends Auth
 {
-    /**
-     * 接口认证类型
-     * @var string
-     */
-    private $type;
-
-    /**
-     * 控制器初始化
-     */
-    protected function initialize()
-    {
-        // 接收接口类型
-        $this->type = $this->request->request('api');
-        $this->type = $this->type ?: $this->request->header('api-name');
-        $this->type = $this->type ?: $this->request->header('api-type');
-        $this->type = $this->type ?: UserAdminService::API_TYPE_WAP;
-        if (empty(UserAdminService::TYPES[$this->type])) {
-            $this->error("接口支付[{$this->type}]未定义规则!");
-        }
-    }
-
+    protected $noNeedLogin=['in','register','sendsms','findpwd'];
     /**
      * @Title("手机号或用户名+密码登陆")
      * @Method("post")
@@ -63,6 +41,7 @@ class Login extends Controller
 
     /**
      * @Title("用户统一注册入口")
+     * @Method("post")
      * @Param("nickname",desc="昵称")
      * @Param("phone",desc="手机号")
      * @Param("verify",desc="验证码")
@@ -96,14 +75,45 @@ class Login extends Controller
     /**
      * @Title("发送短信验证码")
      * @Param("phone",desc="手机号")
+     * @Param("type",desc="1登陆2注册3找回密码")
      */
     public function sendsms()
     {
         $data = $this->_vali([
             'phone.mobile'   => '手机号格式错误!',
             'phone.require'  => '手机号不能为空!',
+            'type.require'  => '类型不能为空!',
+            'type.in:1,2,3'  => '类型有误!',
         ]);
+        $needLogin=[];
+        if(in_array($data['type'],$needLogin) && !$this->uuid){
+            $this->error('请登录');
+        }
         [$state, $message, $data] = MessageService::instance()->sendVerifyCode($data['phone']);
         $state ? $this->success($message, $data) : $this->error($message, $data);
     }
+
+    /**
+     * @Title("找回密码")
+     * @Method("post")
+     * @Param("phone",desc="手机号")
+     * @Param("verify",desc="验证码")
+     * @Param("password",desc="密码")
+     */
+    public function findpwd(){
+        $data=$this->_vali([
+            'phone.mobile'=>'手机号必须',
+            'phone.require'=>'手机号必须',
+            'verify.require'=>'验证码必须',
+            'password.require'=>'密码必须',
+        ]);
+        if (!MessageService::instance()->checkVerifyCode($data['verify'], $data['phone'])) {
+            $this->error('手机短信验证失败!');
+        }
+        $user=DataUser::where('phone',$data['phone'])->find();
+        if(!$user){
+            $this->error('用户不存在');
+        }
+
+    }
 }

+ 10 - 0
app/data/service/SmsSvc.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace app\data\service;
+
+use think\admin\Service;
+
+
+class SmsSvc extends Service
+{
+}