「古城鐘樓」微博帳號以純機器人方式每兩小時報時,內容為地支時辰 + 對應次數的「鏛~」,單日漲粉 20 萬。本文還原其核心邏輯並提供完整 C# 控制台程式碼 (約 100 行)。
| 地支 | 時段 | 整點 |
|---|---|---|
| 子 | 23:00-01:00 | 00:00 |
| 丑 | 01:00-03:00 | 02:00 |
| 寅 | 03:00-05:00 | 04:00 |
| 卯 | 05:00-07:00 | 06:00 |
| 辰 | 07:00-09:00 | 08:00 |
| 巳 | 09:00-11:00 | 10:00 |
| 午 | 11:00-13:00 | 12:00 |
| 未 | 13:00-15:00 | 14:00 |
| 申 | 15:00-17:00 | 16:00 |
| 酉 | 17:00-19:00 | 18:00 |
| 戌 | 19:00-21:00 | 20:00 |
| 亥 | 21:00-23:00 | 22:00 |
規律:每兩小時整點發布,內容 = 【{地支}時】 + 「鏛~」重複 N 次。N = 上午時點數 (0=子, 2=丑...10=巳);下午 = (小時 - 12)。
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Timers;
using NetDimension.Weibo; // NuGet: NetDimension.Weibo
namespace WeiboTimer
{
class Program
{
static string AppKey = "你的_AppKey";
static string AppSecret = "你的_AppSecret";
static string CallbackUrl = "你的_CallbackUrl";
static Timer _timer = new Timer();
static OAuth _oauth;
static Client _sina;
static void Main(string[] args)
{
_oauth = Authorize();
if (string.IsNullOrEmpty(_oauth.AccessToken)) return;
_sina = new Client(_oauth);
var uid = _sina.API.Entity.Account.GetUID();
var user = _sina.API.Entity.Users.Show(uid);
Console.WriteLine($"登入成功:@{user.ScreenName} (https://weibo.com/{user.ProfileUrl})");
_timer.Interval = 60000; // 1 分鐘檢查一次
_timer.Elapsed += TimerElapsed;
_timer.AutoReset = true;
_timer.Start();
Console.WriteLine("定時任務啟動,按任意鍵結束...");
Console.ReadKey();
}
static OAuth Authorize()
{
var o = new OAuth(AppKey, AppSecret, CallbackUrl);
while (!ClientLogin(o))
Console.WriteLine("登入失敗,請重試。");
return o;
}
static bool ClientLogin(OAuth o)
{
Console.Write("微博帳號: ");
var account = Console.ReadLine();
Console.Write("登入密碼: ");
var pwdColor = Console.ForegroundColor;
Console.ForegroundColor = Console.BackgroundColor; // 隱藏輸入
var password = Console.ReadLine();
Console.ForegroundColor = pwdColor;
return o.ClientLogin(account, password);
}
static void TimerElapsed(object sender, ElapsedEventArgs e)
{
var now = DateTime.Now;
var content = MakeContent(now.Hour, now.Minute);
if (string.IsNullOrEmpty(content)) return;
try
{
var status = _sina.API.Entity.Statuses.Update(content);
var created = DateTime.ParseExact(status.CreatedAt,
"ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);
Console.WriteLine($"本機:{now:G} 微博:{created:G} 內容:{status.Text}");
}
catch (Exception ex)
{
Console.WriteLine($"發布失敗: {ex.Message}");
}
}
static string MakeContent(int hour24, int minute)
{
var diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');
if (hour24 % 2 != 0 || minute != 0) return ""; // 僅偶數整點
var bells = "";
int count = hour24 >= 12 ? hour24 - 12 : hour24;
for (int i = 0; i < count; i++) bells += "鏛~";
return $"【{diZhi[hour24 / 2]}時】{bells}";
}
}
}
NetDimension.Weibo (官方推薦 C# SDK),支援 ClientLogin 密碼模式 (需帳號開啟 API 權限)。Console.ForegroundColor = Console.BackgroundColor 視覺隱藏,非真正安全輸入。Timer.Interval = 60000 每分鐘檢查,配合 hour % 2 == 0 && minute == 0 確保整點觸發。status.CreatedAt 解析微博伺服器時間,對比本機時間發現漂移可校正。count = hour >= 12 ? hour - 12 : hour 完美對應上午/下午敲擊次數。

guchengzhonglou.rar (內含 Weico.iPhone AppKey)。AppKey/AppSecret/CallbackUrl。百行代碼複刻百萬粉絲大號核心功能,展示了「簡單邏輯 + 穩定執行 + 獨特內容」的傳播威力。同理可擴展為「每日一句」「節氣提醒」「股市收盤」等垂直領域機器人,歡迎發揮創意。