把即刻附近动态替换为精选

前言

前一阵写了个抓取即刻社区大V动态的爬虫,来筛选互动量比较高的动态。

三丰的机器人 每天、每周发布一个静态网页。

例如 2022-06-072022-05-27

由于前端能力有限,静态网页不能完全还原 APP 的显示效果,就想着把这些动态放到 APP 内展示,附近动态页我几乎不看,那就把这个页面的内容替换掉吧~

抓包

得益于 iOS 强大的生态能力,我们可以通过第三方软件修改 APP 发出的网络包,先抓包看一下接口参数响应。

接口地址

https://47.99.112.78/1.0/nearbyFeed/list

参数

1
2
3
4
5
6
{
"location": "110.36214433321533,31.84648323980757",
"coordsys": "wgs84",
"limit": 10,
"trigger": "user"
}

参数很简单, 只有坐标和分页信息, 替换静态动态的话跟这些参数无关,重点关注响应。

响应

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{
"data":[
{
"id":"629e91765c9a1731570e2d0e",
"type":"ORIGINAL_POST",
"content":"稳定、安定、永定,来自永定门的启发\n2022高考加油✊",
"urlsInText":[

],
"status":"NORMAL",
"isCommentForbidden":false,
"likeCount":0,
"commentCount":0,
"repostCount":0,
"shareCount":0,
"topic":{
"id":"5540eca0e4b0b63be5c7a5a9",
"type":"TOPIC",
"content":"高考加油站",
"subscribersCount":108382,
"squarePicture":{
"format":"jpeg",
"picUrl":"https://cdn.jellow.site/Fnxa6B6WexBT6JHSLjW6M3r-AruO.jpg?imageMogr2/auto-orient/heic-exif/1/format/jpeg/thumbnail/1000x1000%3E",
"middlePicUrl":"https://cdn.jellow.site/Fnxa6B6WexBT6JHSLjW6M3r-AruO.jpg?imageMogr2/auto-orient/heic-exif/1/format/jpeg/thumbnail/800x800%3E",
"smallPicUrl":"https://cdn.jellow.site/Fnxa6B6WexBT6JHSLjW6M3r-AruO.jpg?imageMogr2/auto-orient/heic-exif/1/format/jpeg/thumbnail/300x300%3E",
"thumbnailUrl":"https://cdn.jellow.site/Fnxa6B6WexBT6JHSLjW6M3r-AruO.jpg?imageMogr2/auto-orient/heic-exif/1/format/jpeg/thumbnail/120x120%3E",
"livePhoto":null,
"themes":{

},
"nft":null
},
"briefIntro":"高考在即,即刻为你加油打气,一起分享关于高考的有用经验和信息!",
"topicType":"OFFICIAL",
"operateStatus":"ONLINE",
"isValid":true,
"isVerified":false,
"topicId":0,
"isSearchable":false,
"messagePrefix":"高考重要动态",
"internalTags":[

],
"customTags":[

],
"auditStatus":"",
"newCategory":[

],
"involvedUsers":null,
"entryTab":"",
"tabs":[

],
"rectanglePicture":null,
"pictureUrl":"",
"thumbnailUrl":"",
"subscribedStatusRawValue":0,
"subscribedAt":"",
"ref":"NEARBY_FEED_POST_TOPIC",
"isDreamTopic":false,
"isAnonymous":false,
"enablePictureComments":true,
"enablePictureWatermark":true,
"timeForRank":"",
"lastMessagePostTime":"2022-06-08T06:12:14.385Z",
"createdAt":"",
"updatedAt":"",
"subscribersTextSuffix":"名即友已加入",
"subscribersName":"即友",
"friendsAlsoSubscribe":"",
"maintainer":null,
"isUserTopicAdmin":false,
"activitySection":null,
"activitySections":[

],
"tips":{
"inDraft":"",
"inComment":""
},
"toppingArea":null,
"inShortcuts":false,
"preferSection":"",
"relatedHashtags":[

],
"intro":"高考在即,即刻为你加油打气,一起分享关于高考的有用经验和信息!",
"squarePostUpdateTime":"2022-06-08T06:12:14.385Z",
"subscribersAction":"已加入",
"approximateSubscribersCount":"10万",
"subscribersDescription":"10万名即友已加入",
"isCommentForbidden":false,
"botCount":0,
"recentPost":"",
"source":"",
"enableForUserPost":true
},
"poi":{
"poiId":"B0FFIZ0SZ2",
"name":"永定门城楼",
"location":[
116.399324,
39.872468
],
"countryname":"中国",
"pname":"北京市",
"cityname":"北京市",
"formattedAddress":"永定门城楼永定门东街与永定门内大街交叉口西50米"
},
"pictures":[

],
"collected":false,
"collectTime":null,
"user":{
"id":"62681d1919f10b001002e206",
"username":"38e2993c-a7ba-4e57-b94b-d30b0ad727af",
"screenName":"有人知晓",
"createdAt":"2022-04-26T16:00:00.000Z",
"updatedAt":"2022-06-07T11:37:18.515Z",
"isVerified":false,
"verifyMessage":"",
"briefIntro":"每天更新#时间仓库 摄影\n拿出手机,我们一起拍好照片,纪录时间\n未来无人知晓,一起做到更好",
"avatarImage":{
"thumbnailUrl":"https://cdn.jellow.site/FsxnWHH-LfDN4_JIK6tTuQXMpekbv3.jpg?imageMogr2/auto-orient/heic-exif/1/format/jpeg/thumbnail/!120x120r/gravity/Center/crop/!120x120a0a0",
"smallPicUrl":"https://cdn.jellow.site/FsxnWHH-LfDN4_JIK6tTuQXMpekbv3.jpg?imageMogr2/auto-orient/heic-exif/1/format/jpeg/thumbnail/!300x300r/gravity/Center/crop/!300x300a0a0",
"middlePicUrl":"https://cdn.jellow.site/FsxnWHH-LfDN4_JIK6tTuQXMpekbv3.jpg?imageMogr2/auto-orient/heic-exif/1/format/jpeg/thumbnail/!800x800r/gravity/Center/crop/!800x800a0a0",
"picUrl":"https://cdn.jellow.site/FsxnWHH-LfDN4_JIK6tTuQXMpekbv3.jpg?imageMogr2/auto-orient/heic-exif/1/format/jpeg/thumbnail/!1000x1000r/gravity/Center/crop/!1000x1000a0a0",
"format":"jpeg"
},
"decorations":{

},
"profileImageUrl":"https://cdn.jellow.site/FsxnWHH-LfDN4_JIK6tTuQXMpekbv3.jpg?imageMogr2/auto-orient/heic-exif/1/format/jpeg/thumbnail/!120x120r/gravity/Center/crop/!120x120a0a0",
"statsCount":{
"topicSubscribed":0,
"topicCreated":0,
"followedCount":1,
"followingCount":21,
"highlightedPersonalUpdates":0,
"liked":35,
"respectedCount":0
},
"isSponsor":false,
"backgroundImage":{
"picUrl":"https://cdn.jellow.site/Ftpq4I3OB8Yy3gkQLOXM_mJS6aypv3.jpg?imageMogr2/auto-orient/heic-exif/1/format/jpeg/thumbnail/1000x1000%3E"
},
"bio":"每天更新#时间仓库 摄影\n拿出手机,我们一起拍好照片,纪录时间\n未来无人知晓,一起做到更好",
"gender":"MALE",
"country":"001",
"province":"001011",
"refRemark":{
"type":"ORIGINAL_POST",
"refId":"629e91765c9a1731570e2d0e"
},
"ref":"NEARBY_FEED_POST",
"storyStatus":"NONE"
},
"createdAt":"2022-06-06T23:44:54.379Z",
"isFeatured":false,
"enablePictureComments":true,
"repostable":true,
"isSuppressed":false,
"video":{
"type":"VIDEO",
"image":{
"picUrl":"https://cdn.jellow.site/FqVtf_Hntjok3hiD6nTG2ztI19M1?imageMogr2/auto-orient/heic-exif/1/format/jpeg?imageView2/0/w/800/h/800/format/jpeg/q/80",
"thumbnailUrl":"https://cdn.jellow.site/FqVtf_Hntjok3hiD6nTG2ztI19M1?imageMogr2/auto-orient/heic-exif/1/format/jpeg?imageView2/0/w/200/h/200/format/jpeg/q/80",
"format":"jpeg"
},
"duration":20572,
"width":1080,
"height":1440
},
"rollouts":{
"wmpShare":{
"id":"gh_501436d6aeea",
"path":"/pages/message?id=629e91765c9a1731570e2d0e&type=ORIGINAL_POST"
}
},
"scrollingSubtitles":[
{
"text":"每天更新#时间仓库 摄影 拿出手机,我们一起拍好照片,纪录时间 未来无人知晓,一起做到更好",
"type":"COMMON"
}
],
"readTrackInfo":{
"feedType":"LOCAL_POST"
},
"distance":"3.8km"
}
],
"loadMoreKey":{
"getPostsWithinTenKm":20,
"step":"getPostsWithinTenKm",
"location":{
"lnglat":"116.36834300920364,39.84785189456118",
"coordsys":"gcj02",
"ip":"115.47.100.187",
"cityname":"北京市",
"pname":"北京市",
"countryname":"中国"
},
"page":1
}
}

