sendInvoice
发送支付账单。
返回值: 调用成功时返回 Message。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
chat_id | Integer or String | 是 | 聊天 ID 或 @username |
message_thread_id | Integer | 可选 | 论坛话题 ID |
direct_messages_topic_id | Integer | 可选 | 私信话题 ID (Bot API 10.0) |
title | String | 是 | 商品名称(1-32) |
description | String | 是 | 商品描述(1-255) |
payload | String | 是 | 有效载荷 |
provider_token | String | 可选 | 支付提供商令牌 |
currency | String | 是 | 货币(Stars 使用 XTR) |
prices | Array of LabeledPrice | 是 | LabeledPrice JSON 数组 |
max_tip_amount | Integer | 可选 | 最高小费金额 |
suggested_tip_amounts | Array of Integer | 可选 | 建议小费金额的 JSON 数组 |
start_parameter | String | 可选 | 支付深度链接 |
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 | 可选 | 可变运费 |
disable_notification | Boolean | 可选 | 静默发送 |
protect_content | Boolean | 可选 | 保护内容 |
allow_paid_broadcast | Boolean | 可选 | 允许付费广播 |
message_effect_id | String | 可选 | 消息特效 ID |
suggested_post_parameters | SuggestedPostParameters | 可选 | SuggestedPostParameters JSON 对象(用于频道) |
reply_parameters | ReplyParameters | 可选 | ReplyParameters JSON 对象 |
reply_markup | InlineKeyboardMarkup | 可选 | JSON 对象:InlineKeyboardMarkup |
请求示例
curl
curl -s -X POST "https://api.telegram.org/bot$TOKEN/sendInvoice" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 123456789,
"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}/sendInvoice",
json={
"chat_id": 123456789,
"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}/sendInvoice`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"chat_id": 123456789,
"title": "Example",
"description": "Example item",
"payload": "order-1",
"currency": "XTR",
"prices": [
{
"label": "Item",
"amount": 100
}
]
}),
});
console.log(await res.json());
分步教程: Telegram 机器人教程:从零创建 Telegram 机器人并发送第一条消息
相关方法
createInvoiceLink创建支付链接。refundStarPayment退还 Telegram Stars 付款。sendGift向用户或聊天发送礼物。getMyStarBalance返回机器人的 Telegram Stars 余额。getStarTransactions返回机器人的 Telegram Stars 交易记录。editUserStarSubscription取消或续订 Telegram Stars 订阅。giftPremiumSubscription赠送 Telegram Premium 订阅。answerShippingQuery响应配送查询。answerPreCheckoutQuery响应预结账查询。getAvailableGifts返回机器人可发送的礼物。getUserGifts返回用户的礼物。getChatGifts返回聊天的礼物。