createInvoiceLink
创建支付链接。
返回值: 调用成功时返回 String。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
business_connection_id | String | 可选 | 商业连接 ID |
title | String | 是 | 商品名称 |
description | String | 是 | 商品描述 |
payload | String | 是 | 有效载荷 |
provider_token | String | 可选 | 支付提供商令牌 |
currency | String | 是 | 货币 |
prices | Array of LabeledPrice | 是 | LabeledPrice JSON 数组 |
subscription_period | Integer | 可选 | 订阅周期(秒) |
max_tip_amount | Integer | 可选 | 最高小费金额 |
suggested_tip_amounts | Array of Integer | 可选 | 建议小费金额的 JSON 数组 |
provider_data | String | 可选 | 提供给支付提供商的 JSON 数据 |
photo_url | String | 可选 | 商品照片 URL |
photo_size | Integer | 可选 | 照片大小 |
photo_width | Integer | 可选 | 照片宽度 |
photo_height | Integer | 可选 | 照片高度 |
need_name | Boolean | 可选 | 要求填写姓名 |
need_phone_number | Boolean | 可选 | 要求填写电话 |
need_email | Boolean | 可选 | 要求填写电子邮箱 |
need_shipping_address | Boolean | 可选 | 要求填写收货地址 |
send_phone_number_to_provider | Boolean | 可选 | 将电话号码发送给支付提供商 |
send_email_to_provider | Boolean | 可选 | 将电子邮箱发送给支付提供商 |
is_flexible | Boolean | 可选 | 可变价格 |
请求示例
curl
curl -s -X POST "https://api.telegram.org/bot$TOKEN/createInvoiceLink" \
-H "Content-Type: application/json" \
-d '{
"title": "Example",
"description": "Example item",
"payload": "order-1",
"currency": "XTR",
"prices": [
{
"label": "Item",
"amount": 100
}
]
}'
Python
import requests
TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
f"https://api.telegram.org/bot{TOKEN}/createInvoiceLink",
json={
"title": "Example",
"description": "Example item",
"payload": "order-1",
"currency": "XTR",
"prices": [
{
"label": "Item",
"amount": 100
}
]
},
timeout=30,
)
print(resp.json())
JavaScript
const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/createInvoiceLink`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"title": "Example",
"description": "Example item",
"payload": "order-1",
"currency": "XTR",
"prices": [
{
"label": "Item",
"amount": 100
}
]
}),
});
console.log(await res.json());
分步教程: Telegram 机器人教程:从零创建 Telegram 机器人并发送第一条消息
相关方法
sendInvoice发送支付账单。refundStarPayment退还 Telegram Stars 付款。sendGift向用户或聊天发送礼物。getMyStarBalance返回机器人的 Telegram Stars 余额。getStarTransactions返回机器人的 Telegram Stars 交易记录。editUserStarSubscription取消或续订 Telegram Stars 订阅。giftPremiumSubscription赠送 Telegram Premium 订阅。answerShippingQuery响应配送查询。answerPreCheckoutQuery响应预结账查询。getAvailableGifts返回机器人可发送的礼物。getUserGifts返回用户的礼物。getChatGifts返回聊天的礼物。