1、新增:
import random
import requests
import json
def qu_post():
url = "http://218.17.121.162:38080/fm/company/add"
# Authorization 主要用来获得访问权限的token
headers = {"Content-Type": "application/json", 'Accept-Charset': 'UTF-8',
'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsImNyZWF0ZWQiOjE2NDU2NzA4MzgyNDcsImNvbXBhbnlOYW1lIjpudWxsLCJjb21wYW55U2hvcnROYW1lIjoieXRnIiwidXNlcklkIjoxLCJzdXBwZXIiOnRydWUsImNsaWVudF9pZCI6InNzbyIsInVzZXJfbm8iOiJhZG1pbiIsImN1cnJlbnRfdXNlcl9uYW1lIjoi566h55CG5ZGYIiwidXNlckxhbmd1YWdlIjoiemgtQ04iLCJhdWQiOlsiemhxYyJdLCJjb21wYW55SWQiOjEsImxvZ2luVGltZSI6MTY0NTY3MDgzNjkzNCwibW9kaWZ5VGltZSI6MTY0NTY2ODE4MDAwMCwib3JnX2lkIjoiMSIsInNjb3BlIjpbImFsbCJdLCJjb21wYW55X2NvZGUiOiIxIiwiZXhwIjoxNjQ1NzA2ODM4LCJvcmdfbmFtZSI6IuebkOeUsOa4ryIsInBsYXRGb3JtIjoiV2ViIiwianRpIjoiNmM4MjgxNTQtYTdlOS00MTA1LWFhMjktZGYxMmIzNDYxYjUzIn0.MuEHXhX65feItMguUVtWuJlsJxGcaZr94J29QQDgfIFGeQ2Yv4vRshnr61er6qaVhFOoumbldHd-8PTMx9tXu_Smq2Gd32CNeGgSDFOrBhDabx6i2Sm6bPUKpd2SXgqnirI9RghnN33iaXYxP-LusWppvZ2iDeTX13wnja1tqhRCEKH8eXKTZOJpeNEBezPGEHGcg260oatARSCJQJPTlDE2OggxUllxKnGFJ81NkeQb_j0kUOKqLu2ClJuowJRHrgPTU-1tLlXS_-ZEOLl56Wy0pm7CpwzWU5ltMOEnvDD9cmYDvjm2TPxhB1FF1FkGR0LAyzaZjOyp5hI_HlHSLA'
}
# 生成随机数
str_value = generate_random_str(36)
print("str_value=", str_value)
content = {"companyEnName": "", "linkManTwo": "", "linkManTwoTel": "", "creator": "", "createTime": "",
"companyAddr": "", "linkMan": "", "remark": "", "linkManTwoPosition": "", "linkManEmail": "",
"updater": "", "optimistic": "", "linkManTel": "", "updateTime": "", "companyName": str_value,
"linkManTwoEmail": "", "companyCode": str_value, "linkManPosition": "", "id": "",
"companyShortName": str_value,
"initPwd": str_value, "companyType": 1, "jyBankAccount": "", "jyBusinessRegisterNo": "",
"jyCorpType": 1,
"jyDepositBank": "", "jyEInvoiceQuota": "", "jyGtPayee": str_value, "jyGtReviewer": str_value,
"jyMailingAddress": "", "jyPaperCommonInvoiceQuota": "", "jyPaperSpecialInvoiceQuota": "",
"jyParentOfficeId": "", "tjComCode": ""}
# 使用post方法
r = requests.post(url=url, headers=headers, data=json.dumps(content))
print(r.text)
def generate_random_str(randomlength=16):
"""
生成一个指定长度的随机字符串
"""
random_str = ''
base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'
length = len(base_str) - 1
for i in range(randomlength):
random_str += base_str[random.randint(0, length)]
return random_str
if __name__ == "__main__":
qu_post()
# f = generate_random_str(106)
# print(f)
2、修改:
import random
import requests
import json
def qu_post():
url = "http://218.17.121.162:38080/fm/company/update"
# Authorization 主要用来获得访问权限的token
headers = {"Content-Type": "application/json", 'Accept-Charset': 'UTF-8',
'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsImNyZWF0ZWQiOjE2NDU2NzA4MzgyNDcsImNvbXBhbnlOYW1lIjpudWxsLCJjb21wYW55U2hvcnROYW1lIjoieXRnIiwidXNlcklkIjoxLCJzdXBwZXIiOnRydWUsImNsaWVudF9pZCI6InNzbyIsInVzZXJfbm8iOiJhZG1pbiIsImN1cnJlbnRfdXNlcl9uYW1lIjoi566h55CG5ZGYIiwidXNlckxhbmd1YWdlIjoiemgtQ04iLCJhdWQiOlsiemhxYyJdLCJjb21wYW55SWQiOjEsImxvZ2luVGltZSI6MTY0NTY3MDgzNjkzNCwibW9kaWZ5VGltZSI6MTY0NTY2ODE4MDAwMCwib3JnX2lkIjoiMSIsInNjb3BlIjpbImFsbCJdLCJjb21wYW55X2NvZGUiOiIxIiwiZXhwIjoxNjQ1NzA2ODM4LCJvcmdfbmFtZSI6IuebkOeUsOa4ryIsInBsYXRGb3JtIjoiV2ViIiwianRpIjoiNmM4MjgxNTQtYTdlOS00MTA1LWFhMjktZGYxMmIzNDYxYjUzIn0.MuEHXhX65feItMguUVtWuJlsJxGcaZr94J29QQDgfIFGeQ2Yv4vRshnr61er6qaVhFOoumbldHd-8PTMx9tXu_Smq2Gd32CNeGgSDFOrBhDabx6i2Sm6bPUKpd2SXgqnirI9RghnN33iaXYxP-LusWppvZ2iDeTX13wnja1tqhRCEKH8eXKTZOJpeNEBezPGEHGcg260oatARSCJQJPTlDE2OggxUllxKnGFJ81NkeQb_j0kUOKqLu2ClJuowJRHrgPTU-1tLlXS_-ZEOLl56Wy0pm7CpwzWU5ltMOEnvDD9cmYDvjm2TPxhB1FF1FkGR0LAyzaZjOyp5hI_HlHSLA'
}
# 生成随机数
str_value = generate_random_str(6)
print("str_value=", str_value)
content = {"key": "593933259133440", "id": "593933259133440", "remark": "", "createTime": "2022-02-24 13:40:09",
"creator": "admin", "updateTime": "2022-02-24 13:40:09", "updater": "admin",
"companyId": 593933259133440,
"companyCode": "H5c9Vy", "companyShortName": str_value, "companyName": str_value, "initPwd": str_value,
"companyType": 1,
"companyEnName": "", "linkMan": "", "linkManTel": "", "linkManEmail": "", "linkManPosition": "",
"linkManTwo": "", "linkManTwoTel": "", "linkManTwoEmail": "", "linkManTwoPosition": "",
"companyAddr": "",
"tjComCode": "", "jyCorpType": 1, "jyBusinessRegisterNo": "", "jyDepositBank": "", "jyBankAccount": "",
"jyMailingAddress": "", "jyGtPayee": str_value, "jyGtReviewer": str_value}
# 使用post方法
r = requests.post(url=url, headers=headers, data=json.dumps(content))
print(r.text)
def generate_random_str(randomlength=16):
"""
生成一个指定长度的随机字符串
"""
random_str = ''
base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'
length = len(base_str) - 1
for i in range(randomlength):
random_str += base_str[random.randint(0, length)]
return random_str
if __name__ == "__main__":
qu_post()
# f = generate_random_str(106)
# print(f)
3、外部系统访问:
import pytest
import time
from src.util.Common import com
import requests
import random
import requests
import rsa
import base64
import json
import hashlib
# class Testy2:
# @pytest.mark.parametrize('val',
# [['PRO_WAREHOUSING'],
# ['TRANSFERS_WAREHOUSING'],
# ['OTHER_WAREHOUSING']])
# def test_in(self, val):
# # print(999999999)
# print('循环执行=', val[0])
# -----------------------------------------------20210609
# 指定重复执行用例的次数
# @pytest.mark.repeat(100)
# def test_02(self):
# print("9999999=", com.change_time(format='%Y-%m-%d %H:%M:%S'))
# --------------------------测试requests.post()签名调用接口
class Testy:
headers = {}
# def setup_method(self):
# # Log.debug('每次都执行')
# self.random = 89
# 外部接口获取sign
def get_sign(self, appKey, appSecret, companyCode, version, param):
self.headers = {"Content-Type": "application/json", 'Accept-Charset': 'UTF-8'}
self.rsa = None
self.host = None
self.headers['appkey'] = appKey
self.headers['version'] = version
self.headers['company_code'] = companyCode
self.headers['bizType'] = 'TMS_ORDER_ASYNC@123'
json_str = appKey + version + param
json_list = list(json_str)
json_list.sort()
sortNoBlankStr = ''.join(json_list)
sort_str = appSecret + sortNoBlankStr + appSecret
md5 = hashlib.md5()
md5.update(sort_str.encode('utf-8'))
sign = md5.hexdigest()
self.headers['sign'] = sign.upper() # 'EEFF90D254BF8912E0C83C17592B5ED4'
print("99999999999=", self.headers)
# print("88888888888=", self.random)
return sign.upper()
def test_post(self):
DS_Post = {'origCode': 'WS000043'}
self.get_sign('HD-OMS', 'scqvb88496Yt', 'SCWL', '1.0.0', json.dumps(DS_Post))
print(666666666666, " = ", self.headers)
trs = requests.post("http://192.168.10.245:8888/omsService/oms/api/queryInventoryInformation",
headers=self.headers, data=json.dumps(DS_Post))
print("5555= ", trs.text)
# -----------------------------测试requests.post()签名调用接口(结束)
# 1、咨询一下 为什么,token的值不变:559D7E68A8E635305062BBC309CD04A5
# 2、拿到生成的token,第一次访问系统,也不需要登录吗?
# sql语句的学习
# https://blog.csdn.net/weixin_39877898/article/details/111123337
# https://www.cnblogs.com/karkash/p/8421852.html
# mysql分组取前3_mysql 分组获取前三条记录
# https://blog.csdn.net/weixin_36149065/article/details/113115582
# Python处理接口测试的签名
# https://www.cnblogs.com/ailiailan/p/10647120.html
# def test_ccc(self):
# import webbrowser
# webbrowser.open("https://blog.csdn.net/weixin_39877898/article/details/111123337")
---------------------------------------------------------------------------------------------------- 220716