跳到正文
Petrichor's Blog
返回

ChatGPT转Stripe长链接支付脚本

目录

目录

1. 48月半价team的长链接:

(async function generateTeamHostedLink() {
  console.log("⏳ [team-link] 正在获取 Session Token...");
 
  // ── 1. 获取当前登录的 Access Token ──────────────────────────────────────
  let accessToken;
  try {
    const session = await fetch("/api/auth/session").then((r) => r.json());
    accessToken = session?.accessToken;
    if (!accessToken) throw new Error("accessToken 为空");
  } catch (e) {
    console.error("❌ [team-link] 获取 Token 失败,请确保已登录 ChatGPT:", e.message);
    return;
  }
  console.log("✅ [team-link] Token 获取成功");
 
  // ── 2. 构造请求 Payload ──────────────────────────────────────────────────
  const payload = {
    plan_name: "chatgptteamplan",
 
    team_plan_data: {
      workspace_name: "MyTeam",        // ← 你可以改成自己想要的工作区名字
      price_interval: "month",         // month 或 year
      seat_quantity: 2,                // ← 至少填 2,推荐 2~5
    },
 
    billing_details: {
      country: "US",                   // 必须 US(配合 THINKTECHNOLOGIES promo)
      currency: "USD",
    },
 
    cancel_url: "https://chatgpt.com/#team-pricing",
 
    // 🔥 关键:使用 promo_code(THINKTECHNOLOGIES 专用)
    promo_code: "thinkiafr",
 
    checkout_ui_mode: "hosted",
  };
 
  // ── 3. 发送请求 ──────────────────────────────────────────────────────────
  console.log("⏳ [team-link] 正在请求 Stripe 长链接...");
  let data;
  try {
    const response = await fetch(
      "https://chatgpt.com/backend-api/payments/checkout",
      {
        method: "POST",
        headers: {
          Authorization: `Bearer ${accessToken}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify(payload),
      }
    );
    data = await response.json();
 
    if (!response.ok) {
      console.error("❌ [team-link] 请求失败,HTTP", response.status);
      console.error(data);
      return;
    }
  } catch (e) {
    console.error("❌ [team-link] 网络请求异常:", e.message);
    return;
  }
 
  // ── 4. 输出结果 ──────────────────────────────────────────────────────────
  const hostedUrl = data?.url || data?.stripe_hosted_url || data?.checkout_url;
 
  if (!hostedUrl) {
    console.warn("⚠️ [team-link] 未找到长链接,原始响应如下:");
    console.log(data);
    return;
  }
 
  console.log("─".repeat(60));
  console.log("✅ [team-link] 生成成功!THINKTECHNOLOGIES promo 已生效");
  console.log("");
  console.log("📋 Checkout Session ID :", data.checkout_session_id);
  console.log("🏢 Plan                : ChatGPT Team(THINKTECHNOLOGIES)");
  console.log("👥 Seats               :", payload.team_plan_data.seat_quantity);
  console.log("");
  console.log("🔗 Stripe 长链接(直接打开即可支付):");
  console.log(hostedUrl);
  console.log("─".repeat(60));
  console.log("💡 提示:打开链接后检查价格是否已应用优惠");
})();

2. 首月半价plus的脚本:

(async function generatePlusHostedLink() {
  console.log("⏳ [plus-link] 正在获取 Session Token...");
  let accessToken;
  try {
    const session = await fetch("/api/auth/session").then((r) => r.json());
    accessToken = session?.accessToken;
    if (!accessToken) throw new Error("accessToken 为空");
  } catch (e) {
    console.error("❌ [plus-link] 获取 Token 失败,请确保已登录 ChatGPT:", e.message);
    return;
  }
  console.log("✅ [plus-link] Token 获取成功");

  const payload = {
    plan_name: "chatgptplusplan",
    billing_details: {
      country: "US",
      currency: "USD",
    },
    cancel_url: "https://chatgpt.com/?promo_campaign=plus-1-month-50-pct-off#pricing",
    promo_campaign: "plus-1-month-50-pct-off",
    checkout_ui_mode: "hosted",
  };

  console.log("⏳ [plus-link] 正在请求 Stripe 长链接...");
  let data;
  try {
    const response = await fetch(
      "https://chatgpt.com/backend-api/payments/checkout",
      {
        method: "POST",
        headers: {
          Authorization: `Bearer ${accessToken}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify(payload),
      }
    );
    data = await response.json();
    if (!response.ok) {
      console.error("❌ [plus-link] 请求失败,HTTP", response.status);
      console.error(data);
      return;
    }
  } catch (e) {
    console.error("❌ [plus-link] 网络请求异常:", e.message);
    return;
  }

  const hostedUrl = data?.url || data?.stripe_hosted_url || data?.checkout_url;
  if (!hostedUrl) {
    console.warn("⚠️ [plus-link] 未找到长链接,原始响应如下:");
    console.log(data);
    return;
  }
  console.log("─".repeat(60));
  console.log("✅ [plus-link] 生成成功!首月 50% 优惠");
  console.log("");
  console.log("📋 Checkout Session ID :", data.checkout_session_id);
  console.log("🏢 Plan                : ChatGPT Plus(首月半价)");
  console.log("");
  console.log("🔗 Stripe 长链接(直接打开即可支付):");
  console.log(hostedUrl);
  console.log("─".repeat(60));
  console.log("💡 提示:打开链接后检查价格是否显示为 $10(原价 $20 的 50%)");
})();

分享这篇文章:

上一篇
测试
下一篇
Matplotlib 中文显示配置笔记