import hashlib
import random
import requests

# appId 和 appSecret 请到 https://www.processimage.cn/watermark/user/main 获取

imagePath = ''

appId = ''

appSecret = ''

with open(file=imagePath, mode='rb') as image_file:
    image_md5 = hashlib.md5(image_file.read()).hexdigest()

# 生成一个随机数,范围是 [10^7, 10^8-1] ,将数字转换成字符串,并在前面补0,使长度为8位

salt = f"{random.randint(10 ** 7, 10 ** 8 - 1):08d}"

response = requests.post(

    url='https://www.processimage.cn/watermark/access',

    data={

        'appId': appId,

        'salt': salt,

        # --------------- 以下参数不是必须的,请根须需要参照 api 文档填写 --------------- #

        # 'offset': 'see api document',
        # 'sync': 'see api document',
        # 'callback': 'see api document',
        # 'rectangles': 'see api document',
        # 'markNames': 'see api document',
        # 'excludeKeywords': 'see api document',
        # 'onlyOcr': 'see api document',
        # 'show': see api document'

    },

    files={

        "uploadFile": open(file=imagePath, mode='rb')

    },

    headers={

        'x-access-api-sign': hashlib.md5(

            (appId + image_md5 + str(salt) + appSecret).encode('utf-8')).hexdigest()

    }

).json()

print(response)