-
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.
添加了微信公众号Ada服务消息的到账通知规则,包括主逻辑文件、测试文件及测试数据。该规则用于解析并处理交易到账通知消息,提取交易日期、到账时间、金额及状态等信息,并生成相应的规则对象。
- Loading branch information
1 parent
6b4d0b3
commit 73dc049
Showing
3 changed files
with
62 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,37 @@ | ||
import { Currency, formatDate, parseWechat, RuleObject, toFloat } from 'common/index.js'; | ||
|
||
// 定义源名称和需要匹配的标题数组 | ||
const SOURCE = 'Ada服务消息'; | ||
const TITLE = ['交易到账通知']; | ||
|
||
// 正则表达式和处理函数的映射关系 | ||
const rules = [ | ||
[ | ||
// 交易日期:2024-12-11\n到账时间:2024-12-11 18:18:29\n到账金额:49.85元\n到账状态:交易已经到账 | ||
/交易日期:(.*?)\n到账时间:(.*?)\n到账金额:(.*?)元\n到账状态:(.*?)/, | ||
match => { | ||
const [, date, time, money, status] = match; | ||
return new RuleObject( | ||
'Income', | ||
toFloat(money), | ||
'', | ||
'', | ||
'', | ||
'', | ||
0.0, | ||
Currency['人民币'], | ||
formatDate(time, 'Y-M-D h:i:s'), // 2024-12-11 18:18:29 | ||
`微信[${SOURCE}-到账]` | ||
); | ||
} | ||
] | ||
]; | ||
|
||
/** | ||
* 获取规则对象 | ||
* @param {string} data - JSON格式的数据 | ||
* @returns {RuleObject|null} - 规则对象,如果获取失败则返回null | ||
*/ | ||
export function get (data) { | ||
return parseWechat(data, rules, SOURCE, 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,24 @@ | ||
const { get } = require('./main'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { testAnkioInit, testAnkio } = require('../../../../tests/TestUtils'); | ||
|
||
const { formatDate } = require('common/index.js'); | ||
|
||
testAnkioInit(get, __dirname, 'com.tencent.mm'); | ||
|
||
test('Ada服务消息到账通知', () => | ||
testAnkio('Ada服务消息到账通知', [ | ||
{ | ||
'type': 'Income', | ||
'money': 49.85, | ||
'fee': 0, | ||
'shopName': '', | ||
'shopItem': '', | ||
'accountNameFrom': '', | ||
'accountNameTo': '', | ||
'currency': 'CNY', | ||
'time': formatDate('2024-12-11 18:18:29', 'Y-M-D h:i:s'), | ||
'channel': '微信[Ada服务消息-到账]' | ||
} | ||
])); |
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 @@ | ||
{"mMap":{"tableName":"AppMessage","description":"交易日期:2024-12-11\n到账时间:2024-12-11 18:18:29\n到账金额:49.85元\n到账状态:交易已经到账","source":"Ada服务消息","t":1733912311922,"arg":"msgId","type":5,"appId":"","msgId":10382735,"title":"交易到账通知"}} |