Browse Source

用户登录

afa 5 months ago
parent
commit
499ae32ea9

+ 11 - 0
app/api/common.php

@@ -0,0 +1,11 @@
+<?php
+// 这是系统自动生成的公共文件
+if (!function_exists('create_out_trade_no')) {
+    /**
+     * 生成随机订单号
+     */
+    function create_out_trade_no()
+    {
+        return date('YmdHis',time()).rand(10000,99999);
+    }
+}

+ 33 - 0
app/api/config/site.php

@@ -0,0 +1,33 @@
+<?php
+// +----------------------------------------------------------------------
+// | 应用设置
+// +----------------------------------------------------------------------
+
+return [
+     'auth'=>[
+          //允许同时在线的设备数量
+         'allow_device_num'=>10,
+          //使用期间自动续时
+         'keepalive'=>true,
+          //保持登陆时间,单位秒
+         'keepalive_time'=>24*3600*30,
+         //用户信息保存适配器,更换适配器需要实现app\api\service\auth\Adapter接口
+         'adapter'=>app\api\service\auth\MysqlAdapter::class,
+     ],
+    'upload'=>[
+        //上传地址
+        'uploadurl' => 'ajax/upload',
+        //上传适配器
+        'disks'   => 'local_public',
+        //最大可上传大小,单位mb
+        'maxsize'   => 10,
+        //可上传的文件类型
+        'mimetype'  => 'jpg,png,bmp,jpeg,gif,txt,doc,docx,xls,xlsx',
+        //生成缩略图
+        'thumb'=>true,
+        //压缩图片
+        'compress'=>true,
+        //图片加水印
+        'watermark'=>true
+    ]
+];

+ 58 - 0
app/api/controller/Api.php

@@ -0,0 +1,58 @@
+<?php
+/**
+ * ----------------------------------------------------------------------------
+ * 行到水穷处,坐看云起时
+ * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
+ * ----------------------------------------------------------------------------
+ * Author: 老成
+ * email:85556713@qq.com
+ */
+declare(strict_types=1);
+
+namespace app\api\controller;
+
+use app\api\service\ApiAuthService;
+use app\common\controller\BaseController;
+use think\exception\HttpResponseException;
+use think\facade\Config;
+use think\facade\Cookie;
+use think\Response;
+
+class Api extends BaseController
+{
+    /**
+     * 当前登录用户
+     * @var \app\api\service\ApiAuthService
+     */
+    protected $auth;
+    /**
+     * 无需登录的方法,同时也就不需要鉴权了
+     * @var array
+     */
+    protected $noNeedLogin = [];
+
+    protected function _initialize()
+    {
+
+        $token=request()->header('token');
+        if(!$token){
+            $token=Cookie::get('token');
+        }
+        if(!$token){
+            $token=request()->get('token');
+        }
+        if(!$token){
+            $token=request()->post('token');
+        }
+        //$this->auth=ApiAuthService::newInstance(['adapter'=>new $class($token)]);
+    
+        $actionname = $this->request->action();
+        $noNeedLoginSet=is_string($this->noNeedLogin)?[$this->noNeedLogin]:$this->noNeedLogin;
+        $noNeedLogin = in_array('*',$noNeedLoginSet) || in_array($actionname,$noNeedLoginSet);
+        //需要登陆
+        // if(!$noNeedLogin && !$this->auth->isLogin()){
+        //     $response = Response::create(__('请先登录!'), 'html', 401);
+        //     throw new HttpResponseException($response);
+        // }
+    }
+}

+ 37 - 0
app/api/controller/Common.php

@@ -0,0 +1,37 @@
+<?php
+declare(strict_types=1);
+
+namespace app\api\controller;
+
+
+use app\common\service\upload\PublicUploadService;
+
+
+class Common extends Api{
+    protected $noNeedLogin = ['*'];
+
+    /**
+     * 上传文件
+     * @param File $file 文件流
+     */
+    public function upload()
+    {
+        $file = $this->request->file('file');
+        try{
+            $savename=PublicUploadService::newInstance([
+                'config'=>config('site.upload'),
+                'user_id'=>$this->auth->id,
+                'file'=>$file
+            ])->save();
+        }catch (\Exception $e){
+            $this->error(__('上传文件出错'),[
+                'file'=>$e->getFile(),
+                'line'=>$e->getLine(),
+                'msg'=>$e->getMessage()
+            ]);
+        }
+        $this->success('',$savename);
+    }
+
+
+}

