1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #!/usr/bin/python3
- # -*- coding: utf-8 -*-
- import random
- import string
- import hashlib
- import time
- import base64
- import json
- import requests
- # YZY_HOST = "http://19.15.0.128:8080"
- YZY_HOST = "https://xtbg.digitalgd.com.cn"
- YZY_CORPID = "wld341060039"
- YZY_CORPSECRET = "5_8aOBBjioNbP7KDwjyBKmwnJ05-y1WbaJlt4irM1eA"
- YZH_PASSID = "yzy_demo"
- YZH_PASSTOKEN = "WjKat55cv6PrJtpCHld0trrHsv1mbCqL"
- dgd_pre_release = 1
- def get_access_token():
- url = "{}/ebus/yzyapi/cgi-bin/gettoken?corpid={}&corpsecret={}".format(YZY_HOST, YZY_CORPID, YZY_CORPSECRET)
- timestamp = str(int(time.time()))
- nonce = ranstr(20)
- signature = calcResponseSign(timestamp, YZH_PASSTOKEN, nonce)
- headers = {
- 'Content-Type': 'application/json;charset=UTF-8',
- "x-tif-signature": signature,
- "x-tif-timestamp": timestamp,
- "x-tif-nonce": nonce,
- "x-tif-paasid": YZH_PASSID,
- "dgd-pre-release": str(dgd_pre_release)
- }
- response = requests.get(url, headers=headers, timeout=15)
- print('yzy return:', response.text)
- def ranstr(num):
- salt = ''.join(random.sample(
- string.ascii_letters + string.digits, num))
- return salt
- #
- #
- # 生成校验码
- #
- #
- def authentication(timestamp, token, nonce, uid, uinfo, ext, signature):
- sign_data_sha256 = calcRequestSign(
- timestamp, token, nonce, uid, uinfo, ext)
- return sign_data_sha256 == signature.upper()
- #
- #
- # 计算校验码
- #
- #
- def calcResponseSign(timestamp, token, nonce):
- sign_data = "{}{}{}{}".format(timestamp, token, nonce, timestamp)
- return hashlib.sha256(
- sign_data.encode("utf8")
- ).hexdigest().upper()
- #
- #
- # 计算校验码
- #
- #
- def calcRequestSign(timestamp, token, nonce, uid, uinfo, ext):
- sign_data = "{}{}{},{},".format(
- timestamp, token, nonce, uid)
- if len(uinfo) == 0:
- sign_data = sign_data + ","
- else:
- sign_data = sign_data + uinfo + ","
- if len(ext) == 0:
- sign_data = sign_data
- else:
- sign_data = sign_data + ext
- sign_data = sign_data + timestamp
- return hashlib.sha256(
- sign_data.encode("utf8")
- ).hexdigest().upper()
|