Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python调用例子 #3

Open
xhoustgd70298 opened this issue Jan 1, 2024 · 0 comments
Open

python调用例子 #3

xhoustgd70298 opened this issue Jan 1, 2024 · 0 comments

Comments

@xhoustgd70298
Copy link

import requests
import hashlib

BASE_URL = 'https://upay.xxx.top'

# 验签
def verify_signature(parms):
    # 排序
    parms = sorted(parms.items(), key=lambda x: x[0])
    # print(parms)
    sign = ''
    for i in parms:
        if i[1] == '':
            continue
        if i[0] != 'signature':
            if sign != '':
                sign += '&'
            sign += i[0] + '=' + str(i[1])
    sign = sign + 'ninjakb2005'
    md5 = hashlib.md5(sign.encode('utf-8')).hexdigest()
    return md5


# 发起支付
def create_transaction(usdt_amount, order_id, notify_url, redirect_url, signature):
    url = f'{BASE_URL}/api/v1/order/create-transaction'
    data = {
        "order_id": order_id,
        "amount": usdt_amount,
        "notify_url": notify_url,
        "redirect_url": redirect_url,
        "signature": signature
    }
    response = requests.post(url, json=data)
    print(response.json())


if __name__ == '__main__':
    parms = {
        "order_id": "1006",
        "amount": 1,
        "notify_url": "http://127.0.0.1:2005",
        "redirect_url": "https://www.baidu.com",
    }
    # 验签
    md5 = verify_signature(parms)
    print(md5)
    
    create_transaction(
        usdt_amount=parms['amount'],
        order_id=parms['order_id'],
        notify_url=parms['notify_url'],
        redirect_url=parms['redirect_url'],
        signature=md5
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant