-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增北京银行短信支出解析规则,支持解析账户支付信息并生成对应账单对象。包含以下内容: - 正则表达式匹配短信内容,提取账户号、日期、支付方式、金额、余额及对方户名等信息。 - 根据解析结果生成账单对象,设置支出类型、支付渠道、商户名称等属性。 - 添加单元测试,验证解析逻辑的正确性。
- Loading branch information
1 parent
0288835
commit 95429cf
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": '北京银行[支出]', | ||
}, | ||
])); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |