v03413 / bepusdt

一款更好用的个人USDT收款网关,兼容所有 Epusdt 插件,可无缝切换,支持交易所动态汇率、支持Docker一键部署;支持独角发卡 易支付 异次元发卡
GNU General Public License v3.0
334 stars 79 forks source link

API请求返回 签名错误 状态码400 #30

Closed 46ef882ff3a47d closed 1 week ago

46ef882ff3a47d commented 1 week ago

我的系统: Debian GNU/Linux 11 (bullseye) x86_64 我遇到的问题: 我已经成功安装并且运行了epusdt, 在确保签名计算正确的前提下, API返回400 签名错误

Config EXPIRE_TIME=1800 USDT_RATE=1 AUTH_TOKEN=epusdt_password_xasddawqe LISTEN=:8666 TRADE_IS_CONFIRMED=0 APP_URI= WALLET_ADDRESS=** TG_BOT_TOKEN=** TG_BOT_ADMIN_ID=** *代表我正确并填写了该信息

Detail 我复制文档中的示例参数 order_id : 20220201030210321 amount : 42 notify_url : http://example.com/notify redirect_url : http://example.com/redirect 然后进行md5计算 结果为 1cd4b52df5587cfb1968b0c0c6e156cd 我计算出的结果与文档中的预期结果是一致的, 所以并非签名问题

Request

 url = f"http://******:8666/api/v1/order/create-transaction"

  payload = {
      'order_id': '20220201030210321',
      'amount': '42',
      'notify_url': 'http://example.com/notify',
      'redirect_url': 'http://example.com/redirect',
      'signature': '1cd4b52df5587cfb1968b0c0c6e156cd'
  }

  response = requests.request("POST", url, data=payload)

Response {"error":"expected { character for map value"}{"error":"signature not found"}{"error":"签名错误"}

Utils

def epusdt_sign(parameters, sign_key):
    sorted_params = dict(sorted(parameters.items()))
    sign_str = ''
    for key, val in sorted_params.items():
        if val == '':
            continue

        if key != 'signature':
            if sign_str != '':
                sign_str += "&"

            sign_str += f"{key}={val}"

    sign_str += sign_key
    sign = hashlib.md5(sign_str.encode('utf-8')).hexdigest()
    return sign
46ef882ff3a47d commented 1 week ago

注意 API数据提交方式以及参数类型 即可解决 参数类型不对会导致提示签名错误ovo