+ 71 - 0
app/api/controller/Index.php

@@ -0,0 +1,71 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\controller;
+
+use app\api\service\msg\WechatMsg;
+
+
+
+class Index extends Api
+{
+    protected $noNeedLogin = ['*'];
+
+
+    public function hello()
+    {
+      
+        $this->success('返回消息');
+    }
+
+
+    public function testpost()
+    {
+        sleep(1);
+        $data=$this->request->post();
+        $this->success('返回消息',$data);
+    }
+
+
+    public function list()
+    {
+        $page=$this->request->get('page/d');
+        //假装有29条数据
+        $limit=0;
+        if($page==1 || $page==2){
+            $limit=10;
+        }
+        if($page==3){
+            $limit=9;
+        }
+        if($page>3){
+            $limit=0;
+        }
+        $res=[];
+        for ($i=0;$i<$limit;$i++){
+            $id=($page-1)*10+1+$i;
+            $res[]=array(
+                'id'=>$id,
+                'title'=>'标题'.$id,
+                'content'=>'内容'.$id
+            );
+        }
+        $this->success('',$res);
+    }
+
+    public function mpconfig()
+    {
+        $result=[
+            'url'=>$this->request->domain().'/api/mpapp/connect',
+            'token'=>site_config("uniapp.mpapp_token"),
+            'encodingaeskey'=>site_config("uniapp.mpapp_aeskey"),
+        ];
+        $this->success('',$result);
+    }
+
+    public function sendtempmsg()
+    {
+        WechatMsg::testMsg($this->auth->id);
+        $this->success('创建消息成功,等待消息推送');
+    }
+}

+ 58 - 0
app/api/controller/Miniapp.php

@@ -0,0 +1,58 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\controller;
+
+use app\common\model\Third;
+
+
+class Miniapp extends Api
+{
+    protected $noNeedLogin = ['login','getMobile','mockLogin'];
+
+    public function login()
+    {
+        $code=$this->request->post('code');
+        $config=[
+            'appid'=>site_config("uniapp.miniapp_id"),
+            'appsecret'=>site_config("uniapp.miniapp_secret")
+        ];
+        $mini = new \WeMini\Crypt($config);
+        $data = $mini->session($code);
+        $openid=$data['openid'];
+        $unionid=isset($data['unionid'])?$data['unionid']:'';
+        $avatar=$this->request->post('avatar');
+        $nickname=$this->request->post('nickname');
+        $mobile=$this->request->post('mobile');
+        //判断是否启用账号绑定
+        $third=Third::connect(Third::PLATFORM('微信小程序'), compact('openid', 'unionid', 'avatar', 'nickname', 'mobile'));
+        $this->auth->loginByThirdPlatform(Third::PLATFORM('微信小程序'),$third);
+        $token=$this->auth->getToken();
+        $userinfo=$this->auth->userinfo();
+        $this->success('登录成功',compact('token','userinfo'));
+    }
+
+
+    public function getMobile()
+    {
+        $code=$this->request->post('code');
+        $config=[
+            'appid'=>site_config("uniapp.miniapp_id"),
+            'appsecret'=>site_config("uniapp.miniapp_secret")
+        ];
+        $mini = new \WeMini\Crypt($config);
+        $result=$mini->getPhoneNumber($code);
+        $this->success('',$result['phone_info']['phoneNumber']);
+    }
+
+    //模拟登陆
+    public function mockLogin()
+    {
+        $openid=$this->request->post('openid');
+        $third=Third::where(['openid'=>$openid,'platform'=>Third::PLATFORM('微信小程序')])->find();
+        $this->auth->loginByThirdPlatform(Third::PLATFORM('微信小程序'),$third);
+        $token=$this->auth->getToken();
+        $userinfo=$this->auth->userinfo();
+        $this->success('登录成功',compact('token','userinfo'));
+    }
+}

+ 239 - 0
app/api/controller/Mpapp.php

@@ -0,0 +1,239 @@
+<?php
+declare(strict_types=1);
+namespace app\api\controller;
+
+use app\common\model\Admin;
+use app\common\model\MpSubscribe;
+use app\common\model\Qrcode;
+use app\common\model\Third;
+use app\common\model\QrcodeScan;
+use app\common\model\User;
+
+
+class Mpapp extends Api{
+    protected $noNeedLogin = ['*'];
+
+    protected $config=[];
+
+    const PAGE=[
+        //首页
+        'index'=>'/pages/index/index',
+        //绑定用户
+        'binduser'=>'/pages/index/index',
+        //NEXT页
+        'next'=>'/pages/index/next',
+    ];
+
+    protected function _initialize()
+    {
+        parent::_initialize();
+        $this->config=[
+            'appid'=>site_config("uniapp.mpapp_id"),
+            'appsecret'=>site_config("uniapp.mpapp_secret"),
+            'token'=>site_config("uniapp.mpapp_token"),
+            'encodingaeskey'=>site_config("uniapp.mpapp_aeskey")
+        ];
+    }
+    /**
+     * 发起授权
+     */
+    public function connect()
+    {
+        if($this->auth->id){
+            return $this->gourl();
+        }else{
+            $arr=$this->request->get();
+            if(count($arr)>0){
+                $str='';
+                foreach ($arr as $k=>$v){
+                    $str.=$k.'='.$v.'&';
+                }
+                $str=substr($str,0,strlen($str)-1);
+                $callback=$this->request->domain().'/api/mpapp/callback?'.$str;
+            }else{
+                $callback=$this->request->domain().'/api/mpapp/callback';
+            }
+            $wechat = new \WeChat\Oauth($this->config);
+            // 执行操作
+            $result = $wechat->getOauthRedirect($callback, '', 'snsapi_userinfo');
+            return redirect($result);
+        }
+    }
+
+    /**
+     * 授权回调
+     */
+    public function callback()
+    {
+        // 授权成功后的回调
+        $wechat = new \WeChat\Oauth($this->config);
+        $result = $wechat->getOauthAccessToken();
+        $userinfo = $wechat->getUserInfo($result['access_token'],$result['openid']);
+        $result['nickname']=$userinfo['nickname'];
+        $result['avatar']=$userinfo['headimgurl'];
+        //判断是否启用账号绑定
+        $third=Third::connect('mpapp', $result);
+        $this->auth->loginByThirdPlatform(Third::PLATFORM('微信公众号'),$third);
+        return $this->gourl();
+    }
+
+    private function gourl()
+    {
+        $arr=$this->request->get();
+        $action=$arr['action'];
+        unset($arr['action']);
+        unset($arr['code']);
+        unset($arr['state']);
+        $query='&'.http_build_query($arr);
+        $url=request()->domain().'/h5/#'.self::PAGE[$action].'?token='.$this->auth->getToken().$query;
+        return redirect($url);
+    }
+
+    /**
+     * 创建菜单
+     */
+    public function menu()
+    {
+        $this->error('请删除这行代码后重试');
+        $menu = new \WeChat\Menu($this->config);
+        $json=array('button'=>[
+            //跳转到公众号页面
+            [
+                "name"=>"首页",
+                "url"=>$this->request->domain()."/h5/#/pages/index/index",
+                "type"=>"view",
+            ],
+            //跳转到小程序页面
+            [
+                "name"=>"列表",
+                "type"=>"miniprogram",
+                "appid"=>site_config("uniapp.miniapp_id"),
+                "pagepath"=>"pages/index/list",
+            ],
+            //二级页面
+            [
+                "name"=>"我的",
+                "sub_button"=>[
+                    //先登陆,再跳转到指定页面
+                    [
+                        "name"=>"我的余额",
+                        "url"=>$this->request->domain()."api/mpapp/connect?action=101",
+                        "type"=>"view",
+                    ],
+                    [
+                        "name"=>"其他菜单",
+                        "type"=>"click",
+                        "key"=>"V1001_GOOD",
+                    ],
+                ]
+            ]
+        ]);
+        // 执行创建菜单
+        $menu->create($json);
+        $this->success('创建菜单成功');
+    }
+
+    /**
+     * 公众号事件接收方法
+     */
+    public function event()
+    {
+        $api = new \WeChat\Receive($this->config);
+        $msgtype=$api->getMsgType();
+        if($msgtype=='text'){
+            $api->text('尊敬客户您好,感谢您使用【'.site_config("basic.sitename").'】公众号!')->reply();
+            return;
+        }
+        if($msgtype=='event'){
+            $message = $api->getReceive();
+            event('write_log','微信消息:'.json_encode($message));
+            $event = $message['Event'];
+            $eventkey = isset($message['EventKey'])? $message['EventKey'] : '';
+            $openid=$message['FromUserName'];
+            switch ($event) {
+                //添加关注
+                case 'subscribe':
+                    $user = new \WeChat\User($this->config);
+                    $userinfo=$user->getUserInfo($openid);
+                    $unionid=isset($userinfo['unionid'])?$userinfo['unionid'] : '';
+                    //记录关注
+                    MpSubscribe::create([
+                        'openid'=>$openid,
+                        'unionid'=>$unionid,
+                    ]);
+                    //普通关注
+                    if(is_array($eventkey)){
+                        $api->text('尊敬客户您好,感谢您使用【'.site_config("basic.sitename").'】公众号!')->reply();
+                        return;
+                    }
+                    //扫码关注
+                    if(strpos($eventkey,'qrscene_')===0){
+                        $eventkey=substr($eventkey,8);
+                        $resp=$this->scanQrcode($openid,$unionid,$eventkey);
+                        $api->text($resp)->reply();
+                        return;
+                    }
+                //取消关注
+                case 'unsubscribe':
+                    MpSubscribe::where(['openid'=>$openid])->delete();
+                    return;
+                //扫二维码
+                case 'SCAN':
+                    $user = new \WeChat\User($this->config);
+                    $userinfo=$user->getUserInfo($openid);
+                    $unionid=isset($userinfo['unionid'])?$userinfo['unionid'] : '';
+                    $resp=$this->scanQrcode($openid,$unionid,$eventkey);
+                    $api->text($resp)->reply();
+                    return;
+                //跳转链接
+                case 'VIEW':
+            }
+        }
+    }
+
+    /**
+     * 扫码回调事件
+     */
+    private function scanQrcode($openid,$unionid,$qrcode_id)
+    {
+        $qrcode=Qrcode::find($qrcode_id);
+        if(!$qrcode){
+            return '尊敬客户您好,感谢您使用【'.site_config("basic.sitename").'】公众号!';
+        }
+        //记录扫码
+        $scan=QrcodeScan::where(['openid'=>$openid,'qrcode_id'=>$qrcode->id])->find();
+        if(!$scan){
+            //生成的扫码记录表,可以在用户注册时,查询该表从而绑定推荐人
+            QrcodeScan::create([
+                'openid'=>$openid,
+                'unionid'=>$unionid,
+                'qrcode_id'=>$qrcode->id,
+                'foreign_key'=>$qrcode->foreign_key,
+                'type'=>$qrcode->type,
+            ]);
+        }
+        //根据业务场景返回不同的消息
+        switch ($qrcode->type){
+            case 'backend-login':
+                $third=Third::where(['platform'=>Third::PLATFORM('微信公众号'),'openid'=>$openid])->find();
+                if(!$third){
+                    return '您的微信没有绑定管理员,登陆失败!';
+                }
+                $admin=Admin::where(['third_id'=>$third->id])->find();
+                if(!$admin){
+                    return '您的微信没有绑定管理员,登陆失败!';
+                }
+                if($admin->status=='hidden'){
+                    return '管理员已经被禁止,登陆失败!';
+                }
+                return '登陆成功!';
+            case 'bind-third-user':
+                $path=$this->request->domain()."/api/mpapp/connect?action=binduser";
+                $end="<a href=\"{$path}\">👉👉点击这里授权👈️👈️</a>";
+                return "您正在使用微信扫码授权获取您的微信头像、昵称\n\n{$end}";
+            case 'toker':
+                $user=User::find($qrcode->foreign_key);
+                return '尊敬客户您好,您的好友'.$user->nickname.'推荐您使用【'.site_config("basic.sitename").'】公众号!';
+        }
+    }
+}

+ 66 - 0
app/api/controller/User.php

@@ -0,0 +1,66 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\controller;
+
+
+use app\common\model\Qrcode;
+
+
+class User extends Api
+{
+
+
+    protected $allowFields = ['id', 'nickname', 'mobile', 'avatar', 'balance', 'score'];
+    private Adapter $adapter;
+
+    public function userinfo(bool $allinfo = false)
+    {
+        $user=$this->adapter->userinfo();
+        if(!$user){
+            return false;
+        }
+        if($allinfo){
+            return $user;
+        }else{
+            return array_intersect_key($user,array_flip($this->allowFields));
+        }
+    }
+
+    // public function userinfo()
+    // {
+    //     $user=$this->auth->userinfo();
+    //     $this->success('',$user);
+    // }
+
+ 
+ 
+
+    public function logout()
+    {
+        $this->adapter->logout();
+    }
+
+    public function getToken()
+    {
+        $usertoken=$this->adapter->getUserToken();
+        return $usertoken->token;
+    }
+
+    public function login(string $username, string $password)
+    {
+        $token=uuid();
+        $user=User::where('username',$username)->find();
+        if(!$user){
+            throw new \Exception('账号或密码错误');
+        }
+        if($user->password!=md5(md5($password.$user->salt))){
+            throw new \Exception('账号或密码错误');
+        }
+        if($user->status!='normal'){
+            throw new \Exception('账号已经被禁用');
+        }
+        $this->adapter->login($token,$user);
+        $this->login_user=$this->adapter->userinfo();
+    }
+}

+ 6 - 0
app/api/middleware.php

@@ -0,0 +1,6 @@
+<?php
+// 这是系统自动生成的middleware定义文件
+return [
+    //跨域请求
+    app\api\middleware\AllowCrossDomain::class,
+];

+ 14 - 0
app/api/middleware/AllowCrossDomain.php

@@ -0,0 +1,14 @@
+<?php
+declare(strict_types=1);
+namespace app\api\middleware;
+
+class AllowCrossDomain{
+    public function handle($request, \Closure $next)
+    {
+        header('Access-Control-Allow-Credentials: true');
+        header('Access-Control-Allow-Origin: *');
+        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Token");
+        header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH');
+        return $next($request);
+    }
+}

+ 70 - 0
app/api/service/ApiAuthService.php

@@ -0,0 +1,70 @@
+<?php
+declare(strict_types=1);
+namespace app\api\service;
+
+use app\api\service\auth\Adapter;
+
+use app\common\model\User;
+use app\common\model\UserToken;
+use app\common\service\AuthService;
+
+
+class ApiAuthService extends AuthService
+{
+    protected $allowFields = ['id', 'nickname', 'mobile', 'avatar', 'balance', 'score'];
+    private Adapter $adapter;
+
+    public function userinfo(bool $allinfo = false)
+    {
+        $user=$this->adapter->userinfo();
+        if(!$user){
+            return false;
+        }
+        if($allinfo){
+            return $user;
+        }else{
+            return array_intersect_key($user,array_flip($this->allowFields));
+        }
+    }
+
+    public function logout()
+    {
+        $this->adapter->logout();
+    }
+
+    public function getToken()
+    {
+        $usertoken=$this->adapter->getUserToken();
+        return $usertoken->token;
+    }
+
+    public function login(string $username, string $password)
+    {
+        $token=uuid();
+        $user=User::where('username',$username)->find();
+        if(!$user){
+            throw new \Exception('账号或密码错误');
+        }
+        if($user->password!=md5(md5($password.$user->salt))){
+            throw new \Exception('账号或密码错误');
+        }
+        if($user->status!='normal'){
+            throw new \Exception('账号已经被禁用');
+        }
+        $this->adapter->login($token,$user);
+        $this->login_user=$this->adapter->userinfo();
+    }
+
+    public function loginByMobile(string $mobile, string $code)
+    {
+        // TODO: Implement loginByMobile() method.
+    }
+
+
+    public function updateToken(array $arr)
+    {
+        $usertoken=$this->adapter->getUserToken();
+        UserToken::where('id',$usertoken->id)->update($arr);
+    }
+
+}

+ 25 - 0
app/api/service/auth/Adapter.php

@@ -0,0 +1,25 @@
+<?php
+declare(strict_types=1);
+namespace app\api\service\auth;
+use app\common\model\User;
+use app\common\model\UserToken;
+
+interface Adapter{
+    /**
+     * 获取用户信息
+     */
+    public function userinfo():array|bool;
+
+    /**
+     * 获取用户token
+     */
+    public function getUserToken():UserToken|false;
+    /**
+     * 退出登录
+     */
+    public function logout();
+    /**
+     * 登录
+     */
+    public function login(string $token,User $user);
+}

+ 77 - 0
app/api/service/auth/MysqlAdapter.php

@@ -0,0 +1,77 @@
+<?php
+declare(strict_types=1);
+namespace app\api\service\auth;
+
+
+use app\common\model\UserToken;
+use app\common\model\User;
+use think\facade\Config;
+
+class MysqlAdapter implements Adapter
+{
+    private UserToken $usertoken;
+
+    public function __construct(string $token=null)
+    {
+        if(!$token){
+            return;
+        }
+        $time=time();
+        $usertoken=UserToken::where(function ($query) use ($token,$time){
+            $token=md5($token);
+            $query->where('token','=',$token);
+            $query->where('expire','>',$time);
+        })->withJoin('user','right')->find();
+        if($usertoken){
+            $auth=Config::get('site.auth');
+            //当登陆时间小于保持登陆时间的一半时,自动续时
+            if($auth['keepalive'] && $usertoken->expire-$time<$auth['keepalive_time']/2){
+                $usertoken->expire=$time+$auth['keepalive_time'];
+                $usertoken->save();
+            }
+            $usertoken->token=$token;
+            $this->usertoken=$usertoken;
+        }
+    }
+
+    public function userinfo():array|false
+    {
+        if(isset($this->usertoken)){
+            return $this->usertoken->user->toArray();
+        }
+        return false;
+    }
+
+    public function getUserToken():UserToken|false
+    {
+        if(isset($this->usertoken)){
+            return $this->usertoken;
+        }
+        return false;
+    }
+
+    public function login(string $token,User $user)
+    {
+        $keepalive_time=Config::get('site.auth.keepalive_time');
+        $this->usertoken=UserToken::create([
+            'token'=>md5($token),
+            'user_id'=>$user->id,
+            'expire'=>time()+$keepalive_time
+        ]);
+        $this->usertoken->token=$token;
+        $this->usertoken->user=$user;
+        $allow_device_num=Config::get('site.auth.allow_device_num');
+        //如果数据库中保存的设备数大于允许的设备数,如果超出则挤出去最早登陆的设备
+        $time=time();
+        $count=UserToken::where('user_id',$user->id)->where('expire','>',$time)->count();
+        if($count>$allow_device_num){
+            $usertoken=UserToken::where('user_id',$user->id)->where('expire','>',$time)->order('id','asc')->find();
+            $usertoken->delete();
+        }
+    }
+
+    public function logout()
+    {
+        UserToken::where('token',$this->usertoken->token)->delete();
+    }
+}

+ 68 - 0
app/api/service/msg/WechatMsg.php

@@ -0,0 +1,68 @@
+<?php
+declare(strict_types=1);
+namespace app\api\service\msg;
+
+use app\common\model\MpSubscribe;
+use app\common\model\Third;
+use app\common\service\MsgService;
+use app\common\model\Msg;
+
+class WechatMsg extends MsgService{
+
+    protected $msg_type='wechat';
+
+    //模板列表
+    const 模拟模板='111111111111111111111111111111111111';
+
+    protected function sendEvent(Msg $msg): bool
+    {
+        $config=[
+            'appid'=>site_config("weichat.mp_appid"),
+            'appsecret'=>site_config("weichat.mp_secret"),
+        ];
+        // 实例接口
+        $wechat = new \WeChat\Template($config);
+        // 执行操作
+        try{
+            $wechat->send(json_decode($msg->content,true));
+            return true;
+        }catch (\Exception $e){
+            $this->error=$e->getMessage();
+            return false;
+        }
+    }
+
+
+    public static function testMsg($user_id)
+    {
+        $openid=self::getUserMpOpenid($user_id);
+        if(!$openid){
+            return;
+        }
+        $postdata=[
+            'touser'=>$openid,
+            'template_id'=>self::模拟模板,
+            //跳转到h5首页
+            //'url'=>request()->domain().'/h5/#/pages/index/index',
+            //跳转到小程序
+            'miniprogram'=>[
+                'appid'=>site_config("uniapp.miniapp_id"),
+                'pagepath'=>'/pages/index/index',
+            ],
+            'data'=>[
+                'thing1'=>['value'=>'测试1'],
+                'thing2'=>['value'=>'测试2'],
+            ]
+        ];
+        $postdata=json_encode($postdata,JSON_UNESCAPED_UNICODE);
+        $service=self::newInstance();
+        $service->create($postdata,$user_id);
+    }
+
+    private static function getUserMpOpenid($user_id)
+    {
+        $unionid=Third::where(['user_id'=>$user_id])->value('unionid');
+        $openid=MpSubscribe::where(['unionid'=>$unionid])->value('openid');
+        return $openid;
+    }
+}

+ 1 - 1
app/common/service/AuthService.php

@@ -36,7 +36,7 @@ abstract class AuthService extends BaseService
      * @param string $openid
      * @return mixed
      */
-    abstract public function loginByThirdPlatform(string $platform,Third $third);
+    //abstract public function loginByThirdPlatform(string $platform,Third $third);
     /**
      * 获取用户信息
      * @return array

+ 12 - 0
route/route.php

@@ -0,0 +1,12 @@
+<?php
+use think\facade\Route;
+
+
+
+//员工端
+Route::group('/user/api', function () {
+
+      //News/update
+      Route::get('hello', 'Index@hello');
+      //->controller('api/Index','hello');
+})->namespace('app\api\controller');

+ 241 - 0
runtime/admin/log/202506/24.log

@@ -3551,3 +3551,244 @@ Stack trace:
 [2025-06-24T19:53:32+08:00][info] 管理员访问-ID:1,昵称:超级管理员
 [2025-06-24T19:53:32+08:00][info] 请求完成,耗时:0.43371秒
 
+[2025-06-24T19:58:32+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T19:58:32+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T19:58:32+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T19:58:32+08:00][info] 请求完成,耗时:0.41424秒
+
+[2025-06-24T20:01:59+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:01:59+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:01:59+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:01:59+08:00][info] 请求完成,耗时:0.42261秒
+
+[2025-06-24T20:02:04+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:04+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:04+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:04+08:00][info] 请求完成,耗时:0.44456秒
+
+[2025-06-24T20:02:09+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:09+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:09+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:09+08:00][info] 请求完成,耗时:0.44058秒
+
+[2025-06-24T20:02:12+08:00][info] Url:/Ying/shop/customer/index Method:JSON
+[2025-06-24T20:02:12+08:00][info] ----------admin----------shop.Customer----------index----------
+[2025-06-24T20:02:12+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:12+08:00][info] 请求完成,耗时:0.51429秒
+
+[2025-06-24T20:02:14+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:14+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:14+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:14+08:00][info] 请求完成,耗时:0.46467秒
+
+[2025-06-24T20:02:19+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:19+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:19+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:19+08:00][info] 请求完成,耗时:0.46996秒
+
+[2025-06-24T20:02:24+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:24+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:24+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:24+08:00][info] 请求完成,耗时:0.46892秒
+
+[2025-06-24T20:02:29+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:29+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:29+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:29+08:00][info] 请求完成,耗时:0.44275秒
+
+[2025-06-24T20:02:34+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:34+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:34+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:34+08:00][info] 请求完成,耗时:0.42583秒
+
+[2025-06-24T20:02:39+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:39+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:39+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:39+08:00][info] 请求完成,耗时:0.412秒
+
+[2025-06-24T20:02:44+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:44+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:44+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:44+08:00][info] 请求完成,耗时:0.42921秒
+
+[2025-06-24T20:02:49+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:49+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:49+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:49+08:00][info] 请求完成,耗时:0.45195秒
+
+[2025-06-24T20:02:54+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:54+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:54+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:54+08:00][info] 请求完成,耗时:0.46029秒
+
+[2025-06-24T20:02:59+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:02:59+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:02:59+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:02:59+08:00][info] 请求完成,耗时:0.45152秒
+
+[2025-06-24T20:03:01+08:00][info] 请求完成,耗时:1750766581.2878秒
+
+[2025-06-24T20:03:04+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:04+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:04+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:04+08:00][info] 请求完成,耗时:0.44811秒
+
+[2025-06-24T20:03:09+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:09+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:09+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:09+08:00][info] 请求完成,耗时:0.44763秒
+
+[2025-06-24T20:03:14+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:14+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:14+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:14+08:00][info] 请求完成,耗时:0.39579秒
+
+[2025-06-24T20:03:19+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:19+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:19+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:19+08:00][info] 请求完成,耗时:0.47136秒
+
+[2025-06-24T20:03:24+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:24+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:24+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:24+08:00][info] 请求完成,耗时:0.45983秒
+
+[2025-06-24T20:03:29+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:29+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:29+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:29+08:00][info] 请求完成,耗时:0.4287秒
+
+[2025-06-24T20:03:34+08:00][info] 请求完成,耗时:1750766614.4189秒
+
+[2025-06-24T20:03:34+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:34+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:34+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:34+08:00][info] 请求完成,耗时:0.46421秒
+
+[2025-06-24T20:03:39+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:39+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:39+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:39+08:00][info] 请求完成,耗时:0.45104秒
+
+[2025-06-24T20:03:44+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:44+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:44+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:44+08:00][info] 请求完成,耗时:0.47521秒
+
+[2025-06-24T20:03:49+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:49+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:49+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:49+08:00][info] 请求完成,耗时:0.44649秒
+
+[2025-06-24T20:03:54+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:54+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:54+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:54+08:00][info] 请求完成,耗时:0.40512秒
+
+[2025-06-24T20:03:59+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:03:59+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:03:59+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:03:59+08:00][info] 请求完成,耗时:0.48285秒
+
+[2025-06-24T20:04:04+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:04:04+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:04:04+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:04:04+08:00][info] 请求完成,耗时:0.45858秒
+
+[2025-06-24T20:04:09+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:04:09+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:04:09+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:04:09+08:00][info] 请求完成,耗时:0.42152秒
+
+[2025-06-24T20:04:14+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:04:14+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:04:14+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:04:14+08:00][info] 请求完成,耗时:0.41608秒
+
+[2025-06-24T20:04:19+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:04:19+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:04:19+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:04:19+08:00][info] 请求完成,耗时:0.44195秒
+
+[2025-06-24T20:04:24+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:04:24+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:04:24+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:04:24+08:00][info] 请求完成,耗时:0.45162秒
+
+[2025-06-24T20:04:29+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:04:29+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:04:29+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:04:29+08:00][info] 请求完成,耗时:0.45274秒
+
+[2025-06-24T20:05:01+08:00][info] 请求完成,耗时:1750766701.5014秒
+
+[2025-06-24T20:06:32+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:06:32+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:06:32+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:06:32+08:00][info] 请求完成,耗时:0.42425秒
+
+[2025-06-24T20:08:46+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:08:46+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:08:46+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:08:46+08:00][info] 请求完成,耗时:0.40759秒
+
+[2025-06-24T20:08:51+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:08:51+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:08:51+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:08:51+08:00][info] 请求完成,耗时:0.38159秒
+
+[2025-06-24T20:08:56+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:08:56+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:08:56+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:08:56+08:00][info] 请求完成,耗时:0.47296秒
+
+[2025-06-24T20:09:01+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:09:01+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:09:01+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:09:01+08:00][info] 请求完成,耗时:0.43013秒
+
+[2025-06-24T20:09:06+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:09:06+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:09:06+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:09:06+08:00][info] 请求完成,耗时:0.44236秒
+
+[2025-06-24T20:09:11+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:09:11+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:09:11+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:09:11+08:00][info] 请求完成,耗时:0.44578秒
+
+[2025-06-24T20:09:16+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:09:16+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:09:16+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:09:16+08:00][info] 请求完成,耗时:0.44072秒
+
+[2025-06-24T20:09:21+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:09:21+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:09:21+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:09:21+08:00][info] 请求完成,耗时:0.46658秒
+
+[2025-06-24T20:09:26+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:09:26+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:09:26+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:09:26+08:00][info] 请求完成,耗时:0.39637秒
+
+[2025-06-24T20:09:31+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:09:31+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:09:31+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:09:31+08:00][info] 请求完成,耗时:0.43789秒
+
+[2025-06-24T20:09:36+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:09:36+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:09:36+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:09:36+08:00][info] 请求完成,耗时:0.46317秒
+
+[2025-06-24T20:09:41+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:09:41+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:09:41+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:09:41+08:00][info] 请求完成,耗时:0.45736秒
+
+[2025-06-24T20:10:32+08:00][info] Url:/Ying/develop/queueLog?type=content&page=1 Method:GET
+[2025-06-24T20:10:32+08:00][info] ----------admin----------Develop----------queueLog----------
+[2025-06-24T20:10:32+08:00][info] 管理员访问-ID:1,昵称:超级管理员
+[2025-06-24T20:10:32+08:00][info] 请求完成,耗时:0.15348秒
+

+ 2 - 0
runtime/log/202506/24.log

@@ -19,3 +19,5 @@
 
 [2025-06-24T14:08:02+08:00][info] 请求完成,耗时:1750745282.1332秒
 
+[2025-06-24T20:08:41+08:00][info] 请求完成,耗时:1750766921.672秒
+