From 774f8c98ca4d7150d5422e900d8f694a42de36b7 Mon Sep 17 00:00:00 2001
From: qixingchen <4182240+Qixingchen@users.noreply.github.com>
Date: Fri, 23 Feb 2024 23:42:35 +0800
Subject: [PATCH] feat(route): cib/whpj (#14539)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): cib/whpj
兴业银行外汇牌价
* fix lint & security issue
* fix code review
---
lib/v2/boc/radar.js | 2 +-
lib/v2/cib/maintainer.js | 3 ++
lib/v2/cib/radar.js | 13 ++++++
lib/v2/cib/router.js | 3 ++
lib/v2/cib/whpj.js | 85 +++++++++++++++++++++++++++++++++++
lib/v2/iqnew/radar.js | 2 +-
website/docs/routes/other.mdx | 10 +++++
7 files changed, 116 insertions(+), 2 deletions(-)
create mode 100644 lib/v2/cib/maintainer.js
create mode 100644 lib/v2/cib/radar.js
create mode 100644 lib/v2/cib/router.js
create mode 100644 lib/v2/cib/whpj.js
diff --git a/lib/v2/boc/radar.js b/lib/v2/boc/radar.js
index 1fe2e8d85..3f5d85453 100644
--- a/lib/v2/boc/radar.js
+++ b/lib/v2/boc/radar.js
@@ -4,7 +4,7 @@ module.exports = {
'.': [
{
title: '外汇牌价',
- docs: 'https://docs.rsshub.app/routes/others#zhong-guo-yin-hang',
+ docs: 'https://docs.rsshub.app/routes/other#zhong-guo-yin-hang',
source: ['/sourcedb/whpj', '/'],
target: '/boc/whpj',
},
diff --git a/lib/v2/cib/maintainer.js b/lib/v2/cib/maintainer.js
new file mode 100644
index 000000000..d1222d672
--- /dev/null
+++ b/lib/v2/cib/maintainer.js
@@ -0,0 +1,3 @@
+module.exports = {
+ '/whpj/:format?': ['Qixingchen'],
+};
diff --git a/lib/v2/cib/radar.js b/lib/v2/cib/radar.js
new file mode 100644
index 000000000..47fec2c98
--- /dev/null
+++ b/lib/v2/cib/radar.js
@@ -0,0 +1,13 @@
+module.exports = {
+ 'cib.com.cn': {
+ _name: '中国兴业银行',
+ '.': [
+ {
+ title: '外汇牌价',
+ docs: 'https://docs.rsshub.app/routes/other#zhong-guo-xing-ye-yin-hang',
+ source: ['/'],
+ target: '/cib/whpj',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/cib/router.js b/lib/v2/cib/router.js
new file mode 100644
index 000000000..cbc502fe4
--- /dev/null
+++ b/lib/v2/cib/router.js
@@ -0,0 +1,3 @@
+module.exports = (router) => {
+ router.get('/whpj/:format?', require('./whpj'));
+};
diff --git a/lib/v2/cib/whpj.js b/lib/v2/cib/whpj.js
new file mode 100644
index 000000000..8ae3d5af9
--- /dev/null
+++ b/lib/v2/cib/whpj.js
@@ -0,0 +1,85 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
+const https = require('https');
+const crypto = require('crypto');
+const config = require('@/config').value;
+
+module.exports = async (ctx) => {
+ // fix unsafe legacy renegotiation disabled
+ const agent = new https.Agent({
+ secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT,
+ });
+
+ const response = await got('https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery.do', { agent: { https: agent } });
+ const cookies = response.headers['set-cookie'].map((item) => item.split(';')[0]).join(';');
+
+ const $ = cheerio.load(response.data);
+ let date = $('div.main-body').find('div.labe_text').text();
+ date = date.split('\n\t')[1].replace('日期:', '').trim();
+ date = date.substring(0, 11) + date.substring(15);
+
+ const link = 'https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery/list?_search=false&dataSet.rows=80&dataSet.page=1&dataSet.sidx=&dataSet.sord=asc';
+ const data = await ctx.cache.tryGet(
+ link,
+ async () => {
+ const detailResponse = await got(link, {
+ headers: {
+ Cookie: cookies,
+ },
+ agent: { https: agent },
+ });
+ return detailResponse.data;
+ },
+ config.cache.contentExpire,
+ false
+ );
+
+ const format = ctx.params.format;
+
+ ctx.state.data = {
+ title: '中国兴业银行外汇牌价',
+ link: 'https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery.do',
+ item: data.rows.map((item) => {
+ const name = `${item.cell[0]} ${item.cell[1]}`;
+
+ const xhmr = `现汇买入价:${item.cell[3]}`;
+
+ const xcmr = `现钞买入价:${item.cell[5]}`;
+
+ const xhmc = `现汇卖出价:${item.cell[4]}`;
+
+ const xcmc = `现钞卖出价:${item.cell[6]}`;
+
+ const content = `${xhmr} ${xcmr} ${xhmc} ${xcmc}`;
+
+ return {
+ title: formatTitle(name, xhmr, xcmr, xhmc, xcmc, content, format),
+ pubDate: parseDate(date, 'YYYY年MM月DD日 HH:mm:ss'),
+ description: content.replaceAll(/\s/g, '
'),
+ guid: `${item.cell[0]} ${item.cell[1]} ${date}`,
+ };
+ }),
+ };
+};
+
+function formatTitle(name, xhmr, xcmr, xhmc, xcmc, content, format) {
+ switch (format) {
+ case 'short':
+ return name;
+ case 'xh':
+ return `${name} ${xhmr} ${xhmc}`;
+ case 'xc':
+ return `${name} ${xcmr} ${xcmc}`;
+ case 'xhmr':
+ return `${name} ${xhmr}`;
+ case 'xhmc':
+ return `${name} ${xhmc}`;
+ case 'xcmr':
+ return `${name} ${xcmr}`;
+ case 'xcmc':
+ return `${name} ${xcmc}`;
+ default:
+ return `${name} ${content}`;
+ }
+}
diff --git a/lib/v2/iqnew/radar.js b/lib/v2/iqnew/radar.js
index 2ed0ac6f1..e78913618 100644
--- a/lib/v2/iqnew/radar.js
+++ b/lib/v2/iqnew/radar.js
@@ -4,7 +4,7 @@ module.exports = {
'.': [
{
title: '最近更新',
- docs: 'https://docs.rsshub.app/routes/others#ai-q-sheng-huo-wang',
+ docs: 'https://docs.rsshub.app/routes/other#ai-q-sheng-huo-wang',
source: ['/post/new_100/', '/'],
target: '/iqnew/latest',
},
diff --git a/website/docs/routes/other.mdx b/website/docs/routes/other.mdx
index 296db6662..9979244a9 100644
--- a/website/docs/routes/other.mdx
+++ b/website/docs/routes/other.mdx
@@ -1199,6 +1199,16 @@ Specify options (in the format of query string) in parameter `routeParams` param
| xxkd | gzdt | ztfx |
+## 中国兴业银行 {#zhong-guo-xing-ye-yin-hang}
+
+### 外汇牌价 {#zhong-guo-xing-ye-yin-hang-wai-hui-pai-jia}
+
+
+ | 短格式 | 现汇买卖 | 现钞买卖 | 现汇买入 | 现汇卖出 | 现钞买入 | 现钞卖出 |
+ | ------ | -------- | -------- | -------- | -------- | -------- | -------- |
+ | short | xh | xc | xhmr | xhmc | xcmr | xcmc |
+
+
## 中国银行 {#zhong-guo-yin-hang}
### 外汇牌价 {#zhong-guo-yin-hang-wai-hui-pai-jia}