Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
首航-临时账号
api
Commits
b29be75d
Commit
b29be75d
authored
Aug 25, 2020
by
java-李谡
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
短信发送
parent
362dad5d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
111 deletions
+101
-111
SecurityPropertyPlaceholderConfigurer.java
src/com/ejweb/core/conf/SecurityPropertyPlaceholderConfigurer.java
+5
-4
Util.java
src/com/ejweb/core/util/Util.java
+78
-104
ShortMessageService.java
src/com/ejweb/modules/message/service/ShortMessageService.java
+18
-3
No files found.
src/com/ejweb/core/conf/SecurityPropertyPlaceholderConfigurer.java
View file @
b29be75d
...
...
@@ -4,6 +4,7 @@
package
com
.
ejweb
.
core
.
conf
;
import
com.ejweb.core.security.DES3Utils
;
import
com.ejweb.core.util.Util
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
;
...
...
@@ -78,9 +79,9 @@ public class SecurityPropertyPlaceholderConfigurer extends PropertyPlaceholderCo
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
DES3Utils
.
encrypt
(
"foctest"
,
CONF_DESC_KEY
));
System
.
out
.
println
(
DES3Utils
.
decrypt
(
"dc6788486fc8fa46bdc79e88019874d2dba29c9323df0d41d422c89b73b481946acb4985946fc04c9e83784b79a27bf935e0dbe240259eb88daa2a68d7c26b3c05ef21acf1ec90e77072592f9207bf97"
,
CONF_DESC_KEY
));
System
.
out
.
println
(
DES3Utils
.
decrypt
(
"776b3d2f912b12f8"
,
CONF_DESC_KEY
));
System
.
out
.
println
(
DES3Utils
.
decrypt
(
"
6f2237c231b1464c6474030c906ec914
"
,
CONF_DESC_KEY
));
//
System.out.println(DES3Utils.encrypt("foctest", CONF_DESC_KEY));
//
System.out.println(DES3Utils.decrypt("dc6788486fc8fa46bdc79e88019874d2dba29c9323df0d41d422c89b73b481946acb4985946fc04c9e83784b79a27bf935e0dbe240259eb88daa2a68d7c26b3c05ef21acf1ec90e77072592f9207bf97", CONF_DESC_KEY));
//
System.out.println(DES3Utils.decrypt("776b3d2f912b12f8", CONF_DESC_KEY));
System
.
out
.
println
(
DES3Utils
.
decrypt
(
"
f5c9d35c1df1eb31c0f15d23ee5af33d15ee14d1133b16ae580893ec603fc77c0057d3cccb34407d0505fc99a849cd7ee060d2c605d68b21ea7fea2a325dd4026e7f13e65e216d967bc7696f608fe56ef11ae4801b727c51d09bc4beb44b24f0
"
,
CONF_DESC_KEY
));
}
}
src/com/ejweb/core/util/Util.java
View file @
b29be75d
...
...
@@ -20,14 +20,19 @@ import java.io.Writer;
import
java.security.SecureRandom
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
Util
{
static
Pattern
p
=
Pattern
.
compile
(
"^1(3([0-35-9]\\d|4[1-8])|4[14-9]\\d|5([0125689]\\d|7[1-79])|66\\d|7[2-35-8]\\d|8\\d{2}|9[89]\\d)\\d{7}$"
);
public
static
String
phoneNumberFormat
(
String
phone
)
{
if
(
phone
==
null
)
if
(
phone
==
null
)
{
return
null
;
}
int
len
=
phone
.
length
();
if
(
len
>=
8
)
{
// return phone.replaceAll("(\\d{3})\\d{4}(\\d+)","$1****$2");// 正则匹配
return
phone
.
substring
(
0
,
3
)
+
"****"
+
phone
.
substring
(
7
,
len
);
// 字符串拼接
}
return
phone
;
...
...
@@ -42,16 +47,21 @@ public class Util {
* @time 2017年3月24日
*/
public
static
String
getShowPhone
(
String
phone
)
{
if
(
StringUtils
.
isEmpty
(
phone
))
// 未知
if
(
StringUtils
.
isEmpty
(
phone
))
{
return
""
;
if
(
phone
.
startsWith
(
"1"
)
&&
phone
.
length
()
==
11
)
// 手机号
}
if
(
phone
.
startsWith
(
"1"
)
&&
phone
.
length
()
==
11
)
{
return
phone
;
if
(
phone
.
startsWith
(
"01"
)
&&
phone
.
length
()
==
12
)
// 手机号
}
if
(
phone
.
startsWith
(
"01"
)
&&
phone
.
length
()
==
12
)
{
return
phone
.
substring
(
1
);
if
(
phone
.
startsWith
(
"001"
)
&&
phone
.
length
()
==
13
)
// 手机号
}
if
(
phone
.
startsWith
(
"001"
)
&&
phone
.
length
()
==
13
)
{
return
phone
.
substring
(
2
);
if
(
phone
.
startsWith
(
"5"
)
&&
phone
.
length
()
==
4
)
// 座机号
}
if
(
phone
.
startsWith
(
"5"
)
&&
phone
.
length
()
==
4
)
{
return
"6961"
+
phone
;
}
return
phone
;
// 座机
}
...
...
@@ -64,16 +74,22 @@ public class Util {
* @time 2017年3月19日
*/
public
static
String
getPhoneType
(
String
phone
)
{
if
(
StringUtils
.
isEmpty
(
phone
))
// 未知
// 未知
if
(
StringUtils
.
isEmpty
(
phone
))
{
return
"UNKNOWN"
;
if
(
phone
.
startsWith
(
"1"
)
&&
phone
.
length
()
==
11
)
// 手机号
}
if
(
phone
.
startsWith
(
"1"
)
&&
phone
.
length
()
==
11
)
{
return
"MOBILE"
;
if
(
phone
.
startsWith
(
"01"
)
&&
phone
.
length
()
==
12
)
// 手机号
}
if
(
phone
.
startsWith
(
"01"
)
&&
phone
.
length
()
==
12
)
{
return
"MOBILE"
;
if
(
phone
.
startsWith
(
"001"
)
&&
phone
.
length
()
==
13
)
// 手机号
}
if
(
phone
.
startsWith
(
"001"
)
&&
phone
.
length
()
==
13
)
{
return
"MOBILE"
;
if
(
phone
.
startsWith
(
"6"
)
&&
phone
.
length
()
==
4
)
// 华为短号
}
if
(
phone
.
startsWith
(
"6"
)
&&
phone
.
length
()
==
4
)
{
return
"HWNUBMER"
;
}
return
"PHONE"
;
// 座机
}
...
...
@@ -117,8 +133,9 @@ public class Util {
}
public
static
int
parseInt
(
String
val
,
int
want
)
{
if
(
StringUtils
.
isEmpty
(
val
))
if
(
StringUtils
.
isEmpty
(
val
))
{
return
want
;
}
try
{
return
Integer
.
parseInt
(
val
);
}
catch
(
Exception
e
)
{
...
...
@@ -243,8 +260,9 @@ public class Util {
* @time 2016年12月12日
*/
public
static
String
formatedMobile
(
String
mobile
)
{
if
(
mobile
==
null
||
mobile
.
length
()
==
0
)
if
(
mobile
==
null
||
mobile
.
length
()
==
0
)
{
return
mobile
;
}
try
{
String
[]
species
=
mobile
.
split
(
"\\s+"
);
// 只使用第一个手机号
if
(
species
.
length
>
1
&&
species
[
0
].
matches
(
"1\\d+"
)
&&
species
[
1
].
matches
(
"1\\d+"
))
{
...
...
@@ -291,8 +309,9 @@ public class Util {
* @time 2016年12月12日
*/
public
static
String
formatedWorkPhone
(
String
workPhone
)
{
if
(
workPhone
==
null
||
workPhone
.
length
()
==
0
)
if
(
workPhone
==
null
||
workPhone
.
length
()
==
0
)
{
return
workPhone
;
}
try
{
workPhone
=
workPhone
.
replaceAll
(
"[^\\d|+]+"
,
""
);
if
(
workPhone
.
matches
(
"0+"
))
{
// 非座机号设置为空
...
...
@@ -357,7 +376,6 @@ public class Util {
errors
.
close
();
}
catch
(
Exception
e1
)
{
// TODO Auto-generated catch block
// e1.printStackTrace();
}
return
error
;
}
...
...
@@ -372,12 +390,15 @@ public class Util {
* @time 2016年12月11日
*/
public
static
String
getAbsoluteUrl
(
String
url
,
String
want
)
{
if
(
StringUtils
.
isBlank
(
url
))
if
(
StringUtils
.
isBlank
(
url
))
{
return
getAbsoluteUrl
(
want
);
if
(
url
.
startsWith
(
"http://"
)
||
url
.
startsWith
(
"https://"
))
// 绝对路径
}
if
(
url
.
startsWith
(
"http://"
)
||
url
.
startsWith
(
"https://"
))
{
return
url
;
if
(
GConstants
.
FILE_PREFIX_URL
.
endsWith
(
"/"
)
&&
url
.
startsWith
(
"/"
))
// 相对路径
}
if
(
GConstants
.
FILE_PREFIX_URL
.
endsWith
(
"/"
)
&&
url
.
startsWith
(
"/"
))
{
return
GConstants
.
FILE_PREFIX_URL
+
url
.
replaceAll
(
"^/+"
,
""
);
}
return
GConstants
.
FILE_PREFIX_URL
+
url
;
}
...
...
@@ -390,12 +411,17 @@ public class Util {
* @time 2016年9月1日
*/
public
static
String
getAbsoluteUrl
(
String
url
)
{
if
(
StringUtils
.
isBlank
(
url
))
if
(
StringUtils
.
isBlank
(
url
))
{
return
""
;
if
(
url
.
startsWith
(
"http://"
)
||
url
.
startsWith
(
"https://"
))
// 绝对路径
}
// 绝对路径
if
(
url
.
startsWith
(
"http://"
)
||
url
.
startsWith
(
"https://"
))
{
return
url
;
if
(
GConstants
.
FILE_PREFIX_URL
.
endsWith
(
"/"
)
&&
url
.
startsWith
(
"/"
))
// 相对路径
}
// 相对路径
if
(
GConstants
.
FILE_PREFIX_URL
.
endsWith
(
"/"
)
&&
url
.
startsWith
(
"/"
))
{
return
GConstants
.
FILE_PREFIX_URL
+
url
.
replaceAll
(
"^/+"
,
""
);
}
return
GConstants
.
FILE_PREFIX_URL
+
url
;
}
...
...
@@ -408,10 +434,10 @@ public class Util {
* @time 2017年1月13日
*/
public
static
String
getRelativePath
(
String
url
)
{
if
(
StringUtils
.
isBlank
(
url
))
if
(
StringUtils
.
isBlank
(
url
))
{
return
""
;
}
return
url
.
replaceAll
(
GConstants
.
FILE_PREFIX_URL
,
""
);
// return url;
}
/**
...
...
@@ -421,16 +447,9 @@ public class Util {
* @return
*/
public
static
String
getExtensionName
(
String
filename
)
{
// if(filename == null || filename.length() == 0)
// return null;
// if(filename.contains(".")){
// String[] species = filename.split("\\.");
// return "."+species[species.length-1].toLowerCase();
// }
// return null;
if
(
filename
==
null
||
filename
.
length
()
==
0
)
if
(
filename
==
null
||
filename
.
length
()
==
0
)
{
return
""
;
}
int
startIndex
=
filename
.
lastIndexOf
(
"."
)
+
1
;
int
length
=
filename
.
length
();
if
(
startIndex
>
0
&&
startIndex
<
length
)
{
...
...
@@ -449,8 +468,9 @@ public class Util {
* @time 2017年2月10日
*/
public
static
String
getFileExtensionName
(
String
filename
)
{
if
(
filename
==
null
||
filename
.
length
()
==
0
)
if
(
filename
==
null
||
filename
.
length
()
==
0
)
{
return
""
;
}
int
startIndex
=
filename
.
lastIndexOf
(
"."
)
+
1
;
int
length
=
filename
.
length
();
if
(
startIndex
>
0
&&
startIndex
<
length
)
{
...
...
@@ -479,10 +499,11 @@ public class Util {
for
(
int
i
=
0
;
i
<
maxlength
;
i
++)
{
// if the checked version is too short
if
(
checkVersion
.
length
<=
i
&&
originalVersion
[
i
].
equals
(
0
))
&&
originalVersion
[
i
].
equals
(
0
))
{
return
true
;
else
if
(
checkVersion
.
length
<=
i
)
}
else
if
(
checkVersion
.
length
<=
i
)
{
return
false
;
}
// if the original version is long enough
if
(
originalVersion
.
length
>
i
)
{
...
...
@@ -552,7 +573,6 @@ public class Util {
public
static
String
getGenericCode
()
{
try
{
return
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
).
toLowerCase
();
}
catch
(
Exception
e
)
{
// TODO: handle exception
...
...
@@ -561,8 +581,9 @@ public class Util {
}
public
static
boolean
isrContainValues
(
JSONArray
data
,
String
...
values
)
{
if
(
data
==
null
||
values
==
null
)
if
(
data
==
null
||
values
==
null
)
{
return
false
;
}
int
count
=
0
;
int
len
=
data
.
size
();
for
(
String
val
:
values
)
{
...
...
@@ -579,8 +600,9 @@ public class Util {
}
public
static
boolean
isPraramerValue
(
JSONObject
data
,
String
...
colums
)
{
if
(
data
==
null
||
colums
==
null
)
if
(
data
==
null
||
colums
==
null
)
{
return
false
;
}
for
(
String
colum
:
colums
)
{
if
(
data
.
containsKey
(
colum
)
==
false
)
{
return
false
;
...
...
@@ -590,8 +612,9 @@ public class Util {
}
public
static
boolean
isInValue
(
String
val
,
String
...
vals
)
{
if
(
val
==
null
||
vals
==
null
)
if
(
val
==
null
||
vals
==
null
)
{
return
false
;
}
for
(
String
v
:
vals
)
{
if
(
val
.
equals
(
v
))
{
return
true
;
...
...
@@ -607,19 +630,11 @@ public class Util {
* @param max
* @return
*/
// public static int getRandom(int min, int max) {
//
// int randomNumber = (int)(Math.random()*(max-min+3)+min);
// while (randomNumber == min || randomNumber == max+2) {
// randomNumber = (int)(Math.random()*(max-min+3)+min);
// }
// return randomNumber-1;
// }
public
static
int
getRandom
(
int
min
,
int
max
)
{
int
randomNumber
;
try
{
SecureRandom
number
=
SecureRandom
.
getInstance
(
"SHA1PRNG"
);
randomNumber
=
(
number
.
nextInt
(
max
-
min
+
3
)
+
min
);
//(int)(Math.random()*(max-min+3)+min);
randomNumber
=
(
number
.
nextInt
(
max
-
min
+
3
)
+
min
);
while
(
randomNumber
==
min
||
randomNumber
==
max
+
2
)
{
randomNumber
=
(
number
.
nextInt
(
max
-
min
+
3
)
+
min
);
}
...
...
@@ -643,8 +658,9 @@ public class Util {
*/
public
static
String
getOnlineIP
(
HttpServletRequest
request
)
{
//获取X-Forwarded-For
if
(
request
==
null
)
if
(
request
==
null
)
{
return
"Unknown"
;
}
String
ip
=
request
.
getHeader
(
"X-Real-IP"
);
if
(
StringUtils
.
isBlank
(
ip
)
||
"Unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"x-forwarded-for"
);
...
...
@@ -660,8 +676,9 @@ public class Util {
}
}
}
if
(
StringUtils
.
isBlank
(
ip
))
if
(
StringUtils
.
isBlank
(
ip
))
{
return
"Unknown"
;
}
return
ip
.
split
(
","
)[
0
];
}
...
...
@@ -696,34 +713,6 @@ public class Util {
}
/**
* 固话修改规则
* @param workPhone
* @return
*/
// public static String formatPhone(String workPhone) {
// if (StringUtils.isBlank(workPhone)) {
// return workPhone;
// }
// if(workPhone.startsWith("+")){// 外国号码前面加拨3个000
// workPhone = workPhone.replace("+", "000");
// }
// if(workPhone.startsWith("0106961")){// 1、010 6961 xxxx -> xxxx 内部号码,直接拨短号
//
// workPhone = workPhone.replace("0106961", "");
// } else if(workPhone.startsWith("6961")){// 2、6961 xxxx -> xxxx 内部号码,直接拨短号
//
// workPhone = workPhone.replace("6961", "");
// } else if(workPhone.startsWith("010")){// 3、010 xxxx xxxx -> 0 xxxx xxxx 北京号码,去掉区号,加拨0
//
// workPhone = workPhone.replace("010", "0");
// } else {// 4、xxx xxxx xxxx -> 0 xxx xxxx xxxx 国内非北京号码,加拨0
//
// workPhone = "0"+workPhone;
// }
// return workPhone;
// }
/**
* 得到Uc账号,判断规则,如果同时满足前缀,后缀,直接返回该账号。否则按照前缀,后缀规则,添加后返回账号
*
* @return
...
...
@@ -745,32 +734,17 @@ public class Util {
return
str
;
}
// public static void main(String[] args){
// Map<Integer, Integer> counter = new HashMap<>();
// for(int i=0;i<100000;i++){
// int a = getRandom(0,200);
// if(counter.get(a) == null){
// counter.put(a, 1);
// } else{
//
// counter.put(a, counter.get(a)+1);
// }
// }
// for(Entry<Integer, Integer> a:counter.entrySet()){
//
// System.out.println(a.getKey()+"=>"+a.getValue());
// }
// String email = "renmb@bbdtek.com";
// System.out.println(email.substring(0, email.indexOf("@")));
// System.out.println(phoneNumberFormat("13357826761"));
//// System.out.println(Util.getExtensionName("照片 320.JPG"));
//// System.out.println("结果:"+GConstants.FILE_FILTERS.get(Util.getExtensionName("照片 320.JPG").toLowerCase()) == null);
//// System.out.println(JSON.toJSONString(Util.updateGroupAvatar("4169", "792280723629314048")));
//// System.out.println(Util.getFileExtensionName("a.ah"));
//// System.out.println(Util.formatedWorkPhone("089888693785"));
//// System.out.println(Util.getRelativePath("https://ifos.jdair.net/foc/static/2017/01/13/actuals/images/user/jpg/23198d70826ac171ee03ed5cd3d14c27.jpg"));
// }
public
static
boolean
phoneReg
(
String
mobile
)
{
Matcher
m
=
p
.
matcher
(
mobile
);
boolean
isMatch
=
m
.
matches
();
return
isMatch
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
Util
.
validatePassword
(
"Hjwx#1234"
,
"247fd14c5d908a8312dc23e175e86c4f2e011fb76e08827cd65c962b"
));
System
.
out
.
println
(
phoneReg
(
"18501501226"
));
System
.
out
.
println
(
phoneReg
(
"018501501226"
));
System
.
out
.
println
(
phoneReg
(
"0018501501226"
));
System
.
out
.
println
(
phoneReg
(
"51018501501226"
));
}
}
src/com/ejweb/modules/message/service/ShortMessageService.java
View file @
b29be75d
...
...
@@ -11,6 +11,7 @@ import com.ejweb.core.conf.GConstants;
import
com.ejweb.core.fetcher.FetchEntity
;
import
com.ejweb.core.fetcher.HCFetcher
;
import
com.ejweb.core.util.IdWorker
;
import
com.ejweb.core.util.Util
;
import
com.ejweb.modules.message.bean.ShortMsgBean
;
import
com.ejweb.modules.message.bean.ShortMsgListBean
;
import
com.ejweb.modules.message.bean.ShortMsgUserListBean
;
...
...
@@ -57,20 +58,34 @@ public class ShortMessageService extends BaseService<ShortMessageDao> {
}
StringBuilder
builder
=
new
StringBuilder
();
String
[]
phones
=
phone
.
split
(
",|,"
);
boolean
abroadPhone
=
false
;
for
(
int
i
=
0
,
len
=
phones
.
length
;
i
<
len
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
","
);
}
builder
.
append
(
phones
[
i
].
replaceAll
(
"^0+"
,
""
));
//判断号码去掉开头的0之后是否是国内号码
String
phone1
=
phones
[
i
].
replaceAll
(
"^0+"
,
""
);
if
(
Util
.
phoneReg
(
phone1
))
{
builder
.
append
(
phone1
);
}
else
{
builder
.
append
(
phones
[
i
]);
abroadPhone
=
true
;
}
}
//电话号码去除空格,否则导致发送失败
phone
=
builder
.
toString
().
trim
();
if
(
StringUtils
.
isEmpty
(
phone
))
{
return
false
;
}
String
url
=
""
;
if
(
abroadPhone
)
{
url
=
GConstants
.
JDAIR_SMS_API
+
"&mobile="
+
phone
+
"&msg="
+
URLEncoder
.
encode
(
bean
.
getMessage
(),
"UTF-8"
)
+
"&isInternetPhone=1"
;
}
else
{
url
=
GConstants
.
JDAIR_SMS_API
+
"&mobile="
+
phone
+
"&msg="
+
URLEncoder
.
encode
(
bean
.
getMessage
(),
"UTF-8"
);
}
logger
.
info
(
"短信地址:"
+
url
);
HCFetcher
fetcher
=
HCFetcher
.
getInstance
();
FetchEntity
entity
=
fetcher
.
post
(
GConstants
.
JDAIR_SMS_API
+
"&mobile="
+
phone
+
"&msg="
+
URLEncoder
.
encode
(
bean
.
getMessage
(),
"UTF-8"
)
,
null
);
FetchEntity
entity
=
fetcher
.
post
(
url
,
null
);
if
(
entity
!=
null
&&
entity
.
isSuccess
())
{
String
resultStr
=
entity
.
getContent
(
"utf-8"
);
// 成功获取数据
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment