0
点赞
收藏
分享

微信扫一扫

fastAdmin api方法解析

准备工作:

1.fastAdmin伪静态设置

参考:ThinkPHP URL重写: https://www.kancloud.cn/manual/thinkphp5/177576

Nginx:/conf/vhosts/hostname.conf

2.FeHelper插件安装

参考:Web开发者助手 FeHelper:https://www.baidufe.com/fehelper/index/index.html


一、api方法解析

1.api/controller/Demo.php中,可以使用基类中的接口方法,来获取想要的参数或数据:

    public function test2()
    {
        // $this->success('返回成功', ['action' => 'test2']);
        // $this->success('返回成功', $this->auth->id);
        // $this->success('返回成功', $this->auth->islogin());
        // $this->success('返回成功', $this->auth->getUser());
        // $this->success('返回成功', $this->auth->getToken());
        // $this->success('返回成功', $this->auth->getUserinfo());
        $this->success('返回成功', $this->auth->getRequestUri());
    }

基类:

common/controller/API.php

common/library/Auth.php

更多接口方法,可以在基类中查找。


二、api自动注册登录

1.引入DB类

use think\Db;

2.测试小程序用户自动注册

在数据表user中新增小程序openid字段。

public function test1()
    {
        $openid = "id12345";
        $username = "name123456";

        $search_res = Db::name("user")->whereOr("username", $username)->whereOr("openid", $openid)->find();
        $this->success('返回成功', $search_res);
    }

三、api注册后自动退出


四、api登录后token使用方法和简单分析


举报

相关推荐

0 条评论