Compare View
Commits (2)
Changes
Showing 4 changed files Side-by-side Diff
examples/kopnus/config.json
lib/partner.js
... | ... | @@ -96,7 +96,7 @@ function _topUpRequest(task, isAdvice) { |
96 | 96 | rc: partnerRc[value[RESPONSECODE_TAG]] || '40', |
97 | 97 | message: stringify(value), |
98 | 98 | sn: (value.SN || '').replace(/;$/, '') || st24.extractSnFromMessage(value.MESSAGE, config.sn_pattern), |
99 | - amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE), | |
99 | + amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE, config.amount_pattern), | |
100 | 100 | raw: value, |
101 | 101 | misc: { |
102 | 102 | task: task |
... | ... | @@ -144,7 +144,7 @@ function _topUpInquiry(task) { |
144 | 144 | rc: partnerRc[value.RESPONSECODE] || '40', |
145 | 145 | message: stringify(value), |
146 | 146 | sn: (value.SN || '').replace(/;$/, '') || st24.extractSnFromMessage(value.MESSAGE, config.sn_pattern), |
147 | - amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE), | |
147 | + amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE, config.amount_pattern), | |
148 | 148 | raw: value, |
149 | 149 | misc: { |
150 | 150 | task: task |
lib/st24.js
1 | 1 | "use strict"; |
2 | 2 | |
3 | -function extractSnFromMessage(msg, custom_rule) { | |
3 | +function extractFromMessage(msg, default_pattern, default_match_idx, custom_rule) { | |
4 | 4 | if (!msg || typeof msg !== 'string') { |
5 | 5 | return; |
6 | 6 | } |
... | ... | @@ -13,8 +13,8 @@ function extractSnFromMessage(msg, custom_rule) { |
13 | 13 | match_idx = custom_rule.match_idx; |
14 | 14 | } |
15 | 15 | else { |
16 | - pattern = "^SN=(.*?);"; | |
17 | - match_idx = 1; | |
16 | + pattern = default_pattern; | |
17 | + match_idx = default_match_idx; | |
18 | 18 | } |
19 | 19 | |
20 | 20 | const re = new RegExp(pattern); |
... | ... | @@ -27,23 +27,21 @@ function extractSnFromMessage(msg, custom_rule) { |
27 | 27 | } else { |
28 | 28 | return; |
29 | 29 | } |
30 | + | |
30 | 31 | } |
31 | 32 | |
32 | -function extractPriceFromMsg(msg) { | |
33 | - if (!msg || typeof msg !== 'string') { | |
34 | - return; | |
35 | - } | |
33 | +function extractSnFromMessage(msg, custom_rule) { | |
34 | + const default_pattern = "^SN=(.*?);"; | |
35 | + const default_match_idx = 1; | |
36 | 36 | |
37 | - let match = msg.match(/\d,HRG=(.*?),ID=/); | |
38 | - if (!match || match.length < 2) { | |
39 | - return; | |
40 | - } | |
37 | + return extractFromMessage(msg, default_pattern, default_match_idx, custom_rule); | |
38 | +} | |
41 | 39 | |
42 | - if (!match[1]) { | |
43 | - return; | |
44 | - } | |
40 | +function extractPriceFromMsg(msg, custom_rule) { | |
41 | + const default_pattern = "\\d,HRG=(.*?),ID="; | |
42 | + const default_match_idx = 1; | |
45 | 43 | |
46 | - return parseInt(match[1].replace(/\./g, '')); | |
44 | + return extractFromMessage(msg, default_pattern, default_match_idx, custom_rule); | |
47 | 45 | } |
48 | 46 | |
49 | 47 |