Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-standard-interfaces
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6a742402
authored
Apr 12, 2022
by
levphon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
工单标准接口-短信由通知服务调用
1 parent
ed65268e
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
60 additions
and
680 deletions
src/main/java/cn/com/glsx/stdinterface/modules/remote/NotifyCenterService.java
src/main/java/cn/com/glsx/stdinterface/modules/remote/RemoteFeignDeviceService.java
src/main/java/cn/com/glsx/stdinterface/modules/service/BhgBizService.java
src/main/java/cn/com/glsx/stdinterface/modules/service/FakeOfficeService.java
src/main/java/cn/com/glsx/stdinterface/modules/service/MessageService.java
src/main/java/cn/com/glsx/stdinterface/modules/service/WorkOrderService.java
src/main/java/cn/com/glsx/stdinterface/modules/util/Coder.java
src/main/java/cn/com/glsx/stdinterface/modules/util/GopUtils.java
src/main/java/cn/com/glsx/stdinterface/modules/util/MD5Util.java
src/main/java/cn/com/glsx/stdinterface/modules/util/RopHttpUtil.java
src/main/java/cn/com/glsx/stdinterface/modules/util/RopUtils.java
src/test/java/cn/com/glsx/stdinterface/modules/service/VehicleServiceTest.java
src/test/java/cn/com/glsx/stdinterface/modules/service/WorkOrderServiceTest.java
src/main/java/cn/com/glsx/stdinterface/modules/remote/NotifyCenterService.java
View file @
6a74240
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
remote
;
import
cn.com.glsx.notify.api.NotifyCenterFeignClient
;
import
cn.com.glsx.notify.dto.MailTemplateMessageDTO
;
import
cn.com.glsx.notify.dto.request.MailMessageRequest
;
import
cn.com.glsx.notify.dto.request.SmsMessageRequest
;
import
cn.hutool.json.JSONUtil
;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -20,13 +21,25 @@ public class NotifyCenterService {
private
NotifyCenterFeignClient
notifyCenterFeignClient
;
/**
* 调用短信发送服务
*
* @param messageRequest 邮件发送服务实体类
*/
public
void
sendSms
(
SmsMessageRequest
messageRequest
)
{
log
.
info
(
"发送短信参数==="
+
JSONUtil
.
toJsonStr
(
messageRequest
));
R
r
=
notifyCenterFeignClient
.
sendSms
(
messageRequest
);
log
.
info
(
"发送短信结果返回==="
+
JSONUtil
.
toJsonStr
(
r
));
}
/**
* 调用远程邮件发送服务
*
* @param message
DTO
邮件发送服务实体类
* @param message
Request
邮件发送服务实体类
*/
public
void
sendMailOnlyContent
(
Mail
TemplateMessageDTO
messageDTO
)
{
log
.
info
(
"发送邮件参数==="
+
JSONUtil
.
toJsonStr
(
message
DTO
));
R
r
=
notifyCenterFeignClient
.
sendMailOnlyContent
(
message
DTO
);
public
void
sendMailOnlyContent
(
Mail
MessageRequest
messageRequest
)
{
log
.
info
(
"发送邮件参数==="
+
JSONUtil
.
toJsonStr
(
message
Request
));
R
r
=
notifyCenterFeignClient
.
sendMailOnlyContent
(
message
Request
);
log
.
info
(
"发送邮件结果返回==="
+
JSONUtil
.
toJsonStr
(
r
));
}
}
src/main/java/cn/com/glsx/stdinterface/modules/remote/RemoteFeignDeviceService.java
View file @
6a74240
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
remote
;
import
cn.com.glsx.devicemonitor.api.dto.re
sponse.DeviceSearchDTO
;
import
cn.com.glsx.devicemonitor.api.dto.re
quest.DeviceStatusRequest
;
import
cn.com.glsx.devicemonitor.api.dto.response.DeviceStatusModel
;
import
cn.com.glsx.devicemonitor.api.feign.DeviceFeignService
;
import
cn.hutool.json.JSONUtil
;
...
...
@@ -31,9 +31,7 @@ public class RemoteFeignDeviceService {
public
Map
<
String
,
DeviceStatusModel
>
listDeviceStatusBySns
(
Collection
<
String
>
sns
)
{
log
.
info
(
"调用监控服务获取设备在线和离线的状态==="
+
JSONUtil
.
toJsonStr
(
sns
));
DeviceSearchDTO
deviceSearchDTO
=
new
DeviceSearchDTO
();
deviceSearchDTO
.
setSns
(
sns
);
R
<
List
<
DeviceStatusModel
>>
listDeviceStatusBySnsR
=
deviceFeignService
.
listDeviceStatusBySns
(
deviceSearchDTO
);
R
<
List
<
DeviceStatusModel
>>
listDeviceStatusBySnsR
=
deviceFeignService
.
listDeviceStatusBySns
(
new
DeviceStatusRequest
(
sns
));
List
<
DeviceStatusModel
>
listDeviceStatusBySnsDataList
=
listDeviceStatusBySnsR
.
getDataList
(
new
TypeToken
<
List
<
DeviceStatusModel
>>()
{
}.
getType
());
...
...
@@ -43,4 +41,5 @@ public class RemoteFeignDeviceService {
}
return
deviceStatusBsDataMap
;
}
}
src/main/java/cn/com/glsx/stdinterface/modules/service/BhgBizService.java
View file @
6a74240
...
...
@@ -5,11 +5,11 @@ import cn.com.glsx.stdinterface.enums.WorkOrderSourceEnum;
import
cn.com.glsx.stdinterface.modules.entity.WorkOrder
;
import
cn.com.glsx.stdinterface.modules.entity.WorkOrderVehicle
;
import
cn.com.glsx.stdinterface.modules.model.BhgResultObject
;
import
cn.com.glsx.stdinterface.modules.util.MD5Util
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.common.utils.DateUtils
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.common.utils.MD5Util
;
import
com.glsx.plat.common.utils.StringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
src/main/java/cn/com/glsx/stdinterface/modules/service/FakeOfficeService.java
View file @
6a74240
...
...
@@ -11,9 +11,7 @@ import cn.com.glsx.stdinterface.modules.entity.FakeOfflineVin;
import
cn.com.glsx.stdinterface.modules.entity.Vehicle
;
import
cn.com.glsx.stdinterface.modules.mapper.FakeOfflineFenceSnMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.FakeOfflineVinMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleMapper
;
import
cn.com.glsx.stdinterface.modules.remote.RemoteFeignDeviceService
;
import
cn.hutool.json.JSONUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -41,12 +39,6 @@ public class FakeOfficeService {
@Autowired
private
VehicleMapper
vehicleMapper
;
@Autowired
private
VehicleDeviceMapper
vehicleDeviceMapper
;
@Autowired
private
RemoteFeignDeviceService
remoteFeignDeviceService
;
/**
* 保存假性离线数据
*
...
...
src/main/java/cn/com/glsx/stdinterface/modules/service/MessageService.java
deleted
100644 → 0
View file @
ed65268
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
service
;
import
cn.com.glsx.stdinterface.modules.util.RopHttpUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
/**
* @author zhouhaibao
* @version 1.0
* @description: 短信发送服务
* @date 2021/11/14 14:23
*/
@Slf4j
@Service
@RefreshScope
public
class
MessageService
{
@Value
(
"${sendMessageUrl}"
)
private
String
sendMessageUrl
;
@Value
(
"${sendMessageMethod}"
)
private
String
sendMessageMethod
;
/**
* 发送短信
*
* @param phone 电话号码,批量用逗号隔开
* @param source 来源
* @param type 类型
* @param context 发送内容
*/
@Async
public
void
sendMessage
(
String
phone
,
String
source
,
String
type
,
String
context
)
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<>(
5
);
try
{
params
.
add
(
"phone"
,
phone
);
params
.
add
(
"source"
,
source
);
params
.
add
(
"messageSource"
,
source
);
params
.
add
(
"type"
,
type
);
params
.
add
(
"context"
,
context
);
String
post
=
RopHttpUtil
.
postE
(
params
,
String
.
class
,
sendMessageUrl
+
"?method="
+
sendMessageMethod
,
sendMessageMethod
);
log
.
info
(
"发送短信结果{}"
,
post
);
}
catch
(
Exception
e
)
{
log
.
error
(
"发送短信到{}异常,{}"
,
phone
,
e
.
getMessage
());
//throw new StdInterfaceException("444444", e.getMessage());
}
}
// public static void main(String[] args) {
// MessageService messageService = new MessageService();
// messageService.sendMessage("18682185876", "eshield_workOrder_warm", "1", "this is a test!");
// }
}
src/main/java/cn/com/glsx/stdinterface/modules/service/WorkOrderService.java
View file @
6a74240
...
...
@@ -10,7 +10,8 @@ import cn.com.glsx.devicemonitor.api.enums.DeviceTypeRelationEnum;
import
cn.com.glsx.devicemonitor.api.enums.DeviceWireTypeEnum
;
import
cn.com.glsx.devicemonitor.api.feign.DeviceFeignService
;
import
cn.com.glsx.devicemonitor.api.feign.GpsBsFeignService
;
import
cn.com.glsx.notify.dto.MailTemplateMessageDTO
;
import
cn.com.glsx.notify.dto.request.MailMessageRequest
;
import
cn.com.glsx.notify.dto.request.SmsMessageRequest
;
import
cn.com.glsx.stdinterface.common.constants.Constants
;
import
cn.com.glsx.stdinterface.common.enums.TypeConverseEunm
;
import
cn.com.glsx.stdinterface.common.exception.StdInterfaceException
;
...
...
@@ -109,9 +110,6 @@ public class WorkOrderService {
private
ApiUserService
apiUserService
;
@Autowired
private
MessageService
messageService
;
@Autowired
private
NotifyCenterService
notifyCenterService
;
@Autowired
...
...
@@ -529,7 +527,7 @@ public class WorkOrderService {
content
.
append
(
"备注:"
).
append
(
order
.
getServiceExplain
()).
append
(
";\n"
);
}
Mail
TemplateMessageDTO
messageDTO
=
new
MailTemplateMessageDTO
();
Mail
MessageRequest
messageDTO
=
new
MailMessageRequest
();
String
sendMail
=
PropertiesUtils
.
getProperty
(
"mail.toMail.addr"
);
messageDTO
.
setTo
(
sendMail
);
messageDTO
.
setTitle
(
title
.
toString
());
...
...
@@ -1310,15 +1308,23 @@ public class WorkOrderService {
public
void
finishedNotifyTarget
(
WorkOrder
workOrder
,
Vehicle
vehicle
)
{
String
receiveNumbers
=
workOrder
.
getNotifyTarget
();
if
(
StringUtils
.
isNullOrEmpty
(
receiveNumbers
))
{
log
.
info
(
"未填写手机号码,且非仲利的工单,
本次
不发送短信"
);
log
.
info
(
"未填写手机号码,且非仲利的工单,不发送短信"
);
return
;
}
if
(
vehicle
!=
null
&&
StringUtils
.
isNotEmpty
(
workOrder
.
getPartnerOrderNo
()))
{
String
ownerName
=
StringUtils
.
isNullOrEmpty
(
vehicle
.
getOwnerName
())
?
" 空 "
:
vehicle
.
getOwnerName
();
String
messageContent
=
"【嘀嘀虎】您好,您的服务订单 "
+
workOrder
.
getPartnerOrderNo
()
+
"(车主:"
+
ownerName
+
"),"
+
"已完成,上门时间:"
+
DateUtils
.
formatNormal
(
new
Date
())
+
"。广联赛讯"
;
Map
<
String
,
Object
>
args
=
Maps
.
newLinkedHashMap
();
args
.
put
(
"arg1"
,
workOrder
.
getPartnerOrderNo
());
args
.
put
(
"arg2"
,
ownerName
);
args
.
put
(
"arg3"
,
DateUtils
.
formatNormal
(
new
Date
()));
String
[]
phoneNumberArr
=
receiveNumbers
.
split
(
";"
);
for
(
String
phoneNumber
:
phoneNumberArr
)
{
messageService
.
sendMessage
(
phoneNumber
,
"eshield_workOrder_warm"
,
"1"
,
messageContent
);
SmsMessageRequest
messageRequest
=
new
SmsMessageRequest
();
messageRequest
.
setPhone
(
phoneNumber
);
messageRequest
.
setTemplate
(
"SMS_TEMPLATE_ORDER_FINISHED"
);
messageRequest
.
setArgs
(
args
);
notifyCenterService
.
sendSms
(
messageRequest
);
}
}
}
...
...
src/main/java/cn/com/glsx/stdinterface/modules/util/Coder.java
deleted
100644 → 0
View file @
ed65268
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
util
;
import
sun.misc.BASE64Decoder
;
import
sun.misc.BASE64Encoder
;
import
javax.crypto.KeyGenerator
;
import
javax.crypto.Mac
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.security.MessageDigest
;
public
class
Coder
{
public
static
final
String
KEY_SHA
=
"SHA"
;
public
static
final
String
KEY_MD5
=
"MD5"
;
/**
* MAC算法可选以下多种算法
*
* <pre>
* HmacMD5
* HmacSHA1
* HmacSHA256
* HmacSHA384
* HmacSHA512
* </pre>
*/
public
static
final
String
KEY_MAC
=
"HmacMD5"
;
/**
* BASE64解密
*
* @param key
* @return
* @throws Exception
*/
public
static
byte
[]
decryptBASE64
(
String
key
)
throws
Exception
{
return
(
new
BASE64Decoder
()).
decodeBuffer
(
key
);
}
/**
* BASE64加密
*
* @param key
* @return
* @throws Exception
*/
public
static
String
encryptBASE64
(
byte
[]
key
)
throws
Exception
{
return
(
new
BASE64Encoder
()).
encodeBuffer
(
key
);
}
/**
* MD5加密
*
* @param data
* @return
* @throws Exception
*/
public
static
byte
[]
encryptMD5
(
byte
[]
data
)
throws
Exception
{
MessageDigest
md5
=
MessageDigest
.
getInstance
(
KEY_MD5
);
md5
.
update
(
data
);
return
md5
.
digest
();
}
/**
* SHA加密
*
* @param data
* @return
* @throws Exception
*/
public
static
byte
[]
encryptSHA
(
byte
[]
data
)
throws
Exception
{
MessageDigest
sha
=
MessageDigest
.
getInstance
(
KEY_SHA
);
sha
.
update
(
data
);
return
sha
.
digest
();
}
/**
* 初始化HMAC密钥
*
* @return
* @throws Exception
*/
public
static
String
initMacKey
()
throws
Exception
{
KeyGenerator
keyGenerator
=
KeyGenerator
.
getInstance
(
KEY_MAC
);
SecretKey
secretKey
=
keyGenerator
.
generateKey
();
return
encryptBASE64
(
secretKey
.
getEncoded
());
}
/**
* HMAC加密
*
* @param data
* @param key
* @return
* @throws Exception
*/
public
static
byte
[]
encryptHMAC
(
byte
[]
data
,
String
key
)
throws
Exception
{
SecretKey
secretKey
=
new
SecretKeySpec
(
decryptBASE64
(
key
),
KEY_MAC
);
Mac
mac
=
Mac
.
getInstance
(
secretKey
.
getAlgorithm
());
mac
.
init
(
secretKey
);
return
mac
.
doFinal
(
data
);
}
}
src/main/java/cn/com/glsx/stdinterface/modules/util/GopUtils.java
deleted
100644 → 0
View file @
ed65268
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
util
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author zhouhaibao
* @version 1.0
* @description: TODO
* @date 2021/11/23 21:38
*/
public
class
GopUtils
{
/**
* 使用<code>secret</code>对paramValues按以下算法进行签名: <br/>
* uppercase(hex(sha1(secretkey1value1key2value2...secret))
* <p>
* 需要签名的参数名
*
* @param paramValues 参数列表
* @param secret
* @return
*/
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
String
secret
)
{
return
sign
(
paramValues
,
null
,
secret
);
}
/**
* 对paramValues进行签名,其中ignoreParamNames这些参数不参与签名
*
* @param paramValues
* @param ignoreParamNames
* @param secret
* @return
*/
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
List
<
String
>
ignoreParamNames
,
String
secret
)
{
//try {
StringBuilder
sb
=
new
StringBuilder
();
List
<
String
>
paramNames
=
new
ArrayList
<
String
>(
paramValues
.
size
());
paramNames
.
addAll
(
paramValues
.
keySet
());
if
(
ignoreParamNames
!=
null
&&
ignoreParamNames
.
size
()
>
0
)
{
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
);
/*byte[] sha1Digest = getSHA1Digest(sb.toString());
return byte2hex(sha1Digest);*/
return
MD5Util
.
convert32
(
sb
.
toString
());
/*} catch (IOException e) {
throw new GopException(e);
}*/
}
}
src/main/java/cn/com/glsx/stdinterface/modules/util/MD5Util.java
deleted
100644 → 0
View file @
ed65268
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
util
;
import
java.io.UnsupportedEncodingException
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Map
;
public
class
MD5Util
{
private
static
final
String
hexDigits
[]
=
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
};
private
static
String
byteArrayToHexString
(
byte
b
[])
{
StringBuffer
resultSb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
b
.
length
;
i
++)
{
resultSb
.
append
(
byteToHexString
(
b
[
i
]));
}
return
resultSb
.
toString
();
}
private
static
String
byteToHexString
(
byte
b
)
{
int
n
=
b
;
if
(
n
<
0
)
n
+=
256
;
int
d1
=
n
/
16
;
int
d2
=
n
%
16
;
return
hexDigits
[
d1
]
+
hexDigits
[
d2
];
}
public
static
String
encode
(
String
origin
)
{
return
encode
(
origin
,
"UTF-8"
);
}
public
static
String
encode
(
String
origin
,
String
charsetname
)
{
String
resultString
=
null
;
try
{
resultString
=
new
String
(
origin
);
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
if
(
charsetname
==
null
||
""
.
equals
(
charsetname
))
resultString
=
byteArrayToHexString
(
md
.
digest
(
resultString
.
getBytes
()));
else
resultString
=
byteArrayToHexString
(
md
.
digest
(
resultString
.
getBytes
(
charsetname
)));
}
catch
(
Exception
exception
)
{
}
return
resultString
;
}
/**
* md5加密方法
*
* @param str
* @return
*/
public
static
String
encrypt
(
String
str
)
{
try
{
byte
b
[]
=
Coder
.
encryptMD5
(
str
.
getBytes
(
"utf-8"
));
StringBuffer
buf
=
new
StringBuffer
();
String
stmp
=
""
;
for
(
int
n
=
0
;
n
<
b
.
length
;
n
++)
{
stmp
=
Integer
.
toHexString
(
b
[
n
]
&
0XFF
);
if
(
stmp
.
length
()
==
1
)
buf
.
append
(
"0"
).
append
(
stmp
);
else
buf
.
append
(
stmp
);
}
return
buf
.
toString
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
""
;
}
public
static
String
MD516
(
String
sourceStr
)
{
String
result
=
""
;
try
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
try
{
md
.
update
(
sourceStr
.
getBytes
(
"GBK"
));
}
catch
(
UnsupportedEncodingException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
byte
b
[]
=
md
.
digest
();
int
i
;
StringBuffer
buf
=
new
StringBuffer
(
""
);
for
(
int
offset
=
0
;
offset
<
b
.
length
;
offset
++)
{
i
=
b
[
offset
];
if
(
i
<
0
)
i
+=
256
;
if
(
i
<
16
)
buf
.
append
(
"0"
);
buf
.
append
(
Integer
.
toHexString
(
i
));
}
result
=
buf
.
toString
();
result
=
result
.
toString
().
substring
(
8
,
24
);
}
catch
(
NoSuchAlgorithmException
e
)
{
System
.
out
.
println
(
e
);
}
return
result
;
}
/**
* 获取MD5加密的sign
*
* @param params
* @return
*/
public
static
String
getParamsMD5Sign
(
Map
<
Object
,
Object
>
params
)
{
StringBuffer
paramsStr
=
new
StringBuffer
();
for
(
Map
.
Entry
<
Object
,
Object
>
param
:
params
.
entrySet
())
{
paramsStr
.
append
(
param
.
getKey
()).
append
(
param
.
getValue
());
}
return
MD5Util
.
encrypt
(
paramsStr
.
toString
()).
toUpperCase
();
}
/**
* 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
(
"UTF-8"
);
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
;
}
}
}
src/main/java/cn/com/glsx/stdinterface/modules/util/RopHttpUtil.java
deleted
100644 → 0
View file @
ed65268
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
util
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.util.DefaultUriBuilderFactory
;
import
org.springframework.web.util.UriBuilder
;
import
java.net.URI
;
import
java.util.Map
;
import
java.util.Map.Entry
;
/**
* @author zhouhaibao
* @version 1.0
* @description: http调用rop端服务
* @date 2021/7/30 11:26
*/
public
class
RopHttpUtil
{
private
final
static
String
appKey
=
"48e5e13229b82c1b4e6e8c96151f0637"
;
private
final
static
String
secret
=
"c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b"
;
private
static
void
addBaseParam
(
MultiValueMap
<
String
,
String
>
paramsMap
,
String
method
)
{
paramsMap
.
add
(
"v"
,
"1.0.0"
);
paramsMap
.
add
(
"method"
,
method
);
paramsMap
.
add
(
"name"
,
"zhouhb"
);
}
private
static
void
addBaseParamE
(
MultiValueMap
<
String
,
String
>
paramsMap
,
String
method
)
{
paramsMap
.
add
(
"v"
,
"1.0.0"
);
paramsMap
.
add
(
"method"
,
method
);
}
public
static
<
T
>
T
get
(
MultiValueMap
<
String
,
String
>
paramsMap
,
Class
<
T
>
responseType
,
String
baseurl
,
String
method
)
throws
Exception
{
addBaseParam
(
paramsMap
,
method
);
MultiValueMap
<
String
,
String
>
params
=
getSysParams
();
params
.
putAll
(
paramsMap
);
for
(
Entry
<
String
,
String
>
entry
:
params
.
toSingleValueMap
().
entrySet
())
{
if
(
StringUtils
.
isEmpty
(
entry
.
getValue
()))
{
params
.
remove
(
entry
.
getKey
());
}
}
String
sign
=
RopUtils
.
sign
(
params
.
toSingleValueMap
(),
secret
);
params
.
add
(
"sign"
,
sign
);
RestTemplate
rest
=
new
RestTemplate
();
RopUriTemplateHandler
uriTemplateHandler
=
new
RopUriTemplateHandler
(
baseurl
);
uriTemplateHandler
.
setDefaultUriVariables
(
params
.
toSingleValueMap
());
rest
.
setUriTemplateHandler
(
uriTemplateHandler
);
T
forObject
=
rest
.
getForObject
(
baseurl
,
responseType
,
params
.
toSingleValueMap
());
return
forObject
;
}
public
static
<
T
>
T
post
(
MultiValueMap
<
String
,
String
>
paramsMap
,
Class
<
T
>
responseType
,
String
baseurl
,
String
method
)
throws
Exception
{
addBaseParam
(
paramsMap
,
method
);
MultiValueMap
<
String
,
String
>
params
=
getSysParams
();
params
.
putAll
(
paramsMap
);
for
(
Entry
<
String
,
String
>
entry
:
params
.
toSingleValueMap
().
entrySet
())
{
if
(
StringUtils
.
isEmpty
(
entry
.
getValue
()))
{
params
.
remove
(
entry
.
getKey
());
}
}
String
sign
=
RopUtils
.
sign
(
params
.
toSingleValueMap
(),
secret
);
params
.
add
(
"sign"
,
sign
);
return
new
RestTemplate
().
postForObject
(
baseurl
,
params
,
responseType
);
}
public
static
<
T
>
T
postE
(
MultiValueMap
<
String
,
String
>
paramsMap
,
Class
<
T
>
responseType
,
String
baseurl
,
String
method
)
throws
Exception
{
addBaseParamE
(
paramsMap
,
method
);
MultiValueMap
<
String
,
String
>
params
=
getSysParamsE
();
params
.
putAll
(
paramsMap
);
for
(
Entry
<
String
,
String
>
entry
:
params
.
toSingleValueMap
().
entrySet
())
{
if
(
StringUtils
.
isEmpty
(
entry
.
getValue
()))
{
params
.
remove
(
entry
.
getKey
());
}
}
String
sign
=
GopUtils
.
sign
(
params
.
toSingleValueMap
(),
secret
);
params
.
add
(
"sign"
,
sign
);
return
new
RestTemplate
().
postForObject
(
baseurl
,
params
,
responseType
);
}
public
static
MultiValueMap
<
String
,
String
>
getSysParams
()
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>(
16
);
params
.
add
(
"appKey"
,
appKey
);
params
.
add
(
"format"
,
"json"
);
return
params
;
}
public
static
MultiValueMap
<
String
,
String
>
getSysParamsE
()
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>(
16
);
params
.
add
(
"app_key"
,
appKey
);
params
.
add
(
"format"
,
"json"
);
params
.
add
(
"timestamp"
,
System
.
currentTimeMillis
()
+
""
);
return
params
;
}
static
class
RopUriTemplateHandler
extends
DefaultUriBuilderFactory
{
public
RopUriTemplateHandler
(
String
baseUriTemplate
)
{
super
(
baseUriTemplate
);
}
@Override
public
URI
expand
(
String
uriTemplate
,
Map
<
String
,
?>
uriVars
)
{
UriBuilder
builder
=
uriString
(
uriTemplate
);
if
(
uriVars
!=
null
&&
!
uriVars
.
isEmpty
())
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>();
for
(
Entry
<
String
,
?>
entry
:
uriVars
.
entrySet
())
{
params
.
add
(
entry
.
getKey
(),
entry
.
getValue
().
toString
());
}
builder
.
queryParams
(
params
);
}
return
builder
.
build
(
uriVars
);
}
}
}
src/main/java/cn/com/glsx/stdinterface/modules/util/RopUtils.java
deleted
100644 → 0
View file @
ed65268
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.security.GeneralSecurityException
;
import
java.security.MessageDigest
;
import
java.util.*
;
public
class
RopUtils
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
RopUtils
.
class
);
public
RopUtils
()
{
}
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
String
secret
)
{
return
sign
(
paramValues
,
(
List
)
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
());
paramNames
.
addAll
(
paramValues
.
keySet
());
Iterator
var5
;
String
paramName
;
if
(
ignoreParamNames
!=
null
&&
ignoreParamNames
.
size
()
>
0
)
{
var5
=
ignoreParamNames
.
iterator
();
while
(
var5
.
hasNext
())
{
paramName
=
(
String
)
var5
.
next
();
paramNames
.
remove
(
paramName
);
}
}
Collections
.
sort
(
paramNames
);
sb
.
append
(
secret
);
var5
=
paramNames
.
iterator
();
while
(
var5
.
hasNext
())
{
paramName
=
(
String
)
var5
.
next
();
sb
.
append
(
paramName
).
append
((
String
)
paramValues
.
get
(
paramName
));
}
sb
.
append
(
secret
);
byte
[]
sha1Digest
=
getSHA1Digest
(
sb
.
toString
());
return
byte2hex
(
sha1Digest
);
}
catch
(
IOException
var7
)
{
logger
.
info
(
"异常信息"
,
var7
);
return
null
;
}
}
public
static
String
utf8Encoding
(
String
value
,
String
sourceCharsetName
)
{
try
{
return
new
String
(
value
.
getBytes
(
sourceCharsetName
),
"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
;
}
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
;
}
catch
(
GeneralSecurityException
var3
)
{
throw
new
IOException
(
var3
);
}
}
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
);
if
(
hex
.
length
()
==
1
)
{
sign
.
append
(
"0"
);
}
sign
.
append
(
hex
.
toUpperCase
());
}
return
sign
.
toString
();
}
public
static
String
getUUID
()
{
UUID
uuid
=
UUID
.
randomUUID
();
return
uuid
.
toString
().
toUpperCase
();
}
}
src/test/java/cn/com/glsx/stdinterface/modules/service/VehicleServiceTest.java
View file @
6a74240
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
service
;
import
cn.com.glsx.Application
;
import
cn.com.glsx.notify.dto.MailTemplateMessageDTO
;
import
cn.com.glsx.stdinterface.dto.VehicleDto
;
import
cn.com.glsx.stdinterface.dto.WorkOrderAddrVerifyBO
;
import
cn.com.glsx.stdinterface.dto.WorkOrderAddrVerifyDTO
;
import
cn.com.glsx.stdinterface.modules.entity.Vehicle
;
import
cn.com.glsx.stdinterface.modules.entity.WorkOrder
;
import
cn.com.glsx.stdinterface.modules.entity.WorkOrderDocs
;
import
cn.com.glsx.stdinterface.modules.mapper.WorkOrderDocsMapper
;
import
cn.com.glsx.stdinterface.modules.model.CommonApiRequest
;
import
cn.com.glsx.stdinterface.modules.model.WorkOrderInfoBO
;
import
cn.com.glsx.stdinterface.modules.remote.NotifyCenterService
;
import
cn.com.glsx.stdinterface.modules.util.Sm4EncryptUtils
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.collect.Lists
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -24,9 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Slf4j
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Application
.
class
,
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
...
...
@@ -39,12 +24,12 @@ public class VehicleServiceTest {
public
void
testddd
()
{
String
sn
=
"1190909618"
;
Vehicle
vehicle
=
vehicleService
.
getVehicleInfoBySn
(
sn
);
if
(
vehicle
!=
null
)
{
if
(
vehicle
!=
null
)
{
VehicleDto
vehicleDto
=
new
VehicleDto
();
vehicleDto
.
setId
(
vehicle
.
getId
());
vehicleDto
.
setVin
(
vehicle
.
getVin
());
vehicleDto
.
setCreateBy
(
vehicle
.
getCreatedBy
());
vehicleDto
.
setCreateDate
((
vehicle
.
getCreatedDate
()
!=
null
)?
DateUtil
.
format
(
vehicle
.
getCreatedDate
(),
"yyyy-MM-dd HH:mm:ss"
):
""
);
vehicleDto
.
setCreateDate
((
vehicle
.
getCreatedDate
()
!=
null
)
?
DateUtil
.
format
(
vehicle
.
getCreatedDate
(),
"yyyy-MM-dd HH:mm:ss"
)
:
""
);
System
.
out
.
println
(
"=="
+
JSONObject
.
toJSONString
(
vehicleDto
));
}
System
.
out
.
println
(
"end"
);
...
...
src/test/java/cn/com/glsx/stdinterface/modules/service/WorkOrderServiceTest.java
View file @
6a74240
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
service
;
import
cn.com.glsx.Application
;
import
cn.com.glsx.notify.dto.MailTemplateMessageDTO
;
import
cn.com.glsx.notify.dto.request.MailMessageRequest
;
import
cn.com.glsx.notify.dto.request.SmsMessageRequest
;
import
cn.com.glsx.stdinterface.dto.WorkOrderAddrVerifyBO
;
import
cn.com.glsx.stdinterface.dto.WorkOrderAddrVerifyDTO
;
import
cn.com.glsx.stdinterface.modules.entity.Vehicle
;
...
...
@@ -14,8 +15,10 @@ import cn.com.glsx.stdinterface.modules.remote.NotifyCenterService;
import
cn.com.glsx.stdinterface.modules.util.Sm4EncryptUtils
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.common.utils.DateUtils
;
import
com.glsx.plat.mybatis.base.BaseEntity
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -24,7 +27,9 @@ import org.springframework.boot.test.context.SpringBootTest;
import
org.springframework.test.context.junit4.SpringRunner
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
...
...
@@ -73,7 +78,7 @@ public class WorkOrderServiceTest {
workOrder
.
setOrderNo
(
"2022010517000008"
);
workOrder
.
setNotifyTarget
(
"18682185876"
);
Vehicle
vehicle
=
new
Vehicle
();
//
vehicle.setOwnerName("流川枫");
vehicle
.
setOwnerName
(
"流川枫"
);
workOrderService
.
finishedNotifyTarget
(
workOrder
,
vehicle
);
}
...
...
@@ -101,8 +106,22 @@ public class WorkOrderServiceTest {
}
@Test
public
void
testSendSms
()
{
Map
<
String
,
Object
>
args
=
Maps
.
newLinkedHashMap
();
args
.
put
(
"arg1"
,
"AP0235930039"
);
args
.
put
(
"arg2"
,
"张三丰"
);
args
.
put
(
"arg3"
,
DateUtils
.
formatNormal
(
new
Date
()));
SmsMessageRequest
messageRequest
=
new
SmsMessageRequest
();
messageRequest
.
setPhone
(
"18682185876"
);
messageRequest
.
setTemplate
(
"SMS_TEMPLATE_ORDER_FINISHED"
);
messageRequest
.
setArgs
(
args
);
notifyCenterService
.
sendSms
(
messageRequest
);
}
@Test
public
void
testSendMail
()
{
Mail
TemplateMessageDTO
messageDTO
=
new
MailTemplateMessageDTO
();
Mail
MessageRequest
messageDTO
=
new
MailMessageRequest
();
messageDTO
.
setTo
(
"592761523@qq.com"
);
messageDTO
.
setTitle
(
"(广联赛讯) 手动安装单-482035297744388096-string"
);
messageDTO
.
setContent
(
"租赁公司-广联赛讯;申请编号-482035297744388096;区域-无;设备组合-string;导入时间-2022-02-22;分公司-无;店面名称-string;店面联系电话-string;要求安装日期-2022-02-22;客户姓名-string;车架号-string;颜色-无;车型-null;贷款期限-无;租凭方式-无;安装地址-string;备注—无;安装方式—广联安装;"
);
...
...
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