How to implement the e-commerce order interface API with python

In this era of popular sharing themes, for software, only sharing and openness can play and develop the greatest role of software code. The API appeared just for this theme. The emergence of the API has greatly accelerated the speed of programming, making it possible for us to program more and more complex functions. So mastering the use of API is one of the necessary skills for our programming.

Earlier we provided examples of php and .net, and some netizens also use python to develop, so I encapsulated the relevant code, so that everyone can avoid pitfalls.

First of all, if you want to use the API service of express bird, you need to register an account, and you can find it by checking the previous articles, which is omitted here.

The following directly provides you with the core source code

↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓

# 请求数据处理方法
def before_reqData(shipperCode, logisticCode):
    """请求报文"""
    frs_reqData = {
        "OrderCode": "",  # 可为空
        "ShipperCode": shipperCode,
        "LogisticCode": logisticCode
    }
    # 数据转换为json格式
    data = json.dumps(frs_reqData)
    
    # 进行url编码
    # 替换内容
    reqData = quote(data).replace("%20%", "%")

    return reqData

def data_sign(shipperCode, logisticCode):
    """签名datasign"""
    frs_reqData = {
        'OrderCode': '',
        'ShipperCode': shipperCode,
        'LogisticCode': logisticCode
      
    }
  
    APIKey = "554343b2-7252-439b-b4eb-1af42c8f2175";

# 请求内容(未编码) + APIKey
# MD5加密前去除空格
    data = json.dumps(frs_reqData).replace(": ", ":").replace(", ", ",") + APIKey

    # md5加密
sign_md5 = hashlib.md5(data.encode("utf-8")).hexdigest()

    # Base64编码
data_sign = base64.b64encode(sign_md5.encode("utf-8")).decode("utf-8")

    return data_sign

For more express interface API technology dry goods, interface practical tutorials, and logistics industry knowledge, follow our public account [Express Bird API]. If you think the above content is useful to you, please like, comment and forward. Your recognition is the motivation for me to continue sharing!

If you have any unclear questions, please leave a message to discuss together.

Guess you like

Origin blog.csdn.net/KuaiDNiao/article/details/128615486