diff --git a/dr-feeder.go b/dr-feeder.go index 8889760..6171ded 100644 --- a/dr-feeder.go +++ b/dr-feeder.go @@ -14,7 +14,7 @@ import ( ) // Version is current `git describe --tags` infomation. -var Version string = "v2.3.2" +var Version string = "v2.3.3" func consume(ch chan common.NotifyPayload, notifiers []notifier.Notifier) { for { diff --git a/watcher/weibo.go b/watcher/weibo.go index 00972ce..6a5a01b 100644 --- a/watcher/weibo.go +++ b/watcher/weibo.go @@ -17,6 +17,8 @@ const safariUA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6)" + " AppleWebKit/605.1.15 (KHTML, like Gecko)" + " Version/14.0.3 Safari/605.1.15" +const iOSWeiboIntlUA = "WeiboOverseas/4.2.6 (iPhone; iOS 14.4.2; Scale/3.00)" + type weiboWatcher struct { uid uint64 updateTime time.Time @@ -55,6 +57,47 @@ func (watcher weiboWatcher) weiboAPI() string { ) } +func (watcher weiboWatcher) weiboIntlShareAPI(weiboID string) string { + return fmt.Sprintf("https://weibointl.api.weibo.cn/portal.php"+ + "?a=get_share_url"+ + "&ct=weibo"+ + "&lang=zh-Hans"+ + "&uid=%d"+ + "&weibo_id=%s", + watcher.uid, + weiboID, + ) +} + +func (watcher weiboWatcher) weiboIntlShareURL(weiboID string) (string, error) { + var err error = nil + var shareURL string + c := colly.NewCollector( + colly.UserAgent(iOSWeiboIntlUA), + ) + + c.OnError(func(_ *colly.Response, e error) { + err = e + }) + + c.OnResponse(func(r *colly.Response) { + var resp weiboIntlResp + err = json.Unmarshal(r.Body, &resp) + if err != nil { + return + } + if resp.Retcode != 0 { + err = fmt.Errorf("%s", resp.Info) + return + } + shareURL = resp.Data.URL + }) + + c.Visit(watcher.weiboIntlShareAPI(weiboID)) + c.Wait() + return shareURL, err +} + func (watcher *weiboWatcher) setup() error { var err error = nil c := colly.NewCollector( @@ -152,7 +195,11 @@ func (watcher weiboWatcher) parseContent() (common.NotifyPayload, bool) { } picURL := weibo.PicURL - pageURL := fmt.Sprintf("%s/%s", "https://m.weibo.cn/status", weibo.ID) + pageURL, err := watcher.weiboIntlShareURL(weibo.ID) + if err != nil { + log.Println(err) + pageURL = fmt.Sprintf("%s/%s", "https://m.weibo.cn/status", weibo.ID) + } var pageInfo pageInfo mapstructure.Decode(weibo.PageInfo, &pageInfo) diff --git a/watcher/weibomodels.go b/watcher/weibomodels.go index 3136d36..b1256c5 100644 --- a/watcher/weibomodels.go +++ b/watcher/weibomodels.go @@ -39,3 +39,11 @@ type pageInfo struct { } `mapstructure:"page_pic"` PageURL string `mapstructure:"page_url"` } + +type weiboIntlResp struct { + Data struct { + URL string `json:"url"` + } `json:"data"` + Info string `json:"info"` + Retcode int `json:"retcode"` +}