Skip to content

Commit

Permalink
✨ (rule): 添加北京银行短信支出解析规则及相关测试 #473
Browse files Browse the repository at this point in the history
新增北京银行短信支出解析规则,支持解析账户支付信息并生成对应账单对象。包含以下内容:
- 正则表达式匹配短信内容,提取账户号、日期、支付方式、金额、余额及对方户名等信息。
- 根据解析结果生成账单对象,设置支出类型、支付渠道、商户名称等属性。
- 添加单元测试,验证解析逻辑的正确性。
  • Loading branch information
AnkioTomas committed Dec 18, 2024
1 parent 0288835 commit 95429cf
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/rule/com.android.phone/app/短信北京银行/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { BillType, formatDate, RuleObject, splitSms, toFloat } from 'common/index.js';

let rules = [
{
// 您账户0561于11月6日13:03通过财付通支付1.00元。活期余额13773.30元。对方户名:微信红包。
'regex':
/您账户(\d{4})于(.*?)通过(.*?)支付(.*?)元。活期余额(.*?)元。对方户名:(.*?)。/,
'match': (match,t) => {
let [, number, date, shopItem, money,,shopName ] = match;
let obj = new RuleObject();

obj.money = toFloat(money);

let type = BillType.Expend;
let typeName = "支出";
obj.channel = `北京银行[${typeName}]`;
obj.shopItem = shopItem;
obj.time = t;
obj.shopName = shopName;

obj.type = type;

obj.accountNameFrom = `北京银行(${number})`;
return obj;
}
},
];

export function get (data) {
let { sender, bankName, text, t } = splitSms(data);
if (bankName !== '北京银行') {
return null;
}
for (let rule of rules) {
const match = text.match(rule.regex);
if (match) {
return rule.match(match,t);
}
}
}
21 changes: 21 additions & 0 deletions src/rule/com.android.phone/app/短信北京银行/main.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { get } = require('./main');
const { testAnkio, testAnkioInit } = require('../../../../tests/TestUtils');
const { formatDate } = require('common/Time.js');
testAnkioInit(get, __dirname, 'com.android.phone');
test('北京银行支出', () =>
testAnkio('北京银行支出', [
{
"type": "Expend",
"money": 1,
"fee": 0,
"shopName": '微信红包',
"shopItem": '财付通',
"accountNameFrom": '北京银行(0561)',
"accountNameTo": '',
"currency": 'CNY',
"time": 1730869418140,
"channel": '北京银行[支出]',
},
]));


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sender": "95526",
"body": "【北京银行】您账户0561于11月6日13:03通过财付通支付1.00元。活期余额13773.30元。对方户名:微信红包。",
"t": 1730869418140
}

0 comments on commit 95429cf

Please sign in to comment.