大家最近都在热议古城钟楼的红火。不是加V号、不是官方号、不是皇冠会员。没有拟人化,没有段子、没有运营。1天之内从1万不到的粉丝新增了20多万并且还在持续传播和增长粉丝。我不研究它是怎么红起来的,但写个类似的程序实现它却很容易,程序才100行左右: 9 E- v _9 K j7 D" |) A. X- M
先来普及一下地支时间与北京时间的对应关系: - 【子时】夜半,又名子夜、中夜:十二时辰的第一个时辰。(北京时间23时至次日01时)。
- 【丑时】鸡鸣,又名荒鸡:十二时辰的第二个时辰。(北京时间01时至03时)。
- 【寅时】平旦,又称黎明、早晨、日旦等:时是夜与日的交替之际。(北京时间03时至05时)。
- 【卯时】日出,又名日始、破晓、旭日等:指太阳刚刚露脸,冉冉初升的那段时间。(北京时间05时至07时)。
- 【辰时】食时,又名早食等:古人“朝食”之时也就是吃早饭时间,(北京时间07时至09时)。
- 【巳时】隅中,又名日禺等:临近中午的时候称为隅中。(北京时间09时至11时)。
- 【午时】日中,又名日正、中午等:(北京时间11时至13时)。
- 【未时】日昳,又名日跌、日央等:太阳偏西为日跌。(北京时间13时至15时)。
- 【申时】哺时,又名日铺、夕食等:(北京时间15时至17时)。
- 【酉时】日入,又名日落、日沉、傍晚:意为太阳落山的时候。(北京时间17时至19时)。
- 【戌时】黄昏,又名日夕、日暮、日晚等:此时太阳已经落山,天将黑未黑。天地昏黄,万物朦胧,故称黄昏。(北京时间19时至21时)。
- 【亥时】人定,又名定昏等:此时夜色已深,人们也已经停止活动,安歇睡眠了。人定也就是人静。(北京时间21时至23时)。
: j! c* G$ g7 ~, G. J 7 w; b; I7 S+ ]) p& x" F- P
然后我们来分析一下它昨天发布的内容 - 1月8日00:00来自Weico.iPhone 【子时】
- 1月8日02:00来自Weico.iPhone 【丑时】铛~铛~
- 1月8日04:00来自Weico.iPhone 【寅时】铛~铛~铛~铛~
- 1月8日06:00来自Weico.iPhone 【卯时】铛~铛~铛~铛~铛~铛~
- 1月8日08:00来自Weico.iPhone 【辰时】铛~铛~铛~铛~铛~铛~铛~铛~
- 1月8日10:00来自Weico.iPhone 【巳时】铛~铛~铛~铛~铛~铛~铛~铛~铛~铛~
- 1月8日12:00来自Weico.iPhone 【午时】
- 1月8日14:00来自Weico.iPhone 【未时】铛~铛~
- 1月8日16:00来自Weico.iPhone 【申时】铛~铛~铛~铛~
- 1月8日18:00来自Weico.iPhone 【酉时】铛~铛~铛~铛~铛~铛~
- 1月8日20:00来自Weico.iPhone 【戌时】铛~铛~铛~铛~铛~铛~铛~铛~
- 1月8日22:00来自Weico.iPhone 【亥时】铛~铛~铛~铛~铛~铛~铛~铛~铛~铛~) }$ S$ x ~+ M
; O& c: c0 Z- X& i( q: P, O
根据上面,得出它有以下规律: - 每两个小时发布一条微博,
- 发布时间是偶数小时的0分,这个时间并不是地支时间的开始时间,而是正中间的那个时间点
- 内容是相应的地支时间,加上根据时间而变化的“铛~”的次数,
- “铛~”的次数与时有关,12小时以前与小时相同,12小时以后与[小时减12]相同。
, o$ l# W- z: Y% t2 F1 s
西安钟楼里的钟就是这样敲的吗?去过钟楼一次,没登上去,也没注意。
' Z7 t8 y' O; K7 R6 B6 `7 l% A完整代码如下: 需要自行修改App相关值:
* m, C0 A& D2 P3 k$ ]- m- # S, e, G/ W. K
- <p style="font: 14px/25px verdana, Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><span style="margin: 0px; padding: 0px; color: rgb(255, 0, 0);"></span> </p>
复制代码- using System;
5 ^& ~( `# q1 Z' Q* E8 t( t - using System.Collections.Generic;
+ _7 I% I/ r5 k6 H: y - using System.Text;8 C" _4 q# ]% _ Q3 f
- using NetDimension.Weibo;/ G5 e" Z' ]7 b- d
- using System.Timers;
+ d$ R( r# e. W/ o5 i - using System.Globalization;3 v: V! E7 d% z9 e
3 e$ d+ t) R) K' e- namespace WeiboTimer# h/ ^. n+ G% y# u* e
- {
3 d/ R+ |, p* W# D' r$ `. h1 G - class Program
7 A& b, |: \1 H2 Z7 ]* j! W* e - {
2 N. u5 A( L5 W3 l; P - static string AppKey = "********";
3 g' D2 j% K6 j( J( A; w6 B3 X8 l3 y - static string AppSecret = "*******";/ w- T% n0 v, R
- static string CallbackUrl = "****************";
- W% [ P; V1 @3 o. o( k- g - static Timer t = new Timer();2 g [1 Y8 D! T
- static OAuth oauth = null;" j3 F! D N# o0 a# i0 A) d6 j
- static Client Sina = null;
O0 U; a% i9 V$ z0 c# c& J! ~
+ C7 n: C, M9 l y- static void Main(string[] args)
. Z7 E+ q8 _9 n4 B - {
" ^ b/ V5 Y* g6 S - oauth = Authorize();
e* R$ N B& ?2 Q/ P7 W - if (!string.IsNullOrEmpty(oauth.AccessToken)){Console.Write("登录成功!");}
0 I, ~$ y2 t1 q! J/ M$ W+ H' X - * ?1 T* y& w8 d
- Sina = new Client(oauth);9 D+ y4 r" F$ j/ Z
- string uid = Sina.API.Entity.Account.GetUID();1 m1 q! U, O ?0 H# ]/ X
- var entity_userInfo = Sina.API.Entity.Users.Show(uid);
7 W W$ M4 g; v3 D - Console.WriteLine("昵称:{0},微博地址:http://weibo.com/{1}", entity_userInfo.ScreenName, entity_userInfo.ProfileUrl);" a9 [: H+ z4 v) s9 B
- 6 a9 k) m" k. l0 N$ g7 _
- try
- e0 ?9 r* x/ C. Q0 C8 a4 g - {$ x, x) t+ M* [
- t.Interval = 1000 * 60; //设置间隔时间为1分钟
w) q/ B6 R; @* j - t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); //到达时间的时候执行事件;
9 h6 l, a1 w. R+ W- _9 S( j - t.AutoReset = true; //设置是执行一次(false)还是一直执行(true); 6 |# ?8 s3 m% s Y
- t.Start(); //启动Timer对象;
, A$ Z1 ~' A" ]+ F$ { - }' w) a. C0 L; N3 c. a/ F
- catch (Exception ex)1 g- J. p" K! A. h7 ]. M: t+ I$ E: M
- {+ F7 L9 x6 \3 X' c3 s- a2 l$ X @4 r
- Console.WriteLine("定时任务异常:" + ex.Message);0 `' o& ^4 m* x, j; @) g
- t.Stop();
6 p9 B4 o6 |: f& ^+ y - }
' Y; z3 f& Z% }% T4 X0 N5 b; v5 m3 R2 @ - Console.WriteLine("定时任务开始工作。。。");
. M6 N* f% G8 m* L - Console.ReadKey();
: x# S+ {: x6 s, z; M1 } - }
% d9 M: ^1 ?9 m& T
' \: z3 N% [6 q- static OAuth Authorize()
( `& \2 k5 s% i. z& {/ ?/ _ - {/ A B5 m/ S' s- V, r! M4 A
- OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);
8 o% C, y, U+ y: T, r! F `" M - while (!ClientLogin(o))+ P# K' F d" ~
- {
* s$ }0 D0 L9 c6 G& c: _& x/ Y - Console.WriteLine("登录失败,请重试。");
/ T( x& x: s+ c& Q9 D9 l - }& Z0 W, K" p* A; y
- return o;
: |0 W$ Z# V A7 I" U! u8 c) Q- ` - }
+ f! i @; m% T1 v$ s+ m
& |# ~4 o. S0 f8 \, O1 U9 B- private static bool ClientLogin(OAuth o)
: }8 G. o: d7 q2 X - {3 x3 B9 {; U# p" |
- Console.Write("微博账号:");# Q' B" `4 M' A& t' }* [5 b
- string account = Console.ReadLine();8 ? t2 w7 v. ^8 L& Q. X7 t9 `
- Console.Write("登录密码:");
$ P. H# _# H& u- k* D8 b - ConsoleColor originColor = Console.ForegroundColor;
$ l0 M' Z6 S" Q I. R6 a- e - Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^1 C7 V& ?6 v8 l+ p: M/ e) d6 ]
- string password = Console.ReadLine();9 Q% ?, K! Y @6 G8 o, @
- Console.ForegroundColor = originColor; //恢复前景颜色。9 r+ i8 A$ f; x# Q/ {' e2 u9 O
- return o.ClientLogin(account, password);1 R" B2 P9 n% ~+ X3 A
- }3 v5 r7 r, I5 w% \2 S3 c
; B: n5 [- H: b, e5 Z; I1 v8 k- static void TimerElapsedEvent(object sender, ElapsedEventArgs e)
2 t. P8 c& z* B ^0 d3 j3 V! v4 Z - {
* M) n W) F. K - DateTime iNow = DateTime.Now;
' P8 l/ M+ u V3 E. j2 ^# v- ^ - try
' J% I/ T i" m' @: E - {
) S' C$ `8 f- u - string content = makeContent(iNow.Hour, iNow.Minute);; `( u( l0 Q8 W/ J/ D% S
- if (!string.IsNullOrEmpty(content))8 ]3 M5 p5 G5 I. \. K
- {
! ~6 O9 G0 q: ] - var statusInfo = Sina.API.Entity.Statuses.Update(content);9 L2 A ~4 z2 `$ i
- DateTime dtCreate = DateTime.ParseExact(statusInfo.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);
3 g2 [, |: H0 S9 @! v. ?& h7 o* L - Console.WriteLine("本机时间:{0}, 微博时间:{1}, 发布内容:{2}", string.Format("{0:G}", iNow), string.Format("{0:G}", dtCreate), statusInfo.Text);
1 H4 r! q& e& [ - }
) i2 R, x! I' q1 ^, P# x. f - }" Z& l" c% ^% ]( p( ?4 r% L) }
- catch (Exception ex)
( I9 L/ x2 m9 a; L! Q& w - {
9 q9 c; F$ S% _' U/ o; F9 F6 {! C" j - Console.WriteLine("定时任务异常:" + ex.Message);+ g' _: | ?4 H* R
- }
+ ~ [, G2 |0 C- h8 j/ S- O - }
( |$ k% d0 B# G! e1 D# h8 k: H
; r- h( j6 G" [ X- static string makeContent(int hour24, int minute)
: ]* e3 V/ r" u% J( L) N. s( L - {' _2 C" ?( f& ~- b' Q6 b$ S/ H
- string[] diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');
6 D+ I; Y5 A* N9 O8 e: A* ~$ B8 v - string extWeibo = "";# s5 S3 P/ S1 z( a0 [+ v" X f1 j
- if (hour24 % 2 == 0 && minute == 0)8 j: y( X- o( i3 ]& m
- {
. k2 p- K$ x$ t- H* X - for (int i = 0; i < ((hour24 >= 12)? (hour24 - 12): hour24); i++)
) R" z; n" P4 M, I - {. t2 c W) n0 x5 T, O
- extWeibo += "铛~";: s: E4 V9 Y1 L" S6 {4 @
- }
1 m4 [5 p' b) z6 p) v# Q1 I6 F# n. H9 a - return "【" + diZhi[hour24 / 2] + "时】" + extWeibo;
t% b) v) a7 J* y9 T. S% i: E - }5 j/ i* ]- b+ E3 ~! ~' n
- else
; B. u: Z0 q: `. H- h) s - {
% w: o+ @; B/ Y3 b' t- ]+ O! V& ` - return "";7 t- r& e, z8 s p6 ~
- }
: \/ v' q: \, l; Q$ T - }+ C0 m6 T& X6 E$ c L; W
- }1 S9 X: c/ x' G: z* B C
- }
复制代码完整程序下载: " u: u: `' _) J8 c- u* g
|
上一篇:微信支付下一篇:微信公众平台开发(66)人品计算
|