Skip to content

Commit

Permalink
✨ (rule): 新增微信公众号Ada服务消息到账通知规则 #598
Browse files Browse the repository at this point in the history
添加了微信公众号Ada服务消息的到账通知规则,包括主逻辑文件、测试文件及测试数据。该规则用于解析并处理交易到账通知消息,提取交易日期、到账时间、金额及状态等信息,并生成相应的规则对象。
  • Loading branch information
AnkioTomas committed Dec 28, 2024
1 parent 6b4d0b3 commit 73dc049
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/rule/com.tencent.mm/app/微信公众号Ada服务消息/main.js
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);
}
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服务消息-到账]'
}
]));
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":"交易到账通知"}}

0 comments on commit 73dc049

Please sign in to comment.