-
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.
新增重庆公积金中心短信解析规则,包括: - 新增 `main.js` 文件,实现短信解析逻辑 - 新增 `main.test.js` 文件,添加单元测试 - 新增 `重庆公积金中心收入.txt` 文件,作为测试数据
- Loading branch information
1 parent
c271cbd
commit 391ebe0
Showing
3 changed files
with
63 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,43 @@ | ||
import { formatDate, isPaymentType, RuleObject, splitSms, toFloat } from 'common/index.js'; | ||
|
||
let senderName = '重庆公积金中心'; | ||
|
||
// 正则表达式和处理函数的映射关系 | ||
const rules = [ | ||
[ | ||
//【重庆公积金中心】您的个人账户于2024年12月13日汇缴公积金1980元,汇缴年月为202412, 余额9900元。 | ||
/您的个人账户于(\d{4}年\d{1,2}月\d{1,2}日)(.*?)公积金(.*?)元,汇缴年月为(\d{6}), 余额(.*?)元。/, | ||
match => { | ||
let [, date, type, money, month, balance] = match; | ||
|
||
let obj = new RuleObject(); | ||
|
||
let { matchType, typeName } = isPaymentType(type); | ||
|
||
obj.money = toFloat(money); | ||
obj.channel = `${senderName}[${typeName}]`; | ||
obj.shopItem = type; | ||
obj.time = formatDate(date, 'Y年M月D日'); | ||
obj.type = matchType; | ||
obj.accountNameFrom = `${senderName}`; | ||
return obj; | ||
} | ||
] | ||
]; | ||
|
||
/** | ||
* @param {string} data - JSON格式的数据 | ||
* @returns {RuleObject|null} - 规则对象,如果获取失败则返回null | ||
*/ | ||
export function get (data) { | ||
let { sender, bankName, text, t } = splitSms(data); | ||
if (bankName !== senderName) { | ||
return null; | ||
} | ||
for (let rule of rules) { | ||
const match = text.match(rule[0]); | ||
if (match) { | ||
return rule[1](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,19 @@ | ||
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': 'Income', | ||
'money': 1980, | ||
'fee': 0, | ||
'shopName': '', | ||
'shopItem': '汇缴', | ||
'accountNameFrom': '重庆公积金中心', | ||
'accountNameTo': '', | ||
'currency': 'CNY', | ||
'time': formatDate('2024年12月13日', 'Y年M月D日'), | ||
'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 @@ | ||
{"sender":"12329","body":"【重庆公积金中心】您的个人账户于2024年12月13日汇缴公积金1980元,汇缴年月为202412, 余额9900元。","t":1734060747038} |