thinkphp5开发restful-api接口学习 教程视频 接口文档

1. 获取验证码

get api.tp5.com/code

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
username string 必需 手机号或者邮箱
is_exist int 必需 用户名是否应该存在(1:是 0:否)
{
    "code": 200,
    "msg": "手机验证码已经发送成功, 每天可以发送5次, 请在一分钟内验证!",
    "data": []
}

2. 用户注册

post api.tp5.com/user/register

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
user_name string 必需 手机号或者邮箱
user_pwd string 必需 md5加密的用户密码
code int 必需 用户收到的验证码
{
    "code": 200,
    "msg": "注册成功!",
    "data": []
}

3. 用户登录

post api.tp5.com/user/login

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
user_name string 必需 手机号或者邮箱
user_pwd string 必需 md5加密的用户密码
{
    "code": 200,
    "msg": "登录成功!",
    "data": {
        'user_id':1, // 用户id
        'user_phone':'15639279530', // 用户手机号
        'user_name':'', // 用户昵称
        'user_email':'', // 用户邮箱
        'user_rtime':1501414343 // 用户注册时间
    }
}

4. 用户上传头像

post api.tp5.com/user/icon

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
user_id int 必需 用户id
user_icon file 必需 用户头像(默认 200*200)
{
    "code": 200,
    "msg": "上传头像成功!",
    "data": "/uploads/20170801/71225b61d9ae892db2dc99dac9eee752.jpg"
}

5. 用户修改密码

post api.tp5.com/user/change_pwd

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
user_name string 必需 用户名(手机/邮箱)
user_ini_pwd string 必需 用户的老密码
user_pwd string 必需 用户的新密码
{
    "code": 200,
    "msg": "密码修改成功!",
    "data": []
}

6. 用户找回密码

post api.tp5.com/user/find_pwd

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
user_name string 必需 用户名(手机/邮箱)
code string 必需 验证码
user_pwd string 必需 用户的新密码
{
    "code": 200,
    "msg": "密码修改成功!",
    "data": []
}

7. 用户绑定手机号

post api.tp5.com/user/bind_phone

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
user_id int 必需 用户id
code string 必需 验证码
phone string 必需 用户的手机号
{
    "code": 200,
    "msg": "手机号绑定成功!",
    "data": []
}

8. 用户绑定邮箱

post api.tp5.com/user/bind_email

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
user_id int 必需 用户id
code string 必需 验证码
email string 必需 用户的邮箱
{
    "code": 200,
    "msg": "邮箱绑定成功!",
    "data": []
}

9. 用户绑定用户名(手机/邮箱)

post api.tp5.com/user/bind_email

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
user_id int 必需 用户id
code string 必需 验证码
user_name string 必需 用户的邮箱
{
    "code": 200,
    "msg": "邮箱绑定成功!",
    "data": []
}

10. 用户设定昵称

post api.tp5.com/user/nickname

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
user_id int 必需 用户id
user_nickname string 必需 用户昵称
{
    "code": 200,
    "msg": "昵称修改成功!",
    "data": []
}

11. 新增文章

post api.tp5.com/article

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
article_uid int 必需 文章用户id
article_title string 必需 文章标题
{
    "code": 200,
    "msg": "新增文章成功!",
    "data": "3" // 文章id
}

12. 查看文章列表

get api.tp5.com/articles

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
user_id int 必需 用户id
num int 非必须 10 每页个数
page int 非必须 1 页码
{
    "code": 200,
    "msg": "查询成功!",
    "data": {
        "articles": [
            {
                "article_id": 20, // 文章id
                "article_ctime": 1501756190, // 文章创建时间
                "article_title": "test_title", // 文章标题
                "user_name": "red_panda" // 文章作者昵称(user_nickname)
            },
            {
                "article_id": 21, // 文章id
                "article_ctime": 1501758668, // 文章创建时间
                "article_title": "<script>test_title</script>", // 文章标题
                "user_name": "red_panda" // 文章作者昵称(user_nickname)
            }
        ],
        "page_num": 3 // 文章列表总页数(根据每页条数实时计算)
    }
}

13. 查看单个文章信息

get api.tp5.com/article

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
article_id int 必需 文章id
{
    "code": 200,
    "msg": "获取成功!",
    "data": {
        "article_id": 1,  // 文章id
        "article_title": "test_title", // 文章标题
        "article_ctime": 1501756084, // 文章创建时间
        "article_content": "<script>alert('fuck');</script>", // 文章内容
        "user_name": "red_panda" // 文章作者昵称(user_nickname)
    }
}

14. 修改/保存文章

put api.tp5.com/article

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
article_id int 必需 文章id
{
    "code": 200,
    "msg": "文章更新成功!",
    "data": []
}

15. 删除文章

delete api.tp5.com/article

参数 类型 必需/可选 默认 描述
time int 必需 时间戳(用于判断请求是否超时)
token string 必需 确定来访者身份
article_id int 必需 文章id
{
    "code": 200,
    "msg": "文章删除成功!",
    "data": []
}
[Haima的博客] http://www.cnblogs.com/haima/
原文地址:https://www.cnblogs.com/haima/p/9539971.html