Shipment order printing python version

Just started, everyone is teasing Li. It's a good time to talk about friendship... It's rare to have no new needs and no old bug s. It's just time to sort out some things we played before.

Shipping order: refers to the detailed list of goods purchased by customers attached when the merchant issues the shipping order to the warehouse or shipper after confirming the user's order, including goods ID, goods name, goods specification, model, quantity, etc. After receiving this list, the warehouse or shipper will pick the goods according to the order, and finally the packer will pack and deliver the goods after checking according to the order.

Therefore, in the whole environment, the shipment order is an important intermediate link, which must be printed accurately and clearly to facilitate subsequent operations. Maybe you will say, is it so difficult to get things done with a form?

This is really not a form can handle! The reasons are as follows.
1. Different businesses and goods need different templates to be printed. A form is too low and it is not convenient for subsequent links to quickly find and verify.
2. Different platforms adopt different technologies and codes, which need to be well compatible. It's not a form that can handle it.
3. Sometimes you need to take care of other items along with the shipping order, such as one-to-one supporting express delivery order. This requires more advanced support.

The solution is also relatively simple:
1. Shipment documents support user-defined templates;
2. The shipping order is compatible with the mainstream platform template code;
3. Shipment documents support upstream and downstream connection and expansion;

If you can see here, basically the whole thing will pass. No more nonsense. Look at the demo code:

# coding = utf-8
import hashlib
import json
import time

import requests

key = ''  # Customer authorization key
secret = ''  # Electronic sheet secret
siid = ''  # Printer equipment code
param = {
    "tempid": "1379****4104148992",
    "siid": siid,
    "callBackUrl": "http://www.xxx.com/fhd/callback",
    "petName": "kd100",
    "recName": "Xiaobai",
    "recPhone": "10086",
    "payTime": "2021-01-15 15:40:55",
    "expressName": "Deppon",
    "printTime": "2021-01-15 15:41:30",
    "printCount": "1",
    "address": "Kingdee Software Park, Nanshan District, Shenzhen City, Guangdong Province",
    "total": "21", 
    "remark": "As a shopping voucher, please keep it properly. If you have any questions, please consult the service hotline 123456798",
    "img0": {
        "type": "code_128",
        "content": "887921256577",
        "width": 350,
        "height": 100
    },
    "tab0": [
        {
            "prodName": "Thermal paper",
            "count": "5",
            "specs": "76*130",
            "unitPrice": "30",
            "price": "150"
        },
        {
            "prodName": "Thermal paper",
            "count": "10",
            "specs": "100*180",
            "unitPrice": "50",
            "price": "500"
        },
        {
            "prodName": "Continuous printing paper",
            "count": "5",
            "specs": "",
            "unitPrice": "40",
            "price": "200"
        },
        {
            "prodName": "Cloud printer",
            "count": "1",
            "specs": "Second generation",
            "unitPrice": "499",
            "price": "499"
        }
    ]
}

settings = {
    "pageWidth": 100,
    "pageHeight": 180,
    "margins": {
        "top": 5,
        "bottom": 5,
        "left": 5,
        "right": 5
    }
}

param_json = json.dumps(param)
timestamp = str(time.time())
md = hashlib.md5()
tmp = param_json + timestamp + key + secret
md.update(tmp.encode())
sign = md.hexdigest().upper()

req_params = {
    'method': 'billparcels',
    'key': key,
    't': timestamp,
    'sign': sign,
    'param': param_json,
    'settings': json.dumps(settings)
}
url = 'https://poll.kuaidi100.com/print/billparcels.do '# request address

print(req_params)

result = requests.post(url, req_params)  # Send request
print(result.text)  # Return data

For more details, please refer to code and Invoice interface document . Come and talk if you have any questions~~~

Tags: Python interface demo

Posted by izua on Sun, 17 Apr 2022 21:16:12 +0930