Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
push-message
Project
Project
Details
Activity
Releases
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
liucheng
push-message
Commits
95873b51
Commit
95873b51
authored
Apr 22, 2022
by
renandong
🇨🇳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.签名信息配置
parent
8540a781
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
78 additions
and
39 deletions
+78
-39
ValidatorParam.java
...main/java/com/weface/common/validator/ValidatorParam.java
+2
-3
ValidatorUtils.java
...main/java/com/weface/common/validator/ValidatorUtils.java
+1
-3
GeTuiService.java
src/main/java/com/weface/component/GeTuiService.java
+16
-3
PushController.java
src/main/java/com/weface/controller/PushController.java
+7
-6
InformForm.java
src/main/java/com/weface/dto/InformForm.java
+9
-5
PushLogServiceImpl.java
src/main/java/com/weface/serviceimpl/PushLogServiceImpl.java
+1
-5
UserTagsTask.java
src/main/java/com/weface/task/UserTagsTask.java
+19
-12
PushMessageApplicationTests.java
src/test/java/com/weface/PushMessageApplicationTests.java
+23
-2
No files found.
src/main/java/com/weface/common/validator/ValidatorParam.java
View file @
95873b51
...
...
@@ -3,7 +3,6 @@ package com.weface.common.validator;
import
com.weface.code.CommonResult
;
import
com.weface.code.ResultCode
;
import
com.weface.dto.InformForm
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
/**
...
...
@@ -23,10 +22,10 @@ public class ValidatorParam {
return
CommonResult
.
failed
(
ResultCode
.
PARAMS_ERROR
);
}
}
String
[]
cid
=
informForm
.
getCid
();
String
cid
=
informForm
.
getCid
();
String
phone
=
informForm
.
getPhone
();
Integer
messageTemplate
=
informForm
.
getMessageTemplate
();
if
(
Array
Utils
.
isEmpty
(
cid
)
||
StringUtils
.
isEmpty
(
phone
)
||
messageTemplate
==
null
)
{
if
(
String
Utils
.
isEmpty
(
cid
)
||
StringUtils
.
isEmpty
(
phone
)
||
messageTemplate
==
null
)
{
return
CommonResult
.
failed
(
ResultCode
.
PARAMS_ERROR
);
}
return
null
;
...
...
src/main/java/com/weface/common/validator/ValidatorUtils.java
View file @
95873b51
...
...
@@ -33,11 +33,9 @@ public class ValidatorUtils {
throws
RRException
{
Set
<
ConstraintViolation
<
Object
>>
constraintViolations
=
validator
.
validate
(
object
,
groups
);
if
(!
constraintViolations
.
isEmpty
())
{
StringBuilder
msg
=
new
StringBuilder
();
for
(
ConstraintViolation
<
Object
>
constraint
:
constraintViolations
)
{
msg
.
append
(
constraint
.
getMessage
()).
append
(
"\n"
);
throw
new
RRException
(
constraint
.
getMessage
(),
10001
);
}
throw
new
RRException
(
msg
.
toString
());
}
}
}
src/main/java/com/weface/component/GeTuiService.java
View file @
95873b51
...
...
@@ -340,7 +340,6 @@ public class GeTuiService {
*/
public
CommonResult
pushSingleAlias
(
InformForm
informForm
)
{
try
{
log
.
error
(
"单推参数:{}"
,
informForm
);
String
type
=
informForm
.
getEquipmentType
();
String
appId
=
getAppId
(
type
);
String
pushToken
=
getPushToken
(
type
);
...
...
@@ -348,7 +347,14 @@ public class GeTuiService {
return
CommonResult
.
failed
();
}
MessageTemplate
template
=
getTemplate
(
informForm
);
template
.
setAudience
(
new
MessageTemplate
.
Audience
(
informForm
.
getCid
()));
String
[]
split
;
String
cid
=
informForm
.
getCid
();
if
(
cid
.
contains
(
","
))
{
split
=
cid
.
split
(
","
);
}
else
{
split
=
new
String
[]{
cid
};
}
template
.
setAudience
(
new
MessageTemplate
.
Audience
(
split
));
template
.
setGroup_name
(
"toSingleAlias"
);
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
informForm
.
getDevice
(),
false
,
1
,
template
);
//请求url
...
...
@@ -391,7 +397,14 @@ public class GeTuiService {
return
CommonResult
.
failed
();
}
MessageTemplate
template
=
getTemplate
(
informForm
);
template
.
setAudience
(
new
MessageTemplate
.
Audience
(
informForm
.
getCid
()));
String
[]
split
;
String
cid
=
informForm
.
getCid
();
if
(
cid
.
contains
(
","
))
{
split
=
cid
.
split
(
","
);
}
else
{
split
=
new
String
[]{
cid
};
}
template
.
setAudience
(
new
MessageTemplate
.
Audience
(
split
));
template
.
setGroup_name
(
"toSingleCid"
);
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
informForm
.
getDevice
(),
false
,
0
,
template
);
//请求url
...
...
src/main/java/com/weface/controller/PushController.java
View file @
95873b51
...
...
@@ -2,20 +2,18 @@ package com.weface.controller;
import
com.weface.code.CommonResult
;
import
com.weface.common.validator.ValidatorParam
;
import
com.weface.common.validator.ValidatorUtils
;
import
com.weface.component.GeTuiService
;
import
com.weface.dto.InformForm
;
import
com.weface.dto.MsgDTO
;
import
com.weface.dto.PushDTO
;
import
com.weface.service.PushService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.validation.groups.Default
;
/**
* @author Administrator
*/
...
...
@@ -40,12 +38,14 @@ public class PushController {
}
@PostMapping
(
"/all"
)
public
CommonResult
pushAll
(
@Validated
({
Default
.
class
})
InformForm
informForm
)
{
public
CommonResult
pushAll
(
InformForm
informForm
)
{
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
return
geTuiService
.
listPush
(
informForm
);
}
@PostMapping
(
"/single/alias"
)
public
CommonResult
pushSingleAlias
(
@Validated
({
Default
.
class
})
InformForm
informForm
)
{
public
CommonResult
pushSingleAlias
(
@RequestBody
InformForm
informForm
)
{
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
CommonResult
commonResult
=
ValidatorParam
.
validPushSingleAlias
(
informForm
);
if
(
commonResult
!=
null
)
{
return
commonResult
;
...
...
@@ -54,7 +54,8 @@ public class PushController {
}
@PostMapping
(
"/single/cid"
)
public
CommonResult
pushSingleCid
(
@Validated
({
Default
.
class
})
InformForm
informForm
)
{
public
CommonResult
pushSingleCid
(
@RequestBody
InformForm
informForm
)
{
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
CommonResult
commonResult
=
ValidatorParam
.
validPushSingleAlias
(
informForm
);
if
(
commonResult
!=
null
)
{
return
commonResult
;
...
...
src/main/java/com/weface/dto/InformForm.java
View file @
95873b51
...
...
@@ -10,13 +10,13 @@ import javax.validation.constraints.NotBlank;
@Data
public
class
InformForm
{
//标题
@NotBlank
@NotBlank
(
message
=
"标题不能为空"
,
groups
=
{
PushValid
.
class
})
private
String
title
;
//内容
@NotBlank
@NotBlank
(
message
=
"内容不能为空"
,
groups
=
{
PushValid
.
class
})
private
String
body
;
//跳转url
@NotBlank
@NotBlank
(
message
=
"url不能为空"
,
groups
=
{
PushValid
.
class
})
private
String
url
;
//推送类型 0:h5 1:原生
private
Integer
pushType
;
...
...
@@ -27,17 +27,21 @@ public class InformForm {
//是否需要登录
private
String
needLogin
;
//请求应用名称首字母小写 例:看看生活->kksh
@NotBlank
@NotBlank
(
message
=
"应用名称不能为空"
,
groups
=
{
PushValid
.
class
})
private
String
equipmentType
;
//推送设备 4 android 1: ios
private
Integer
device
;
//定速推送,例如100,个推控制下发速度在100条/秒左右,0表示不限速
private
Integer
speed
;
//推送目标
private
String
[]
cid
;
private
String
cid
;
//推送手机号
private
String
phone
;
//推送模板
private
Integer
messageTemplate
;
public
interface
PushValid
{
}
}
src/main/java/com/weface/serviceimpl/PushLogServiceImpl.java
View file @
95873b51
...
...
@@ -41,11 +41,7 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
DES
des
=
DES
.
getInstanceDes
();
pushLogEntity
.
setPhone
(
des
.
encrypt
(
informForm
.
getPhone
()));
pushLogEntity
.
setMessageTemplate
(
informForm
.
getMessageTemplate
());
StringBuilder
sb
=
new
StringBuilder
();
for
(
String
target
:
informForm
.
getCid
())
{
sb
.
append
(
target
).
append
(
","
);
}
pushLogEntity
.
setPushTarget
(
sb
.
toString
());
pushLogEntity
.
setPushTarget
(
informForm
.
getCid
());
pushLogEntity
.
setPushContent
(
informForm
.
getBody
());
pushLogEntity
.
setArriveStatus
(
1001
);
pushLogEntity
.
setUpdateTime
(
new
Date
());
...
...
src/main/java/com/weface/task/UserTagsTask.java
View file @
95873b51
...
...
@@ -104,10 +104,13 @@ public class UserTagsTask {
*/
@Scheduled
(
cron
=
"0 0 3 * * ?"
)
public
void
updateRedisHashKey
()
{
try
{
log
.
error
(
"开始更新任务缓存"
);
HashSet
<
Object
>
hashSet
=
new
HashSet
<>();
Set
<
Object
>
keys
=
RedisUtil
.
HashOps
.
hKeys
(
Constant
.
PUSH_TASK_INFO
);
for
(
Object
key
:
keys
)
{
Object
hashValue
=
RedisUtil
.
HashOps
.
hGet
(
Constant
.
PUSH_TASK_INFO
,
key
.
toString
());
log
.
error
(
"缓存任务信息:{}"
,
hashValue
);
if
(
hashValue
!=
null
)
{
RedisExpireData
redisData
=
JSONUtil
.
toBean
(
hashValue
.
toString
(),
RedisExpireData
.
class
);
Object
obj
=
redisData
.
getStoreData
();
...
...
@@ -119,6 +122,10 @@ public class UserTagsTask {
if
(!
hashSet
.
isEmpty
())
{
RedisUtil
.
HashOps
.
hDelete
(
Constant
.
PUSH_TASK_INFO
,
hashSet
.
toArray
());
}
}
catch
(
Exception
e
)
{
log
.
error
(
"更新任务缓存失败:{}"
,
e
.
getMessage
());
e
.
printStackTrace
();
}
}
/**
...
...
src/test/java/com/weface/PushMessageApplicationTests.java
View file @
95873b51
...
...
@@ -6,10 +6,12 @@ import cn.hutool.json.JSONObject;
import
cn.hutool.json.JSONUtil
;
import
com.baomidou.mybatisplus.core.toolkit.CollectionUtils
;
import
com.weface.code.CommonResult
;
import
com.weface.common.utils.CommonUtil
;
import
com.weface.common.utils.RedisUtil
;
import
com.weface.common.utils.SnowIdUtil
;
import
com.weface.component.GeTuiService
;
import
com.weface.component.MenuService
;
import
com.weface.config.SignValidateFilter
;
import
com.weface.dto.InformForm
;
import
com.weface.entity.MenuTagsEntity
;
import
com.weface.entity.UserMenusEntity
;
...
...
@@ -347,8 +349,7 @@ class PushMessageApplicationTests {
informForm
.
setClassTitle
(
"我的金币"
);
informForm
.
setNeedLogin
(
"1"
);
informForm
.
setEquipmentType
(
"kksh"
);
String
[]
strings
=
{
"kksh_59354"
};
informForm
.
setCid
(
strings
);
informForm
.
setCid
(
"kksh_59354"
);
CommonResult
commonResult
=
geTuiService
.
pushSingleAlias
(
informForm
);
System
.
out
.
println
(
commonResult
);
}
...
...
@@ -367,4 +368,24 @@ class PushMessageApplicationTests {
CommonResult
commonResult
=
geTuiService
.
listPush
(
informForm
);
System
.
out
.
println
(
commonResult
);
}
@Test
public
void
testSign
()
{
// d9c57eada1389691d86ff4d62787d3cc
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"title"
,
"花费充值"
);
map
.
put
(
"body"
,
"尊敬的用户您好,您的户"
);
map
.
put
(
"url"
,
"https://docs.getui.com/getui/mobile/vendor/report/"
);
map
.
put
(
"pushType"
,
"0"
);
map
.
put
(
"equipmentType"
,
"kksh"
);
map
.
put
(
"cid"
,
"kksh_59354"
);
map
.
put
(
"messageTemplate"
,
"1"
);
map
.
put
(
"phone"
,
"15538250098"
);
long
l
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
l
);
map
.
put
(
"timestamp"
,
l
);
String
s
=
CommonUtil
.
apiParamSign
(
map
,
SignValidateFilter
.
SECRET_KEY
);
System
.
out
.
println
(
s
);
}
}
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