Skip to content

Commit

Permalink
✨ (rule): 添加微信公众号ETC助手规则及测试 #528
Browse files Browse the repository at this point in the history
新增微信公众号ETC助手的规则解析逻辑,包括:
- 添加 `main.js` 文件,用于解析ETC扣费通知并生成账单对象
- 添加 `微信公众号ETC助手.txt` 文件,包含测试数据
- 添加 `main.test.js` 文件,用于验证规则解析的正确性

该规则支持解析ETC扣费通知中的通行流水号、通行时间、扣费时间、通行详情及金额等信息,并生成相应的账单对象。
  • Loading branch information
AnkioTomas committed Dec 25, 2024
1 parent 4e31785 commit e5232f6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/rule/com.tencent.mm/app/微信公众号ETC助手/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { BillType, Currency, formatDate, isPaymentType, parseWechat, RuleObject, toFloat } from 'common/index.js';

// 定义源名称和需要匹配的标题数组
const SOURCE = 'ETC助手';
const TITLE = ['ETC扣费成功通知'];

// 正则表达式和处理函数的映射关系
const rules = [
[
// 通行流水号:陕FF93513\n通行时间:2024-11-24 16:42:17\n扣费时间:2024-11-24 19:36:44\n通行详情:陕西新街子收费站驶入-陕西略阳收费站驶出\n金额:42.64元,出行频繁,请速领高速券
/通行流水号:(.*?)\n通行时间:(.*?)\n扣费时间:(.*?)\n通行详情:(.*?)\n金额:(.*?)元,出行频繁,请速领高速券/,
match => {
const [, shopName,t,time,shopItem,money] = match;

return new RuleObject(
BillType.Expend,
toFloat(money),
shopName,
shopItem,
'',
'',
0.0,
Currency['人民币'],
formatDate(time, 'Y-M-D h:i:s'), // 11月14日 14:45
`微信[${SOURCE}]`
)
},
],
];



/**
* 获取规则对象
* @param {string} data - JSON格式的数据
* @returns {RuleObject|null} - 规则对象,如果获取失败则返回null
*/
export function get(data) {
return parseWechat(data, rules, SOURCE, TITLE);
}
25 changes: 25 additions & 0 deletions src/rule/com.tencent.mm/app/微信公众号ETC助手/main.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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('微信公众号ETC助手', () =>
testAnkio('微信公众号ETC助手', [
{
"type": "Expend",
"money": 42.64,
"fee": 0,
"shopName": '陕FF93513',
"shopItem": '陕西新街子收费站驶入-陕西略阳收费站驶出',
"accountNameFrom": '',
"accountNameTo": '',
"currency": 'CNY',
"time": formatDate('2024-11-24 19:36:44', 'Y-M-D h:i:s'),
'channel': '微信[ETC助手]'
},

]));
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"mMap": {
"tableName": "AppMessage",
"description": "通行流水号:陕FF93513\n通行时间:2024-11-24 16:42:17\n扣费时间:2024-11-24 19:36:44\n通行详情:陕西新街子收费站驶入-陕西略阳收费站驶出\n金额:42.64元,出行频繁,请速领高速券",
"source": "ETC助手",
"t": 1732448209023,
"arg": "msgId",
"type": 5,
"appId": "",
"msgId": 668513,
"title": "ETC扣费成功通知"
}
}

0 comments on commit e5232f6

Please sign in to comment.