token

token案例:

案例:

网站:http://shop.duoceshi.com/login?redirect=%2Fdashboard

code接口:http://manage.duoceshi.com/auth/code

登录接口:http://manage.duoceshi.com/auth/login

登录接口参数:{"username":"admin","password":"e6WGOz+g/FuR646O7IF8JrlC6qH/anCI9/0UCsVDnUxN2aBdGKtRffNb1W7i87dRavZCNyP9yqvAcXLgdKtsRA==","code":"8888","uuid":"{{uuid}}"}

链接类型:Content-Type:application/json

搜索商品接口:http://manage.duoceshi.com/api/yxStoreCategory?page=0\&size=10\&sort=sort%2Cdesc

Authorization:

Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTY4MDE0OTgwNX0.fmlEdR5Xh1BF2al6crfPMjG8dd-M6TOKux3wni5ejvGFLce4Zk0tvKsCobj7WEaXvXI-N-21AIj2HH5LFlFMNw

一、postman工具实现

第一个接口:

code接口:http://manage.duoceshi.com/auth/code

test中的语句:

//需要拿到uuid接口返回值里面的uuid作为下一个接口请求头里面的入参

// 1.通过JSON.parse函数把responseBody响应体进行格式化为json字符串

var jsonData = JSON.parse(responseBody);

// 2.通过json字符串里面的uuid这个键拿到对应的uuid值

postman.setEnvironmentVariable("uuid",jsonData.uuid);

第二个接口:

登录接口:http://manage.duoceshi.com/auth/login

body参数:

{"username":"admin","password":"e6WGOz+g/FuR646O7IF8JrlC6qH/anCI9/0UCsVDnUxN2aBdGKtRffNb1W7i87dRavZCNyP9yqvAcXLgdKtsRA==","code":"8888","uuid":"{{uuid}}"}

test语句:

//需要拿到登录接口返回值里面的token作为下个接口请求头里面的入参

// 1.通过JSON.parse函数把response响应体进行格式化为json字符串

var jsonData = JSON.parse(responseBody);

// 2.通过json字符串里面的token这个键拿到对应的token值设为环境变量

postman.setEnvironmentVariable("token", jsonData.token);

第三个接口:

搜索接口:

http://manage.duoceshi.com/api/yxStoreCategory?page=0\&size=10\&sort=sort%2Cdesc

==========================================================

python 获取tonken

复制代码
import  requests
def uid():
    url="http://manage.duoceshi.com/auth/code"
    h={"Content-Type":"application/json"}
    r=requests.get(url=url,headers=h)
    print(r.text)  #返回参数
    u=r.json()["uuid"]
    print(u)
    return r.json()['uuid'] #在返回参数中提取
def login():
    url1="http://manage.duoceshi.com/auth/login"
    h1 = {"Content-Type": "application/json"}
    data1={"username":"admin",
           "password":"AL2HPFkHICFLSF7Nh0HBWqKf2XbZh9aBqM01ygQmQl61eLZVjxjXVp3/KtTwUzGiTHIhBXmdEExVzD4RoIYdhA==",
           "code":"8888",
           "uuid":uid() #引用上一个接口
           }
    r1=requests.post(url=url1,json=data1,headers=h1)  #备注data数据要json格式,才能查看到返回数据
    print(r1.text)
    print(r1.json())
    t=r1.json()["token"]
    print(t)
    return  r1.json()['token']  #在返回体中提取token
def bid():
    url2="http://manage.duoceshi.com/api/menus/build"
    h2={"Authorization":login()}
    r2=requests.get(url=url2,headers=h2)
    print(r2.json())
if __name__ == '__main__':
    # uid()
    # login()
    bid()

第二种方法:

|-------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import re import requests class tonken(): ``def __init__(``self``): ``pass ``def uid(``self``): ``url``=``"http://manage.duoceshi.com/auth/code" ``h``=``{``"Content-Type"``:``"application/json"``} ``r``=``requests.get(url``=``url,headers``=``h) ``# print(r.text) #返回参数 ``wb``=``r.text ``s``=``re.findall(``'"uuid":"(.+?)"'``,wb) ``print``(s) ``dict1 ``= {} ``dict1[``'uuid'``] ``= s[``0``] ``for i,j ``in dict1.items(): ``print``(j) ``return j ``def login(``self``): ``c``=``self``.uid() ``url1``=``"http://manage.duoceshi.com/auth/login" ``h1 ``= {``"Content-Type"``: ``"application/json"``} ``data1``=``{``"username"``:``"admin"``, ``"password"``:``"AL2HPFkHICFLSF7Nh0HBWqKf2XbZh9aBqM01ygQmQl61eLZVjxjXVp3/KtTwUzGiTHIhBXmdEExVzD4RoIYdhA=="``, ``"code"``:``"8888"``, ``"uuid"``:c``#引用上一个接口 ``} ``r1``=``requests.post(url``=``url1,json``=``data1,headers``=``h1) ``#备注data数据要json格式,才能查看到返回数据 ``print``(r1.text) ``wb1``=``r1.text ``s ``= re.findall(``'"token":"(.+?)"'``, wb1) ``print``(s) ``dict2 ``= {} ``dict2[``'uuid'``] ``= s[``0``] ``for i, j ``in dict2.items(): ``print``(j) ``return j ``def build(``self``): ``url2``=``"http://manage.duoceshi.com/api/menus/build" ``h2``=``{``"Authorization"``:``self``.login()} ``r2``=``requests.get(url``=``url2,headers``=``h2) ``print``(r2.json()) if __name__ ``=``= '__main__'``: ``dx``=``tonken() ``# dx.uid() ``# dx.login() ``dx.build() |

