本文为您提供了Python语言版本的充值接口接口对接DEMO示例
#python3.10.2
import http.client
import urllib.parse
hostname = "api.ihuyi.com"
request_uri = "/f/giftcard?action=buy"
#定义请求的数据
values = {
'username':'123456', #API ID
'mobile':'130*******', #手机号
'orderid':'DD20253995959', #商家订单ID
'productid':'k111-1', #产品ID
'buynum':'1', #购买数量-固定数量1
'timestamp':'20240321150546', #时间戳格式如:yyyyMMddHHmmss 允许 10分钟统一以东 8 时间
'sign':'81ed625f338277f1bd7f27b9339e302c', #签名
}
#将数据进行编码
params = urllib.parse.urlencode(values).encode(encoding='UTF8')
#定义请求的头部
headers = {
"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"
}
#初始化一个 http 链接
conn = http.client.HTTPConnection(hostname)
conn.request("POST", request_uri, params, headers)
response = conn.getresponse()
#打印状态
print(response.status, response.reason)
#打印结果
print(response.read().decode("utf-8"))
conn.close()
在线咨询
150,000家
企业客户
21年
行业经验
2V1
2对1客户支持