fly 5 年之前
父節點
當前提交
e4d9fcb44f

+ 67 - 0
app/Http/Controllers/QuickApp/User/UserController.php

@@ -4,8 +4,11 @@ namespace App\Http\Controllers\QuickApp\User;
 
 
 use App\Http\Controllers\QuickApp\BaseController;
+use App\Libs\AliSMS;
 use App\Modules\Subscribe\Services\YearOrderService;
+use App\Modules\User\Services\QappUserService;
 use App\Modules\User\Services\UserSignService;
+use Redis;
 
 class UserController extends BaseController
 {
@@ -110,4 +113,68 @@ class UserController extends BaseController
         }
         return response()->error('QAPP_SYS_ERROR');
     }
+
+    /**
+     * @apiVersion 1.0.0
+     * @apiDescription 发送验证码
+     * @api {GET} sendCode 发送验证码
+     * @apiHeader {String} [Authorization]  token
+     * @apiGroup User
+     * @apiName sendCode
+     * @apiSuccess {String}  phone 手机号
+     * @apiSuccessExample {json} Success-Response:
+     *
+     *     {
+     *         "code": 0,
+     *         "msg": "",
+     *         "data": {}
+     *     }
+     */
+    public function sendCode(Request $request)
+    {
+        $phone = $request->post('phone');
+        $code = random_int(1000, 9999);
+        Redis::setex('quser_code:' . $phone, 120, $code);
+        AliSMS::send($phone, 'quickapp_user_bind_phone', ['code' => $code]);
+        return response()->success();
+    }
+
+    /**
+     * @apiVersion 1.0.0
+     * @apiDescription 绑定手机号
+     * @api {GET} bindPhone 绑定手机号
+     * @apiHeader {String} [Authorization]  token
+     * @apiGroup User
+     * @apiName bindPhone
+     * @apiSuccess {String}  phone 手机号
+     * @apiSuccess {String}  code 验证码
+     * @apiSuccessExample {json} Success-Response:
+     *
+     *     {
+     *         "code": 0,
+     *         "msg": "",
+     *         "data": {}
+     *     }
+     */
+    public function bindPhone(Request $request)
+    {
+        $code = $request->post('code');
+        $phone = $request->post('phone');
+        $old = Redis::get('quser_code:' . $phone);
+        if ($old && $old == $code) {
+            try {
+                Redis::del('quser_code:' . $phone);
+                $result = QappUserService::bindPhoneStatic($this->uid, $phone);
+                if (!$result) {
+                    return response()->error('WAP_BIND_PHONE_EXIST');
+                } else {
+                    return response()->success();
+                }
+            } catch (\Exception $e) {
+                return response()->error();
+            }
+        } else {
+            return response()->error('WAP_SEND_CODE_ERROR');
+        }
+    }
 }

+ 0 - 2
app/Libs/AliSMS.php

@@ -28,7 +28,6 @@ class AliSMS
     static function send($number,$template_type,$param=array(),$sign='追书云')
     {
     	$sign = env('SMS_SIGN');
-        \Log::info('AliSMS_send:number:'.$number.' template_type:'.$template_type.' param:'.json_encode($param));
         // 根据类型找模板id
         $sms_template = SmsTemplate::get_sms_template($template_type);
     
@@ -37,7 +36,6 @@ class AliSMS
                 return false;
         }
         $template_id = isset($sms_template->template_id)?$sms_template->template_id:'';
-        \Log::info('AliSMS_send:number:'.$number.' template_type:'.$template_type.' template_id:'.$template_id.' param:'.json_encode($param));
          
         $response = ZsySms::sendSms($number,$template_id,$param,$sign);
         \Log::info('send_response:'.json_encode($response));

+ 22 - 1
app/Modules/User/Services/QappUserService.php

@@ -14,8 +14,9 @@ use Tymon\JWTAuth\Facades\JWTAuth;
 /**
  * 
  * @method static \App\Modules\User\Models\QappUser setGolableUserStatic(int $uid) 设置快应用用户信息(全局)
- * @method static \App\Modules\User\Models\QappUser getGolableUserStatic() 获取快应用用户信息(全局)
+ * @method static void getGolableUserStatic() 获取快应用用户信息(全局)
  * @method static \App\Modules\User\Models\QappUser loginStatic(array $data) 快应用用户登录
+ * @method static bool bindPhoneStatic(int $uid, string $phone) 绑定手机号
  */
 class QappUserService
 {
@@ -44,6 +45,26 @@ class QappUserService
         return $qapp_user;
     }
 
