• Python x-www-form-urlencoded post


    # 可以指定商品数量,不指定的话默认随机random
    def DataCenterCreate(appoint_num=None):
        i = 0
        dataall = []
        order_amount = 0
        format_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        order_num = 'CS' + datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')
        if appoint_num == None:
            appoint_num = random.randint(2, 5)
        while i < appoint_num:
            code = sqlSelect('goods')
            price = round(random.uniform(1, 10), 2)
            print("price=====", price)
            number = random.randint(1, 10)
            print("number=====", number)
            subtotal = round(price * number, 2)
            print("subtotal=====", subtotal)
            order_amount = round((order_amount + subtotal), 2)
            dataall.append({"order_num": order_num, "goods_sn": code[0][0], "price": price,
                            "number": number, "order_amount": order_amount, "time": format_time})
            i += 1
        print("dataall====", dataall)
        print("dataall最大值====", dataall[len(dataall) - 1]["order_amount"])
        return dataall
    
    
    def OrderInsert():
        headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", 'Connection': 'close'}
        url = 'http://test/submit'
        arra = []
        # 传参需要的商品数量
        dataset = DataCenterCreate()
        for data in dataset:
            arra.append({
                "sku": data["goods_sn"],
                "price": data["price"],
                "num": data["number"]
            })
        data = {
            "token": "BE3DBFD76E",
            "orderid": dataset[0]["order_num"],
            "sku": json.dumps(arra),
            "name": "测试",
            "email": "123456@163.com",
            "remark": "",
            "dep_code": "DW44556565512",
            "dep_name": "",
            "invoice_title": "中",
            "invoice_type": "2",
            "invoice_org_code": "45521454122",
            "invoice_name": "测试",
            "invoice_phone": "010-23524154",
            "payment": 2,
            "orderprice": dataset[len(dataset) - 1]["order_amount"]
        }
        print("data===", data)
        payload = urlencode(data)
        print("payload===", payload)
        response = requests.post(url=url, data=payload, headers=headers)
        print(response.json())
    
    
    def InsertOrder(num):
        i = 0
        while i < num:
            minn = False
            while minn == False:
                OrderInsert()
                minn = True
            i += 1
    
    
    InsertOrder(1)
    
    • 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
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73

    注意:
    在这里插入图片描述

  • 相关阅读:
    Arduino Firmata + PyFirmata
    c++的文件读写
    瑞萨e2studio(25)----电容触摸配置(2)
    Node.js 实战 第2章 Node 编程基础 2.4 用 node_modules 重用模块 & 2.5 注意事项
    vue3后台管理框架之基础配置
    工控机设备安全-系统加固的意义
    70、window11+visual studio2019+共享内存进行数据传输
    ollama 模型国内加速下载,制作自定义Modelfile模型文件
    Java进阶之路——从初级程序员到架构师,从小工到专家
    Linux中文件查找相关命令比较
  • 原文地址:https://blog.csdn.net/weixin_43006743/article/details/127939611