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

相关推荐
软件黑马王子1 小时前
C#初级教程(4)——流程控制:从基础到实践
开发语言·c#
闲猫1 小时前
go orm GORM
开发语言·后端·golang
李白同学3 小时前
【C语言】结构体内存对齐问题
c语言·开发语言
黑子哥呢?4 小时前
安装Bash completion解决tab不能补全问题
开发语言·bash
青龙小码农4 小时前
yum报错:bash: /usr/bin/yum: /usr/bin/python: 坏的解释器:没有那个文件或目录
开发语言·python·bash·liunx
大数据追光猿4 小时前
Python应用算法之贪心算法理解和实践
大数据·开发语言·人工智能·python·深度学习·算法·贪心算法
彳卸风5 小时前
Unable to parse timestamp value: “20250220135445“, expected format is
开发语言
dorabighead5 小时前
JavaScript 高级程序设计 读书笔记(第三章)
开发语言·javascript·ecmascript
风与沙的较量丶6 小时前
Java中的局部变量和成员变量在内存中的位置
java·开发语言
水煮庄周鱼鱼6 小时前
C# 入门简介
开发语言·c#