第三种方法

|----------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import re import requests class tonken(): ``def __init__(``self``): ``pass ``def uid(``self``): ``url``=``"http://manage.duoceshi.com/auth/code" ``h``=``{``"Content-Type"``:``"application/json"``} ``r``=``requests.get(url``=``url,headers``=``h) ``# print(r.text) #返回参数 ``wb``=``r.text ``s``=``re.findall(``'"uuid":"(.+?)"'``,wb) ``print``(s) ``m``=``" "``.join(s) ``print``(m) ``#code-keyd6f4494345ba49679d80592465f13305 ``return m ``def login(``self``): ``c``=``self``.uid() ``url1``=``"http://manage.duoceshi.com/auth/login" ``h1 ``= {``"Content-Type"``: ``"application/json"``} ``data1``=``{``"username"``:``"admin"``, ``"password"``:``"AL2HPFkHICFLSF7Nh0HBWqKf2XbZh9aBqM01ygQmQl61eLZVjxjXVp3/KtTwUzGiTHIhBXmdEExVzD4RoIYdhA=="``, ``"code"``:``"8888"``, ``"uuid"``:``self``.uid()``#引用上一个接口 ``} ``r1``=``requests.post(url``=``url1,json``=``data1,headers``=``h1) ``#备注data数据要json格式,才能查看到返回数据 ``print``(r1.text) ``wb1``=``r1.text ``s ``= re.findall(``'"token":"(.+?)"'``, wb1) ``print``(s) ``n``=``''.join(s) ``print``(n) ``def build(``self``): ``url2``=``"http://manage.duoceshi.com/api/menus/build" ``h2``=``{``"Authorization"``:``self``.login()} ``r2``=``requests.get(url``=``url2,headers``=``h2) ``print``(r2.json()) if __name__ ``=``= '__main__'``: ``dx``=``tonken() ``# dx.uid() ``# dx.login() ``dx.build() |

复制代码
==========================================================
jmeter中tonken
复制代码
第一个接口:GET http://manage.duoceshi.com/auth/code
第二个接口:POST http://manage.duoceshi.com/auth/login

{"username":"admin","password":"ogqJt/paTDJCulj4u06yrGhkwH7XwiNe0Ce6ToKxUaPRjASkd+RHIp8knCihuLpsL5I+5p7NCp7mClZ04U9vog==","code":"8888","uuid":"code-key1867ef6878954530a3b5ce2a3b8ead00"}

复制代码
第三个接口:GET http://manage.duoceshi.com/api/menus/build

第一种方法步骤:
复制代码
第一个接口:GET http://manage.duoceshi.com/auth/code

提取:

复制代码
第二个接口:POST http://manage.duoceshi.com/auth/login
用户参数:
复制代码
{"username":"admin","password":"ogqJt/paTDJCulj4u06yrGhkwH7XwiNe0Ce6ToKxUaPRjASkd+RHIp8knCihuLpsL5I+5p7NCp7mClZ04U9vog==","code":"8888","uuid":"code-key1867ef6878954530a3b5ce2a3b8ead00"}
复制代码
token值提取:

第三个接口:

GET http://manage.duoceshi.com/api/menus/build

第二种方法:

通过JSON Extractor 方法

第一个接口:GET http://manage.duoceshi.com/auth/code

在设置uiid变量

第二个接口:

POST http://manage.duoceshi.com/auth/login

POST data:

{"username":"admin","password":"ogqJt/paTDJCulj4u06yrGhkwH7XwiNe0Ce6ToKxUaPRjASkd+RHIp8knCihuLpsL5I+5p7NCp7mClZ04U9vog==","code":"8888","uuid":"code-keyc156c7a4911e464790e2998ce068240f"}

设置提取方法

请求头中设置了变量

第三个接口:

GET http://manage.duoceshi.com/api/menus/build

相关推荐
serve the people1 小时前
解决osx-arm64平台上conda默认源没有提供 python=3.7 的官方编译版本的问题
开发语言·python·conda
柒七爱吃麻辣烫1 小时前
在Linux中安装JDK并且搭建Java环境
java·linux·开发语言
极小狐2 小时前
如何构建容器镜像并将其推送到极狐GitLab容器镜像库?
开发语言·数据库·机器学习·gitlab·ruby
多多*2 小时前
Java反射 八股版
java·开发语言·hive·python·sql·log4j·mybatis
正在走向自律2 小时前
从0到1:Python机器学习实战全攻略(8/10)
开发语言·python·机器学习
FY_20183 小时前
键盘输出希腊字符方法
开发语言
西西弗Sisyphus3 小时前
Python 处理图像并生成 JSONL 元数据文件 - 灵活text版本
开发语言·python
q567315233 小时前
Go语言多线程爬虫与代理IP反爬
开发语言·爬虫·tcp/ip·golang
Chandler243 小时前
Go语言即时通讯系统 开发日志day1
开发语言·后端·golang
强化学习与机器人控制仿真4 小时前
openpi 入门教程
开发语言·人工智能·python·深度学习·神经网络·机器人·自动驾驶