xieruidong 2 年之前
父节点
当前提交
e3d230bd9c
共有 4 个文件被更改,包括 246 次插入193 次删除
  1. 27 4
      application/api/controller/qiyu/User.php
  2. 23 0
      application/common/model/QiyuToken.php
  3. 6 0
      application/common/model/User.php
  4. 190 189
      public/api.html

+ 27 - 4
application/api/controller/qiyu/User.php

@@ -2,6 +2,7 @@
 
 namespace app\api\controller\qiyu;
 use app\common\controller\Api;
+use app\common\model\QiyuToken;
 use think\Cache;
 
 /**
@@ -27,17 +28,39 @@ class User extends Api
         if($data['appsecret']!=$config['appSecret']){
             $this->error('appsecret有误');
         }
-        $cacheName="qiyu_crm_token";
         $expire=$config['expire']??7200;
-        $token=Cache::remember($cacheName,function (){
-            return session_create_id();
-        },$expire);
+        $token=QiyuToken::getToken();
         $this->success('',[
             'token'=>$token,
             'expires'=>$expire,
         ]);
     }
 
+    /**
+     * 获取用户信息
+     * @param string userid
+     */
+    public function info(){
+        $data=$this->_validate([
+            'userid'=>['require']
+        ]);
+        $user=\app\common\model\User::where('mobile',$data['userid'])->find();
+        if(!$user){
+            $this->error('用户不存在');
+        }
+        $this->success('',[
+            'uid'=>$data['userid'],
+            'data'=>[
+                ['index'=>0,'key'=>'account','label'=>'账户','value'=>$user->getShowName()],
+                ['index'=>1,'key'=>'name','label'=>'昵称','value'=>$user['nickname']],
+                ['index'=>2,'key'=>'mobile','label'=>'手机号','value'=>$user['mobile']],
+            ]
+        ]);
+    }
+
+    protected function checkToken(){
+
+    }
     protected function success($msg = '', $data = [], $code = 1, $type = null, array $header = [])
     {
         $info=[

+ 23 - 0
application/common/model/QiyuToken.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace app\common\model;
+
+use Carbon\Carbon;
+use think\Model;
+
+/**
+ * 短信验证码
+ */
+class QiyuToken Extends Model
+{
+    public static function clear(){
+        return self::where('expire','<',time())->delete();
+    }
+    public static function getToken(){
+        self::clear();
+        return self::create([
+            'token'=>session_create_id(),
+            'expire'=>Carbon::now()->addSeconds(7210)->timestamp,
+        ])['token'];
+    }
+}

+ 6 - 0
application/common/model/User.php

@@ -270,6 +270,12 @@ class User extends Model
     public static function recharge($params,Payment $payment){
         self::money($payment['amount'],$payment['uer_id'],MoneyLog::TYPE_CHARGE,'充值');
     }
+    public function getShowName(){
+        if($this['username']){
+            return $this['username'];
+        }
+        return $this['mobile'];
+    }
     public function verification(){
         return $this->hasOne(UserVerification::class);
     }

文件差异内容过多而无法显示
+ 190 - 189
public/api.html


部分文件因为文件数量过多而无法显示