tencent cloud

Tencent Cloud Super App as a Service

계약
데이터 처리 및 보안 계약
문서Tencent Cloud Super App as a Service

Signature and Verification

포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-01-16 19:30:02

Virtual payment request signature algorithm

The pay_sig parameter uses a signature algorithm that signs the payment request with the AppKey obtained from the superapp. This indicates that the request is initiated by the developer’s server-side payment module. The signature algorithm pseudocode is as follows:
paySig = to_hex(hmac_sha256(appKey,method + '&' + signData))
import hmac
import hashlib
import urllib.parse

# sign_data: The original payment string. Note that sign_data must be exactly the same as the parameters sent from the frontend, including spaces and line breaks. It is recommended to generate and send it from the backend.
# appKey
# method
def gen_pay_sig(sign_data, appkey, method):
need_encode_body = method + '&' + sign_data
print(need_encode_body)
return hmac.new(key=appkey.encode('utf-8'), msg=need_encode_body.encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()

Virtual payment callback signature

The pay_event_sig parameter uses a signature algorithm that signs the payment event request with the virtual payment key from the superapp, indicating the request is initiated via the superapp backend service. The signature algorithm pseudocode is as follows:
pay_event_sig = to_hex(hmac_sha256(app_key, event + '&' + payload))
You can refer to the calc_pay_event_sig implementation in the following Python example, where:
●event is the type of the pushed event.
●app_key is the virtual payment key configured for the superapp.
●payload is the data for this push, corresponding to the payload within the minigame structure; refer to the specific push request parameter documentation for details.

#!/usr/bin/python
# -*- coding: utf-8 -*-
""" Example of PayEventSig signature calculation algorithm """
import hmac
import hashlib
def calc_pay_event_sig(event, payload, app_key):
""" pay_event_sig signature algorithm
Args:
event - event type, e.g., pass event when creating an order
payload - data corresponding to the event, such as the payload in the notification message,
e.g. {"OpenId":"to_user_openid","OutTradeNo":"xxxxxxx","WeChatPayInfo":{"MchOrderNo":"xxxxxxx","TransactionId":"xxxxxxx"},"Env":0,"CoinInfo":{"ZoneId":"1","TotalPrice":100,"BuyQuantity":1,"OrigPrice":100}}
app_key - virtual payment key configured by superapp
Returns:
Payment request signature pay_event_sig
"""
need_sign_msg = event + '&' + payload
pay_sig = hmac.new(key=appkey.encode('utf-8'), msg=need_sign_msg.encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()
return pay_sig

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백