-
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.
✨ (rule): 添加微信公众号黑龙江省农村信用社的交易解析规则 #468
新增用于解析微信公众号黑龙江省农村信用社交易信息的规则和测试文件。 - 添加 `main.js` 文件,定义交易信息的解析逻辑 - 添加 `main.test.js` 文件,包含测试用例以验证解析逻辑的正确性 - 添加 `tests/黑龙江省农村信用社存入.txt` 文件,提供测试数据
- Loading branch information
1 parent
5cb2132
commit ab15ec0
Showing
3 changed files
with
74 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, Currency, formatDate, parseWechat, RuleObject, toFloat } from 'common/index.js'; | ||
|
||
// 定义源名称和需要匹配的标题数组 | ||
const SOURCE_NAME = '黑龙江省农村信用社'; | ||
const TITLE = ['交易提醒']; | ||
|
||
// 定义用于解析文本的正则表达式 | ||
const rules = [ | ||
[ | ||
/交易时间:(.*?)\n交易类型:(.*?)\n交易金额:(.*?)元\n卡内余额:.*?元/, | ||
match => { | ||
const [, time, type, money] = match; | ||
const accountNameFrom = SOURCE_NAME; | ||
|
||
return new RuleObject( | ||
type.includes('存入') ? BillType.Income : BillType.Expend, | ||
toFloat(money), | ||
'', | ||
type, | ||
accountNameFrom, | ||
'', | ||
0.0, | ||
Currency['人民币'],//2024-10-29 14:02:21 | ||
formatDate(time, 'Y-M-D h:i:s'), | ||
`微信[${SOURCE_NAME}-交易]` | ||
); | ||
} | ||
] | ||
] | ||
|
||
|
||
|
||
/** | ||
* 处理数据并返回结果 | ||
* @param {string} data - 要处理的数据 | ||
* @returns {RuleObject|null} - 处理结果对象,如果处理失败则返回null | ||
*/ | ||
export function get(data) { | ||
return parseWechat(data,rules,SOURCE_NAME,TITLE) | ||
} |
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 { testAnkioInit, testAnkio } = require('../../../../tests/TestUtils'); | ||
|
||
const { formatDate } = require('common/index.js'); | ||
|
||
testAnkioInit(get, __dirname, 'com.tencent.mm'); | ||
test('黑龙江省农村信用社存入', () => | ||
testAnkio('黑龙江省农村信用社存入', [ | ||
{ | ||
"type": "Income", | ||
"money": 100, | ||
"fee": 0, | ||
"shopName": '', | ||
"shopItem": '转账存入', | ||
"accountNameFrom": '黑龙江省农村信用社', | ||
"accountNameTo": '', | ||
"currency": 'CNY', | ||
"time": formatDate('2024-10-29 14:02:21', 'Y-M-D h:i:s'), | ||
"channel": '微信[黑龙江省农村信用社-交易]', | ||
}, | ||
])); |
13 changes: 13 additions & 0 deletions
13
src/rule/com.tencent.mm/app/微信公众号黑龙江省农村信用社/tests/黑龙江省农村信用社存入.txt
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,13 @@ | ||
{ | ||
"mMap": { | ||
"tableName": "AppMessage", | ||
"description": "交易时间:2024-10-29 14:02:21\n交易类型:转账存入\n交易金额:100.00元\n卡内余额:3649.91元", | ||
"source": "黑龙江省农村信用社", | ||
"t": 1730181742585, | ||
"arg": "msgId", | ||
"type": 5, | ||
"appId": "", | ||
"msgId": 232096, | ||
"title": "交易提醒" | ||
} | ||
} |