Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-execute-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8386fe38
authored
Sep 07, 2023
by
叶立庆
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]短信发送服务调用
1 parent
4717190b
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
157 additions
and
22 deletions
platform-execute-api/src/main/java/cn/com/glsx/execute/modules/model/RopResponseDTO.java → platform-execute-api/src/main/java/cn/com/glsx/execute/modules/model/rop/RopResponseDTO.java
platform-execute-api/src/main/java/cn/com/glsx/execute/modules/model/sms/SmsResponseDTO.java
platform-execute/src/main/java/cn/com/glsx/execute/modules/service/proxy/SendMessageService.java
platform-execute/src/main/java/cn/com/glsx/execute/utils/MD5.java
platform-execute/src/main/java/cn/com/glsx/execute/utils/RopHttpUtil.java
platform-execute/src/main/java/cn/com/glsx/execute/utils/RopUtils.java
platform-execute/src/test/java/cn/com/glsx/cn/com/glsx/Utils/RopHttpUtilTest.java
platform-execute/src/test/java/cn/com/glsx/cn/com/glsx/Utils/SendMessageServiceTest.java
platform-execute-api/src/main/java/cn/com/glsx/execute/modules/model/RopResponseDTO.java
→
platform-execute-api/src/main/java/cn/com/glsx/execute/modules/model/
rop/
RopResponseDTO.java
View file @
8386fe3
package
cn
.
com
.
glsx
.
execute
.
modules
.
model
;
package
cn
.
com
.
glsx
.
execute
.
modules
.
model
.
rop
;
import
lombok.Data
;
...
...
platform-execute-api/src/main/java/cn/com/glsx/execute/modules/model/sms/SmsResponseDTO.java
0 → 100644
View file @
8386fe3
package
cn
.
com
.
glsx
.
execute
.
modules
.
model
.
sms
;
import
lombok.Data
;
import
lombok.ToString
;
/**
* @Author yelq
* @Version 1.0
* @Description:
* @Date 2023/9/7 17:53
*/
@ToString
@Data
public
class
SmsResponseDTO
{
private
String
code
;
private
String
message
;
private
Object
datas
;
}
platform-execute/src/main/java/cn/com/glsx/execute/modules/service/proxy/SendMessageService.java
View file @
8386fe3
package
cn
.
com
.
glsx
.
execute
.
modules
.
service
.
proxy
;
import
cn.com.glsx.execute.modules.model.sms.SmsResponseDTO
;
import
cn.com.glsx.execute.utils.RopHttpUtil
;
import
cn.com.glsx.framework.core.enums.DefaultErrorEnum
;
import
cn.com.glsx.framework.core.exception.RpcServiceException
;
...
...
@@ -28,8 +29,8 @@ public class SendMessageService {
* @param type 类型
* @param context 发送内容
*/
public
void
sendMessage
(
String
phone
,
String
source
,
String
type
,
String
context
)
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>(
4
);
public
SmsResponseDTO
sendMessage
(
String
phone
,
String
source
,
String
type
,
String
context
)
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<>(
4
);
try
{
params
.
add
(
"phone"
,
phone
);
params
.
add
(
"source"
,
source
);
...
...
@@ -37,11 +38,12 @@ public class SendMessageService {
params
.
add
(
"type"
,
type
);
params
.
add
(
"context"
,
context
);
log
.
info
(
"短信发送参数:{}"
,
JSON
.
toJSONString
(
params
));
S
tring
post
=
RopHttpUtil
.
postE
(
params
,
String
.
class
,
sendMessageUrl
+
"?method="
+
sendMessageMethod
,
sendMessageMethod
,
null
);
S
msResponseDTO
post
=
RopHttpUtil
.
postE
(
params
,
SmsResponseDTO
.
class
,
sendMessageUrl
+
"?method="
+
sendMessageMethod
,
sendMessageMethod
,
null
);
log
.
info
(
"发送短信结果{}"
,
post
);
return
post
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
info
(
"发送短信异常
,{}
"
,
e
);
log
.
info
(
"发送短信异常
:
"
,
e
);
throw
new
RpcServiceException
(
DefaultErrorEnum
.
SERVER_ERROR
);
}
}
...
...
platform-execute/src/main/java/cn/com/glsx/execute/utils/MD5.java
0 → 100644
View file @
8386fe3
package
cn
.
com
.
glsx
.
execute
.
utils
;
import
java.security.MessageDigest
;
/**
* @author zhouhaibao
* @version 1.0
* @description: TODO
* @date 2021/11/23 21:39
*/
public
class
MD5
{
/**
* 32位MD5加密算法
* @param s
* @return
*/
public
static
String
convert32
(
String
s
){
char
hexChars
[]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
try
{
byte
[]
bytes
=
s
.
getBytes
();
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
md
.
update
(
bytes
);
bytes
=
md
.
digest
();
int
j
=
bytes
.
length
;
char
[]
chars
=
new
char
[
j
*
2
];
int
k
=
0
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
byte
b
=
bytes
[
i
];
chars
[
k
++]
=
hexChars
[
b
>>>
4
&
0xf
];
chars
[
k
++]
=
hexChars
[
b
&
0xf
];
}
return
new
String
(
chars
);
}
catch
(
Exception
e
){
return
null
;
}
}
/**
* 16位MD5加密算法
* @param s
* @return
*/
public
static
String
convert16
(
String
s
){
char
hexChars
[]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
try
{
byte
[]
bytes
=
s
.
getBytes
();
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
md
.
update
(
bytes
);
bytes
=
md
.
digest
();
int
j
=
bytes
.
length
;
char
[]
chars
=
new
char
[
j
*
2
];
int
k
=
0
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
byte
b
=
bytes
[
i
];
chars
[
k
++]
=
hexChars
[
b
>>>
4
&
0xf
];
chars
[
k
++]
=
hexChars
[
b
&
0xf
];
}
return
new
String
(
chars
).
substring
(
8
,
24
);
}
catch
(
Exception
e
){
return
null
;
}
}
}
platform-execute/src/main/java/cn/com/glsx/execute/utils/RopHttpUtil.java
View file @
8386fe3
...
...
@@ -103,7 +103,7 @@ public class RopHttpUtil {
params
.
remove
(
entry
.
getKey
());
}
}
String
sign
=
RopUtils
.
sign
(
params
.
toSingleValueMap
()
,
appKeyEnum
==
null
?
secret
:
appKeyEnum
.
getSecret
());
String
sign
=
RopUtils
.
sign
E
(
params
.
toSingleValueMap
(),
null
,
appKeyEnum
==
null
?
secret
:
appKeyEnum
.
getSecret
());
params
.
add
(
"sign"
,
sign
);
return
new
RestTemplate
().
postForObject
(
baseurl
,
params
,
responseType
);
}
...
...
platform-execute/src/main/java/cn/com/glsx/execute/utils/RopUtils.java
View file @
8386fe3
...
...
@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.StandardCharsets
;
import
java.security.GeneralSecurityException
;
import
java.security.MessageDigest
;
import
java.util.*
;
...
...
@@ -16,17 +17,17 @@ public class RopUtils {
}
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
String
secret
)
{
return
sign
(
paramValues
,
(
List
)
null
,
secret
);
return
sign
(
paramValues
,
null
,
secret
);
}
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
List
<
String
>
ignoreParamNames
,
String
secret
)
{
try
{
StringBuilder
sb
=
new
StringBuilder
();
List
<
String
>
paramNames
=
new
ArrayList
(
paramValues
.
size
());
List
<
String
>
paramNames
=
new
ArrayList
<>
(
paramValues
.
size
());
paramNames
.
addAll
(
paramValues
.
keySet
());
Iterator
var5
;
String
paramName
;
if
(
ignoreParamNames
!=
null
&&
ignoreParamNames
.
size
()
>
0
)
{
if
(
ignoreParamNames
!=
null
&&
!
ignoreParamNames
.
isEmpty
()
)
{
var5
=
ignoreParamNames
.
iterator
();
while
(
var5
.
hasNext
())
{
...
...
@@ -41,7 +42,7 @@ public class RopUtils {
while
(
var5
.
hasNext
())
{
paramName
=
(
String
)
var5
.
next
();
sb
.
append
(
paramName
).
append
(
(
String
)
paramValues
.
get
(
paramName
));
sb
.
append
(
paramName
).
append
(
paramValues
.
get
(
paramName
));
}
sb
.
append
(
secret
);
...
...
@@ -55,31 +56,25 @@ public class RopUtils {
public
static
String
utf8Encoding
(
String
value
,
String
sourceCharsetName
)
{
try
{
return
new
String
(
value
.
getBytes
(
sourceCharsetName
),
"UTF-8"
);
return
new
String
(
value
.
getBytes
(
sourceCharsetName
),
StandardCharsets
.
UTF_8
);
}
catch
(
UnsupportedEncodingException
var3
)
{
throw
new
IllegalArgumentException
(
var3
);
}
}
private
static
byte
[]
getSHA1Digest
(
String
data
)
throws
IOException
{
Object
var1
=
null
;
try
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA-1"
);
byte
[]
bytes
=
md
.
digest
(
data
.
getBytes
(
"UTF-8"
));
return
bytes
;
return
md
.
digest
(
data
.
getBytes
(
StandardCharsets
.
UTF_8
));
}
catch
(
GeneralSecurityException
var3
)
{
throw
new
IOException
(
var3
);
}
}
private
static
byte
[]
getMD5Digest
(
String
data
)
throws
IOException
{
Object
var1
=
null
;
try
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
byte
[]
bytes
=
md
.
digest
(
data
.
getBytes
(
"UTF-8"
));
return
bytes
;
return
md
.
digest
(
data
.
getBytes
(
StandardCharsets
.
UTF_8
));
}
catch
(
GeneralSecurityException
var3
)
{
throw
new
IOException
(
var3
);
}
...
...
@@ -88,8 +83,8 @@ public class RopUtils {
private
static
String
byte2hex
(
byte
[]
bytes
)
{
StringBuilder
sign
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
bytes
.
length
;
++
i
)
{
String
hex
=
Integer
.
toHexString
(
bytes
[
i
]
&
255
);
for
(
byte
aByte
:
bytes
)
{
String
hex
=
Integer
.
toHexString
(
aByte
&
255
);
if
(
hex
.
length
()
==
1
)
{
sign
.
append
(
"0"
);
}
...
...
@@ -105,4 +100,23 @@ public class RopUtils {
return
uuid
.
toString
().
toUpperCase
();
}
public
static
String
signE
(
Map
<
String
,
String
>
paramValues
,
List
<
String
>
ignoreParamNames
,
String
secret
)
{
StringBuilder
sb
=
new
StringBuilder
();
List
<
String
>
paramNames
=
new
ArrayList
<>(
paramValues
.
size
());
paramNames
.
addAll
(
paramValues
.
keySet
());
if
(
ignoreParamNames
!=
null
&&
!
ignoreParamNames
.
isEmpty
())
{
for
(
String
ignoreParamName
:
ignoreParamNames
)
{
paramNames
.
remove
(
ignoreParamName
);
}
}
Collections
.
sort
(
paramNames
);
sb
.
append
(
secret
);
for
(
String
paramName
:
paramNames
)
{
sb
.
append
(
paramName
).
append
(
paramValues
.
get
(
paramName
));
}
sb
.
append
(
secret
);
return
MD5
.
convert32
(
sb
.
toString
());
}
}
platform-execute/src/test/java/cn/com/glsx/cn/com/glsx/Utils/RopHttpUtilTest.java
View file @
8386fe3
package
cn
.
com
.
glsx
.
cn
.
com
.
glsx
.
Utils
;
import
cn.com.glsx.execute.modules.model.RopResponseDTO
;
import
cn.com.glsx.execute.modules.model.
rop.
RopResponseDTO
;
import
cn.com.glsx.execute.utils.RopHttpUtil
;
import
org.junit.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
...
...
platform-execute/src/test/java/cn/com/glsx/cn/com/glsx/Utils/SendMessageServiceTest.java
0 → 100644
View file @
8386fe3
package
cn
.
com
.
glsx
.
cn
.
com
.
glsx
.
Utils
;
import
cn.com.glsx.execute.modules.model.sms.SmsResponseDTO
;
import
cn.com.glsx.execute.modules.service.proxy.SendMessageService
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.core.env.Environment
;
/**
* @Author yelq
* @Version 1.0
* @Description:
* @Date 2023/9/7 17:14
*/
@ComponentScan
(
basePackages
=
"cn.com.glsx.execute,cn.com.glsx.cn.com.glsx"
)
@SpringBootTest
public
class
SendMessageServiceTest
{
@Autowired
private
SendMessageService
sendMessageService
;
@Autowired
private
Environment
environment
;
@Test
public
void
Test01
()
throws
Exception
{
//sendMessageUrl=http://qcdidicb.glsx.com.cn:7060/router
//sendMessageMethod=glsx.accounts.send.message
// SendMessageService sendMessageService = new SendMessageService();
String
text
=
"【波波的单店门店】SOP营销测试https://dwz.cn/sHkDTMo9"
;
SmsResponseDTO
s
=
sendMessageService
.
sendMessage
(
"18126301457"
,
"djsms-marketing"
,
"1"
,
text
);
System
.
out
.
println
(
s
);
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment