京东sign计算的研究

2022-07-04 Views314字2 min read

sign python代码

# -*- coding:utf-8 -*-

import base64
import hashlib
import time
import uuid
from urllib.parse import quote

from Crypto.Cipher import AES
from fastapi import FastAPI
from urllib3 import disable_warnings

disable_warnings()

server = FastAPI()


def sub(arg1, arg2, arg3):
    return arg1 + arg2 + arg3


def encrypt(code):
    return code


def func_sign(
        functionId,
        body,
        client="apple",
        clientVersion="10.3.6"
):
    uid = "".join(str(uuid.uuid4()).split("-"))
    st = str(int(time.time() * 1000))
    random1, random2 = 2, 0
    sv = f"{random1}{random2}"
    lists = [
        f"functionId={functionId}",
        f"body={body}",
        f"uuid={uid}",
        f"client={client}",
        f"clientVersion={clientVersion}",
        f"st={st}",
        f"sv=1{sv}"
    ]
    ret_bytes = sub(str.encode("&".join(lists)), random1, random2)
    lists = [
        f"body={quote(body)}",
        f"client={client}",
        f"clientVersion={clientVersion}",
        f"uuid={uid}",
        f"st={st}",
        f"sign={hashlib.md5(base64.b64encode(ret_bytes)).hexdigest()}",
        f"sv=1{sv}"
    ]
    return "&".join(lists)

京东sign计算的接口说明

POST /sign

请求 Request

请求 BODY
fn string
body object

子属性
body.url string
body.action string

响应 Response

成功返回

状态码 200
HEADER


Date string
值:Thu, 19 May 2022 00:23:19 GMT
Content-Type string
值:application/json;charset=utf-8


参数
code int
int64

data object

子属性
data.fn string
data.sign string

msg string

错误返回

状态码 400

HEADER


Date string
值:Thu, 19 May 2022 00:48:02 GMT

Content-Type string
值:application/json;charset=utf-8

参数


code int
int64
msg string
sign string

参考
Github:https://github.com/chiupam/jd_sign

EOF