koishi-plugin-bns-rate 1.2.6 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +13 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -94,6 +94,12 @@ const Config = Schema.object({
94
94
 
95
95
  // ===== 抓取与解析 =====
96
96
 
97
+ // dd373 的阿里云 WAF 挑战页特征(响应里是滑块验证组件,没有任何商品数据)
98
+ function looksLikeWafChallenge(html) {
99
+ const s = String(html || '')
100
+ return /aliyun-captcha|_waf_is_mobile|slideStyle|captcha-element/.test(s)
101
+ }
102
+
97
103
  async function fetchRates(ctx, url, count) {
98
104
  const limit = Math.max(1, Math.min(10, Number(count) || 5))
99
105
  const response = await ctx.http.get(url, {
@@ -102,6 +108,9 @@ async function fetchRates(ctx, url, count) {
102
108
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
103
109
  'Accept': 'text/html,application/xhtml+xml',
104
110
  'Accept-Language': 'zh-CN,zh;q=0.9',
111
+ // ⚠️ dd373 的阿里云 WAF 会拦截「没有 Referer」的请求,直接返回滑块验证页(约 12KB,无任何商品数据)
112
+ // 实测结论:只有 Referer 是必需项,Cookie 无关(连伪造的 acw_tc 都能过)。缺了它整站必然解析失败
113
+ 'Referer': DEFAULT_BUTTON_URL,
105
114
  },
106
115
  })
107
116
 
@@ -125,6 +134,10 @@ async function fetchRates(ctx, url, count) {
125
134
  }
126
135
 
127
136
  if (rates.length === 0) {
137
+ // 区分「被反爬拦截」和「页面真的改版了」——两者的排查方向完全不同
138
+ if (looksLikeWafChallenge(html)) {
139
+ throw new Error('请求被 dd373 的反爬验证页拦截(阿里云 WAF,返回了滑块验证页)。通常是请求过于频繁或缺少 Referer')
140
+ }
128
141
  throw new Error('无法解析页面汇率数据,页面结构可能已变更')
129
142
  }
130
143
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-bns-rate",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "Fetch BNS Classic Divine Stone exchange rate from dd373.com, with QQ official Markdown card support",
5
5
  "main": "index.js",
6
6
  "files": [