响应结构比较复杂,看了一下跟获取动态详情接口的响应结构基本一致,那就好办了。
我们爬取的有精选动态 ID, 挨个调用动态详情接口, 把多条动态的响应数据拼成数组返回就好了,中间加上一层缓存提高性能。

伪装接口

怎么实现的就不细讲了,下面就是我仿照附近动态的结构模拟的一个接口,返回的内容是当天精选动态。

1
curl -X POST -H "Content-Type:application/json" https://jike.asynctask.cn/api/recommendFeed  --data '{}'

下一步我们就开始狸猫换太子。

修改响应

修改接口响应用的是 iOS 端的 QuantumultX APP

规则文件

1
2
3
hostname = api.ruguoapp.com,47.99.112.78

^https?:\/\/api\.ruguoapp\.com\/1\.0\/nearbyFeed\/list url script-response-body https://raw.githubusercontent.com/junbaor/script/main/jike/qx_recommend_v3.js

替换逻辑

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const url = "https://jike.asynctask.cn/api/recommendFeed";
const method = "POST";
const headers = { "Content-Type": "application/json" };
const data = {};

const myRequest = {
url: url,
method: method,
headers: headers,
body: JSON.stringify(data)
};

$task.fetch(myRequest).then(response => {
$done(response.body);
}, reason => {
console.log("😿 替换动态广场失败, 原因: " + reason.error);
$notify("😿 替换动态广场失败", "", "原因: " + reason.error + " 请刷新重试");
$done();
});

先是对 api.ruguoapp.com,47.99.112.78 这两个域名 IP 开启 https 解密, 这样才能识别到请求内容。
然后用脚本替换掉 https://api.ruguoapp.com/1.0/nearbyFeed/list 接口的响应, 把我们伪装接口的内容放到响应体中,这样 APP 就能正常展示了。

其他类似软件也可以实现,原理相同,期待有缘人编写适配规则。

使用方式

前提条件:拥有 iPhone 和 QuantumultX APP

  1. 打开 MitM 开关,按照提示信任证书
  2. 打开重写开关
  3. 点击引用,添加引用链接 https://raw.githubusercontent.com/junbaor/script/main/jike/qx_recommend_v3.conf
  4. 打开即刻 APP 刷新附近动态列表试试

友情提醒, 软件不能是盗版,不然重写功能不会生效。


把即刻附近动态替换为精选
https://asynctask.cn/2022/06/08/jike_qx/
作者
三丰
发布于
2022年6月8日
许可协议