Skip to content

Commit c59d7c6

Browse files
author
RikkaW
committed
改进判断
1 parent 2a52cbb commit c59d7c6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

app/src/main/java/rikka/smscodehelper/utils/SMSCode.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public int compare(String o1, String o2) {
4343

4444
// 分出每个句子 并在有关键词的句子里找验证码
4545
ArrayList<String> sentence;
46-
sentence = findCodeSentence(content);
46+
sentence = findSentence(content);
4747

4848
for (String str : sentence) {
4949
if (findKeyWord(str) != -1) {
@@ -98,7 +98,7 @@ private static int findKeyWord(String content) {
9898
return codeFindStart;
9999
}
100100

101-
private static ArrayList<String> findCodeSentence(String content) {
101+
private static ArrayList<String> findSentence(String content) {
102102
ArrayList<String> list = new ArrayList<>();
103103

104104
int last = 0;
@@ -124,9 +124,23 @@ private static boolean isCodeChar(char ch) {
124124
return ((ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'));
125125
}
126126

127+
private static String getStringAfter(String content, String string) {
128+
int startPos = content.indexOf(string);
129+
if (startPos == -1) {
130+
return content;
131+
} else {
132+
return content.substring(startPos);
133+
}
134+
}
135+
127136
private static String findCode(String content) {
128137
content += " ";
129138

139+
// 如果有冒号
140+
content = getStringAfter(content, ":");
141+
content = getStringAfter(content, ":");
142+
143+
130144
int startPos = -1;
131145
for (int i = 0; i < content.length(); i++) {
132146
char ch = content.charAt(i);

app/src/test/java/rikka/smscodehelper/utils/SMSCodeTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@ private void setSmsContact() {
4141
SmsContactCodeMap.put(SMSContact5, "060973");
4242
String SMSContact6 = "您在付款,为防诈骗千万不要告诉他人验证码505513,商户为汇付天下,金额80元。如有疑问请停止操作。(短信编号:245747)【工商银行】";
4343
SmsContactCodeMap.put(SMSContact6, "505513");
44+
String SMSContact7 = "任何向你索要验证码的都是骗子,千万别给!您正在向www(尾号4832)转账,验证码370000,100元。";
45+
SmsContactCodeMap.put(SMSContact7, "370000");
4446
}
4547
}

0 commit comments

Comments
 (0)