+    /**
+     * 绑定手机号
+     */
+    public function bindPhone(int $uid, string $phone)
+    {
+        $is_exists = QappUser::where('phone', $phone)->exists();
+        if ($is_exists) {
+            return false;
+        } else {
+            $qapp_user = QappUser::where('uid', $uid)->first();
+            if ($qapp_user->phone) {
+                return false;
+            } else {
+                $qapp_user->phone = $phone;
+                $qapp_user->save();
+                return true;
+            }
+        }
+    }
+
     public function setGolableUser(int $uid)
     {
         $user_info = $this->getQAppUserByUid($uid);

+ 95 - 0
public/kyydoc/api_data.js

@@ -3417,6 +3417,57 @@ define({ "api": [
   },
   {
     "version": "1.0.0",
+    "description": "<p>绑定手机号</p>",
+    "type": "GET",
+    "url": "bindPhone",
+    "title": "绑定手机号",
+    "header": {
+      "fields": {
+        "Header": [
+          {
+            "group": "Header",
+            "type": "String",
+            "optional": true,
+            "field": "Authorization",
+            "description": "<p>token</p>"
+          }
+        ]
+      }
+    },
+    "group": "User",
+    "name": "bindPhone",
+    "success": {
+      "fields": {
+        "Success 200": [
+          {
+            "group": "Success 200",
+            "type": "String",
+            "optional": false,
+            "field": "phone",
+            "description": "<p>手机号</p>"
+          },
+          {
+            "group": "Success 200",
+            "type": "String",
+            "optional": false,
+            "field": "code",
+            "description": "<p>验证码</p>"
+          }
+        ]
+      },
+      "examples": [
+        {
+          "title": "Success-Response:",
+          "content": "\n{\n    \"code\": 0,\n    \"msg\": \"\",\n    \"data\": {}\n}",
+          "type": "json"
+        }
+      ]
+    },
+    "filename": "app/Http/Controllers/QuickApp/User/UserController.php",
+    "groupTitle": "用户"
+  },
+  {
+    "version": "1.0.0",
     "description": "<p>获取用户信息</p>",
     "type": "GET",
     "url": "userinfo",
@@ -3556,6 +3607,50 @@ define({ "api": [
   },
   {
     "version": "1.0.0",
+    "description": "<p>发送验证码</p>",
+    "type": "GET",
+    "url": "sendCode",
+    "title": "发送验证码",
+    "header": {
+      "fields": {
+        "Header": [
+          {
+            "group": "Header",
+            "type": "String",
+            "optional": true,
+            "field": "Authorization",
+            "description": "<p>token</p>"
+          }
+        ]
+      }
+    },
+    "group": "User",
+    "name": "sendCode",
+    "success": {
+      "fields": {
+        "Success 200": [
+          {
+            "group": "Success 200",
+            "type": "String",
+            "optional": false,
+            "field": "phone",
+            "description": "<p>手机号</p>"
+          }
+        ]
+      },
+      "examples": [
+        {
+          "title": "Success-Response:",
+          "content": "\n{\n    \"code\": 0,\n    \"msg\": \"\",\n    \"data\": {}\n}",
+          "type": "json"
+        }
+      ]
+    },
+    "filename": "app/Http/Controllers/QuickApp/User/UserController.php",
+    "groupTitle": "用户"
+  },
+  {
+    "version": "1.0.0",
     "description": "<p>用户签到</p>",
     "type": "GET",
     "url": "sign",

+ 95 - 0
public/kyydoc/api_data.json

@@ -3417,6 +3417,57 @@
   },
   {
     "version": "1.0.0",
+    "description": "<p>绑定手机号</p>",
+    "type": "GET",
+    "url": "bindPhone",
+    "title": "绑定手机号",
+    "header": {
+      "fields": {
+        "Header": [
+          {
+            "group": "Header",
+            "type": "String",
+            "optional": true,
+            "field": "Authorization",
+            "description": "<p>token</p>"
+          }
+        ]
+      }
+    },
+    "group": "User",
+    "name": "bindPhone",
+    "success": {
+      "fields": {
+        "Success 200": [
+          {
+            "group": "Success 200",
+            "type": "String",
+            "optional": false,
+            "field": "phone",
+            "description": "<p>手机号</p>"
+          },
+          {
+            "group": "Success 200",
+            "type": "String",
+            "optional": false,
+            "field": "code",
+            "description": "<p>验证码</p>"
+          }
+        ]
+      },
+      "examples": [
+        {
+          "title": "Success-Response:",
+          "content": "\n{\n    \"code\": 0,\n    \"msg\": \"\",\n    \"data\": {}\n}",
+          "type": "json"
+        }
+      ]
+    },
+    "filename": "app/Http/Controllers/QuickApp/User/UserController.php",
+    "groupTitle": "用户"
+  },
+  {
+    "version": "1.0.0",
     "description": "<p>获取用户信息</p>",
     "type": "GET",
     "url": "userinfo",
@@ -3556,6 +3607,50 @@
   },
   {
     "version": "1.0.0",
+    "description": "<p>发送验证码</p>",
+    "type": "GET",
+    "url": "sendCode",
+    "title": "发送验证码",
+    "header": {
+      "fields": {
+        "Header": [
+          {
+            "group": "Header",
+            "type": "String",
+            "optional": true,
+            "field": "Authorization",
+            "description": "<p>token</p>"
+          }
+        ]
+      }
+    },
+    "group": "User",
+    "name": "sendCode",
+    "success": {
+      "fields": {
+        "Success 200": [
+          {
+            "group": "Success 200",
+            "type": "String",
+            "optional": false,
+            "field": "phone",
+            "description": "<p>手机号</p>"
+          }
+        ]
+      },
+      "examples": [
+        {
+          "title": "Success-Response:",
+          "content": "\n{\n    \"code\": 0,\n    \"msg\": \"\",\n    \"data\": {}\n}",
+          "type": "json"
+        }
+      ]
+    },
+    "filename": "app/Http/Controllers/QuickApp/User/UserController.php",
+    "groupTitle": "用户"
+  },
+  {
+    "version": "1.0.0",
     "description": "<p>用户签到</p>",
     "type": "GET",
     "url": "sign",

+ 1 - 1
public/kyydoc/api_project.js

@@ -17,7 +17,7 @@ define({
   "apidoc": "0.3.0",
   "generator": {
     "name": "apidoc",
-    "time": "2019-10-29T08:38:53.978Z",
+    "time": "2019-10-29T09:11:53.672Z",
     "url": "http://apidocjs.com",
     "version": "0.17.7"
   }

+ 1 - 1
public/kyydoc/api_project.json

@@ -17,7 +17,7 @@
   "apidoc": "0.3.0",
   "generator": {
     "name": "apidoc",
-    "time": "2019-10-29T08:38:53.978Z",
+    "time": "2019-10-29T09:11:53.672Z",
     "url": "http://apidocjs.com",
     "version": "0.17.7"
   }