GoForum🌐 V2EX

[送码] 维护了快一年的会员订阅管理工具 — 口袋订阅,最近大幅优化了一版本

iPocket · 2026-05-26 21:13 · 0 次点赞 · 0 条回复

一个苹果 iOS 原生制作的会员订阅管理工具 —— 口袋订阅,维护了快一年了,总体很稳定了,非常感谢国内外的朋友反馈,特别是一个老外叫 Jimmy ,好像非常喜欢我这款产品,他发现 bug 总是发邮件给我,邮件里有和他对话的几十封邮件了,真的非常感谢,也很开心。 产品主打简约,可以快速添加会员订阅,快速查找会员订阅,其他功能,订阅 APP 里该有的应该都有。然后可以通过长按别的 APP 分享到 口袋订阅 快速添加,也可以通过搜索 APP/网站 名称来快速添加,其他功能我倒觉得没那么重要,主要看个大概的费用。 APP 不搜集你的任何数据,这里其实有个缺点,就是你想改善你的产品的时候,没有数据,就会发现无从下手,你根本不知道用户在哪个页面体验不好😂,全靠用户从其他渠道反馈,邮件、小红书等。如有苹果开发者也可以一起交流下这方面的经验。 App Store 地址: https://apps.apple.com/cn/app/%E5%8F%A3%E8%A2%8B%E8%AE%A2%E9%98%85-%E8%AE%A2%E9%98%85%E7%AE%A1%E7%90%86%E4%B8%8E%E8%B4%A6%E5%8D%95%E6%8F%90%E9%86%92/id6752631319 https://i.imgur.com/RApyBOD.png

留言抽 20 个永久会员,明天收市后按上证指数抽出,因为我发现我送的很多兑换码感觉被机器人秒了 抽奖程序由 GPT 提供,代码如下

(async function lottery() {
  const drawTime = "2026-05-27 18:00:00";      // 开奖时间
  const postUrl = "https://example.com/post/123"; // 帖子链接
  const shIndex = "3123.45";                   // 上证指数,建议用字符串,避免小数精度问题
  const replyTotal = 1000;                     // 回复总数
  const winnerCount = 20;                       // 抽奖个数

  if (!drawTime || !postUrl || !shIndex) {
    console.error("开奖时间、帖子链接、上证指数不能为空");
    return;
  }

  if (!Number.isSafeInteger(replyTotal) || replyTotal <= 0) {
    console.error("回复总数必须是大于 0 的安全整数");
    return;
  }

  if (!Number.isSafeInteger(winnerCount) || winnerCount <= 0) {
    console.error("抽奖个数必须是大于 0 的安全整数");
    return;
  }

  if (winnerCount > replyTotal) {
    console.error("抽奖个数不能大于回复总数");
    return;
  }

  async function sha256Hex(text) {
    const data = new TextEncoder().encode(text);
    const hashBuffer = await crypto.subtle.digest("SHA-256", data);

    return Array.from(new Uint8Array(hashBuffer))
      .map(b => b.toString(16).padStart(2, "0"))
      .join("");
  }

  function hexToBigInt(hex) {
    return BigInt("0x" + hex);
  }

  async function randomInt(seed, counter, maxExclusive) {
    const max = BigInt(maxExclusive);
    const space = 1n << 256n;
    const limit = space - (space % max);

    while (true) {
      const hash = await sha256Hex(seed + ":" + counter.value);
      counter.value++;

      const num = hexToBigInt(hash);

      // 拒绝采样,避免简单取模产生偏差
      if (num < limit) {
        return Number(num % max);
      }
    }
  }

  async function drawWinners(seed, replyTotal, winnerCount) {
    const winners = [];
    const swapped = new Map();
    const counter = { value: 0 };

    for (let i = 0; i < winnerCount; i++) {
      const remaining = replyTotal - i;
      const r = await randomInt(seed, counter, remaining);

      const selectedIndex = i + r;

      const selectedValue = swapped.has(selectedIndex)
        ? swapped.get(selectedIndex)
        : selectedIndex + 1;

      const currentValue = swapped.has(i)
        ? swapped.get(i)
        : i + 1;

      swapped.set(selectedIndex, currentValue);
      winners.push(selectedValue);
    }

    return winners;
  }

  const rawSeed = [
    `开奖时间=${drawTime}`,
    `帖子链接=${postUrl}`,
    `上证指数=${shIndex}`,
    `回复总数=${replyTotal}`,
    `抽奖个数=${winnerCount}`
  ].join("|");

  const seedHash = await sha256Hex(rawSeed);
  const winners = await drawWinners(seedHash, replyTotal, winnerCount);
  const sortedWinners = [...winners].sort((a, b) => a - b);

  console.log("========== 抽奖结果 ==========");
  console.log("原始种子:");
  console.log(rawSeed);
  console.log("");
  console.log("种子 SHA-256:");
  console.log(seedHash);
  console.log("");
  console.log("中奖楼层:");
  console.log(winners.join(", "));
  console.log("");
  console.log("中奖楼层,升序:");
  console.log(sortedWinners.join(", "));
  console.log("============================");
})();
0 条回复
添加回复
你还需要 登录 后发表回复

登录后可发帖和回复

登录 注册
主题信息
作者: iPocket
发布: 2026-05-26
点赞: 0
回复: 0