1 Star 2 Fork 1

叶颖男/python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
zhifu.py 5.85 KB
一键复制 编辑 原始数据 按行查看 历史
叶颖男 提交于 2022-02-26 13:42 . 更新博客
import json
import random
from locust import HttpUser, TaskSet, task, SequentialTaskSet, constant
import uuid
class UserTasks(HttpUser):
wait_time = constant(1)
#执行时最先开始运行on_start方法
def on_start(self):
self.header = {"Content-Type": "application/json", "store-id": "34f05584-7610-421a-a366-b67df6000471","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJHVUVTVCJdLCJhZG1pbl9pZCI6IjlkY2Q5ZmI4LTA1MGItNGIzOS1hNWNmLTk0NDQxYzkyNzU3NiIsImFkbWluX3JvbGVzIjpbIkFETUlOOlNVUEVSQURNSU4iXSwiaXNzIjoibGF6eXNob3A6cGVybWlzc2lvbiIsImN1c3RvbWVyX2lkIjoiZThmMDM4OTAtNmVlMC00NzlhLWI1MTItMTVlOWY0NGVhODkwIiwiZXhwIjoxNjcwMTI1Mjg5LCJpYXQiOjE2Mzg1ODkxNjksInNvdXJjZV9pcCI6IjQyLjE4NC41LjExMCJ9.R1NDNpXkjUBLEY-hRylvku5KdLYReLUcOIPWvxxm2Xc","cookie":""}
# 列出需要测试的任务形式一
#根据店铺ID获得支付方式
# @task(1)
def redius(self):
url = '/payment/method/descriptors'
par = {"countryCode":"CN"}
with self.client.get(url, headers=self.header,catch_response=True,params=par) as res:
if res.status_code == 200 and res.text.find("SUCCESS") > -1:
resdata = res.json()
self.ids = resdata["data"]["paymentMethods"]["paymentMethods"][0]["id"]
self.createPaymentTransactionType = resdata["data"]["paymentMethods"]["paymentMethods"][0]["createPaymentTransactionType"]
self.idss = resdata["data"]["paymentMethods"]["paymentMethods"][1]["id"]
self.idsss = resdata["data"]["paymentMethods"]["paymentMethods"][2]["id"]
#发起cod支付
# @task(1)
def checkout(self):
self.redius()
url = '/payment'
body = {
"amount": "666",
"createPaymentTransactionType": self.createPaymentTransactionType,
"currency": "USD",
"merchantTransactionId":"{}".format(uuid.uuid1()),
"paymentMethodId": self.ids
}
with self.client.post(url, catch_response=True, headers=self.header,data=json.dumps(body)) as res:
if res.status_code == 200 and res.text.find("SUCCESS") > -1:
#res.json 是帮你把json字符串转为了字典,res.text 是原始的json字符串
resdata = res.json()
print(resdata)
else:
res.failure("失败")
print("失败")
#发起wordpay支付
#@task(1)
def wordpay(self):
self.redius()
url = '/payment'
body = {
"amount": 5.99,
"currency": "USD",
"encryptedData":"eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMjU2R0NNIiwia2lkIjoiMSIsImNvbS53b3JsZHBheS5hcGlWZXJzaW9uIjoiMS4wIiwiY29tLndvcmxkcGF5LmxpYlZlcnNpb24iOiIxLjAuMiIsImNvbS53b3JsZHBheS5jaGFubmVsIjoiamF2YXNjcmlwdCJ9.LTp0wyeegyv4WFyqB4qeT5TbwuS90NQy-J8ubWtVBguHcnhXoiO_BWUfkpU75b19KedNvnXppwdwsAHNgydrZUtTQ4Oi9N1cXeUu0Uc_buluTAuFFWRTS07WOSYydORzxZFQqD80jrwNQJtPDsTQ42kW4ANLREaaKOb_hHPPmdsVuRPgsEUuXiJui4a9yAiCCOJ1uTRopYb3CU543KR3H3u0lGlt8l9PTGdvsob8FJ396hF3_BPtSxVRUzTrE2hwv0W5xjzv694o0EXTaOMg94DagfOLv_UHwaSBi7KjYwMW_YJ_G36gc7xUL-3qV0CDxy96XbMaoPxZAC4ZYCsfeA.-5NGbqUWDle21MYQ.lTiBgWM6zG0IQVoPpW8zdPQyFP7LQ5umGXACYkKO6QQo1HzU2dq-QEI1Tn2_bzqo8tUNMhGo7QsBHk9YeWuW0sfpQX9IDU2DfWC1aMDUcimrgG0oC6Ce8BoDCYiwroOzaxHajNCOCe2uag.5DSRe8nSdc6rtN7RQvPfJA",
"merchantTransactionId": "{}".format(uuid.uuid1()),
"paymentMethodId": self.idss,
"properties": {
"billingAddress": {
"address1": "address-1",
"address2": "address-2",
"city": "hrb",
"company": "",
"countryCode": "CN",
"firstName": "ocean",
"lastName": "li",
"phone": "15544444444",
"phoneAreaCode": "+86",
"postalCode": "150000",
"provinceCode": "HL"
},
"description": "WorldPay WPG Payment demo",
"email": "[email protected]"
}
}
with self.client.post(url, catch_response=True, headers=self.header, data=json.dumps(body)) as res:
if res.status_code == 200 and res.text.find("SUCCESS") > -1:
# res.json 是帮你把json字符串转为了字典,res.text 是原始的json字符串
resdata = res.json()
print(resdata)
else:
print(res.text)
#发起paypel支付
@task(1)
def paypel(self):
self.redius()
url = '/payment'
body = {
"paymentMethodId": self.idsss,
"createPaymentTransactionType": "PURCHASE",
"merchantTransactionId": "{}".format(uuid.uuid1()),
"amount": 3.99,
"currency": "USD",
"properties": {
"cancelUrl": "http://localhost.com/cancel",
"returnUrl": "http://localhost.com/return",
"email": "[email protected]",
"shippingAddress": {
"address1": "address-1",
"address2": "address-2",
"city": "hrb",
"company": "",
"countryCode": "C2",
"firstName": "ocean",
"lastName": "li",
"phone": "15544444444",
"phoneAreaCode": "+86",
"postalCode": "150000",
"provinceCode": "HL"
}
}
}
with self.client.post(url, catch_response=True, headers=self.header, data=json.dumps(body)) as res:
if res.status_code == 200 and res.text.find("SUCCESS") > -1:
# res.json 是帮你把json字符串转为了字典,res.text 是原始的json字符串
resdata = res.json()
print(resdata)
else:
print(res.text)
if __name__ == "__main__":
import os
os.system("locust -f zhifu.py --host=https://api.dev.lazyshop.com:4430")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/yeyingnan/python.git
[email protected]:yeyingnan/python.git
yeyingnan
python
python
master

搜索帮助