Telegram Bot API
🌐 中文

createInvoiceLink

分类: 支付 · Bot API 10.3 · 官方文档

创建支付链接。

返回值: 调用成功时返回 String。

参数

参数类型必填说明
business_connection_idString可选商业连接 ID
titleString是商品名称
descriptionString是商品描述
payloadString是有效载荷
provider_tokenString可选支付提供商令牌
currencyString是货币
pricesArray of LabeledPrice是LabeledPrice JSON 数组
subscription_periodInteger可选订阅周期(秒)
max_tip_amountInteger可选最高小费金额
suggested_tip_amountsArray of Integer可选建议小费金额的 JSON 数组
provider_dataString可选提供给支付提供商的 JSON 数据
photo_urlString可选商品照片 URL
photo_sizeInteger可选照片大小
photo_widthInteger可选照片宽度
photo_heightInteger可选照片高度
need_nameBoolean可选要求填写姓名
need_phone_numberBoolean可选要求填写电话
need_emailBoolean可选要求填写电子邮箱
need_shipping_addressBoolean可选要求填写收货地址
send_phone_number_to_providerBoolean可选将电话号码发送给支付提供商
send_email_to_providerBoolean可选将电子邮箱发送给支付提供商
is_flexibleBoolean可选可变价格

参数说明为简要概括,完整内容请参阅官方文档。

请求示例

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 机器人并发送第一条消息