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
ed53074b
Commit
ed53074b
authored
Nov 01, 2022
by
zuoadmin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bug' into 'master'
Bug See merge request
!30
parents
180b4039
2acfaec5
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
209 additions
and
37 deletions
+209
-37
ValidatorParam.java
...main/java/com/weface/common/validator/ValidatorParam.java
+26
-0
GeTuiService.java
src/main/java/com/weface/component/GeTuiService.java
+50
-1
MobPushService.java
src/main/java/com/weface/component/MobPushService.java
+39
-6
PushController.java
src/main/java/com/weface/controller/PushController.java
+45
-10
InformForm.java
src/main/java/com/weface/dto/InformForm.java
+6
-2
PushLogServiceImpl.java
src/main/java/com/weface/serviceimpl/PushLogServiceImpl.java
+28
-3
UserTagsTask.java
src/main/java/com/weface/task/UserTagsTask.java
+5
-3
PushMessageApplicationTests.java
src/test/java/com/weface/PushMessageApplicationTests.java
+10
-12
No files found.
src/main/java/com/weface/common/validator/ValidatorParam.java
View file @
ed53074b
...
...
@@ -5,13 +5,39 @@ import com.weface.code.ResultCode;
import
com.weface.dto.InformForm
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.Objects
;
/**
* @author : Administrator
* @date : 2022/4/21 14:28
*/
public
class
ValidatorParam
{
/**
* 校验推送参数
*
* @param informForm 推送参数
* @return 核验结果
*/
public
static
CommonResult
validPushParams
(
InformForm
informForm
)
{
Integer
style
=
informForm
.
getStyle
();
if
(
Objects
.
nonNull
(
style
))
{
if
(
style
==
1
||
style
==
2
)
{
String
content
=
informForm
.
getContent
();
if
(
StringUtils
.
isEmpty
(
content
))
{
return
CommonResult
.
failed
(
ResultCode
.
PARAMS_ERROR
);
}
}
}
return
null
;
}
/**
* 核验别名单推推送参数
*
* @param informForm 推送参数
* @return 核验结果
*/
public
static
CommonResult
validPushSingleAlias
(
InformForm
informForm
)
{
String
body
=
informForm
.
getBody
();
if
(
body
.
length
()
>
60
)
{
...
...
src/main/java/com/weface/component/GeTuiService.java
View file @
ed53074b
...
...
@@ -300,7 +300,7 @@ public class GeTuiService {
public
CommonResult
listPush
(
InformForm
informForm
)
{
try
{
String
type
=
informForm
.
getEquipmentType
();
if
(
"kkwj"
.
equals
(
type
)){
if
(
"kkwj"
.
equals
(
type
))
{
return
CommonResult
.
success
(
"暂未开放推送"
);
}
String
appId
=
getAppId
(
type
);
...
...
@@ -318,6 +318,7 @@ public class GeTuiService {
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/all"
;
log
.
info
(
"执行群推"
);
String
result
=
generalPost
(
url
,
pushToken
,
map
);
log
.
error
(
"个推群推结果:{}"
,
result
);
if
(
result
==
null
)
{
return
CommonResult
.
failed
();
}
...
...
@@ -497,6 +498,54 @@ public class GeTuiService {
return
null
;
}
/**
* 撤回下发消息
*
* @param taskId 任务id
* @return 执行结果
*/
public
String
revokeTask
(
String
taskId
,
String
equipmentType
)
{
String
appId
=
getAppId
(
equipmentType
);
String
pushToken
=
getPushToken
(
equipmentType
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"request_id"
,
String
.
valueOf
(
SnowIdUtil
.
nextId
()));
map
.
put
(
"audience"
,
"all"
);
Map
<
String
,
Object
>
push_message
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
revoke
=
new
HashMap
<>();
revoke
.
put
(
"old_task_id"
,
"RASA_0607_cca1c0bbccb4eccc9b102eee15708989"
);
revoke
.
put
(
"force"
,
false
);
push_message
.
put
(
"revoke"
,
revoke
);
map
.
put
(
"push_message"
,
push_message
);
String
revokePush
=
GeTuiService
.
GE_TUI_BASE_URL
+
appId
+
"/push/all"
;
String
s
=
generalPost
(
revokePush
,
pushToken
,
map
);
log
.
error
(
"推送撤回消息:{}"
,
s
);
if
(
StringUtils
.
isBlank
(
pushToken
))
{
return
null
;
}
String
revokeDel
=
GE_TUI_BASE_URL
+
appId
+
"/task/"
+
taskId
;
String
token
=
HttpRequest
.
delete
(
revokeDel
).
header
(
"token"
,
pushToken
).
header
(
"content-type"
,
"application/json;charset=utf-8"
).
execute
().
body
();
log
.
error
(
"停止下发:{}"
,
token
);
return
token
;
}
/**
* 获取推送下发实时结果 注意:该接口需要开通权限,如需开通,请联系对应的商务同学开通
*
* @param taskId 任务id
* @param equipmentType 推送app
* @return 下发结果
*/
public
String
getReportByTaskId
(
String
taskId
,
String
equipmentType
)
{
String
prefix
=
String
.
format
(
"/report/push/task/%s/detail"
,
taskId
);
String
appId
=
getAppId
(
equipmentType
);
String
pushToken
=
getPushToken
(
equipmentType
);
String
url
=
GE_TUI_BASE_URL
+
appId
+
prefix
;
String
token
=
HttpRequest
.
get
(
url
).
header
(
"token"
,
pushToken
).
header
(
"content-type"
,
"application/json;charset=utf-8"
).
execute
().
body
();
log
.
error
(
"推送下发结果:{}"
,
token
);
return
token
;
}
/**
* 将内容转为推送模板
*
...
...
src/main/java/com/weface/component/MobPushService.java
View file @
ed53074b
...
...
@@ -15,6 +15,7 @@ import com.weface.common.utils.Model;
import
com.weface.dto.InformForm
;
import
com.weface.service.PushLogService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -152,7 +153,12 @@ public class MobPushService {
return
Model
.
error
();
}
/**
* 通过 workId查询当前消息推送结果
*
* @param workId 推送id
* @return 是否收到
*/
public
boolean
getPushInfoById
(
String
workId
)
{
String
reqUrl
=
"http://api.push.mob.com/v3/stats/getByWorkId"
;
Map
<
String
,
Object
>
request
=
new
HashMap
<>();
...
...
@@ -221,7 +227,7 @@ public class MobPushService {
//推送类型:1通知;2自定义
pushNotify
.
put
(
"type"
,
1
);
//android通知消息, type=1, android
Map
<
String
,
Object
>
androidNotify
=
getAndroidNotify
();
Map
<
String
,
Object
>
androidNotify
=
getAndroidNotify
(
informForm
);
if
(!
androidNotify
.
isEmpty
())
{
pushNotify
.
put
(
"androidNotify"
,
androidNotify
);
}
...
...
@@ -236,7 +242,7 @@ public class MobPushService {
//推送时,不走厂商通道。1: 开启,不走厂商通道;其它,关闭 ,默认关闭。
pushNotify
.
put
(
"skipFactory"
,
0
);
//推送策略: * 1:先走tcp,再走厂商 * 2:先走厂商,再走tcp * 3:只走厂商 * 4:只走tcp (厂商透传policy只支持策略3或4)
pushNotify
.
put
(
"policy"
,
2
);
pushNotify
.
put
(
"policy"
,
1
);
//拓展参数
pushNotify
.
put
(
"extrasMapList"
,
getExtrasMapList
(
informForm
));
return
pushNotify
;
...
...
@@ -391,16 +397,43 @@ public class MobPushService {
/**
* 安卓通知细节配置
*
* @param informForm 推送消息内容
* @return 安卓细节
*/
private
Map
<
String
,
Object
>
getAndroidNotify
()
{
private
Map
<
String
,
Object
>
getAndroidNotify
(
InformForm
informForm
)
{
Map
<
String
,
Object
>
androidNotify
=
new
HashMap
<>(
1
);
androidNotify
.
put
(
"warn"
,
"123"
);
//androidNotify.put("content", new String[]{"测试这是一条数据"});
//androidNotify.put("style", "3");
Integer
style
=
informForm
.
getStyle
();
if
(
Objects
.
isNull
(
style
))
{
return
androidNotify
;
}
androidNotify
.
put
(
"style"
,
style
);
String
content
=
informForm
.
getContent
();
if
(
style
==
1
||
style
==
2
)
{
androidNotify
.
put
(
"content"
,
new
String
[]{
content
});
}
String
image
=
informForm
.
getImage
();
if
(
StringUtils
.
isNotEmpty
(
image
))
{
androidNotify
.
put
(
"image"
,
image
);
}
return
androidNotify
;
}
/**
* customStyle:安卓通知自定义样式
*
* @return 安卓细节
*/
private
Map
<
String
,
Object
>
getCustomStyle
()
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"styleNo"
,
1
);
map
.
put
(
"backgroundUrl"
,
"https://socialsecurity.oss-cn-beijing.aliyuncs.com/userPhoto/ycfj.png"
);
map
.
put
(
"smallIcons"
,
"http://i.weface.com.cn/banners/tcformphoto/certificationOldSuucess01.gif"
);
map
.
put
(
"buttonCopy"
,
"测试文案"
);
map
.
put
(
"buttonJumpUrl"
,
"https://www.hutool.cn/"
);
return
map
;
}
/**
* ios通知细节配置
*
...
...
src/main/java/com/weface/controller/PushController.java
View file @
ed53074b
...
...
@@ -12,6 +12,7 @@ import com.weface.dto.MsgDTO;
import
com.weface.dto.PushDTO
;
import
com.weface.service.PushService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -43,42 +44,76 @@ public class PushController {
return
pushService
.
pushSingle
(
param
);
}
/**
* 群推
*/
@PostMapping
(
"/all"
)
public
CommonResult
pushAll
(
InformForm
informForm
)
{
log
.
error
(
"群推内容:{}"
,
JSONObject
.
toJSONString
(
informForm
));
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
if
(
informForm
.
getEquipmentType
().
equals
(
"kksh"
))
{
CommonResult
result
=
ValidatorParam
.
validPushParams
(
informForm
);
if
(
result
!=
null
)
{
return
result
;
}
if
(
informForm
.
getEquipmentType
().
equals
(
"kksh"
))
{
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
RADIO
);
}
return
geTuiService
.
listPush
(
informForm
);
}
/**
* 别名单推
*/
@PostMapping
(
"/single/alias"
)
public
CommonResult
pushSingleAlias
(
@RequestBody
InformForm
informForm
)
{
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
CommonResult
commonResult
=
ValidatorParam
.
validPushSingleAlia
s
(
informForm
);
if
(
commonR
esult
!=
null
)
{
return
commonR
esult
;
CommonResult
result
=
ValidatorParam
.
validPushParam
s
(
informForm
);
if
(
r
esult
!=
null
)
{
return
r
esult
;
}
CommonResult
result
=
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
ALIAS
);
result
=
ValidatorParam
.
validPushSingleAlias
(
informForm
);
if
(
result
!=
null
)
{
return
result
;
}
result
=
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
ALIAS
);
if
(
result
!=
null
)
{
return
CommonResult
.
success
();
}
return
geTuiService
.
pushSingleAlias
(
informForm
);
}
/**
* cid单推
*/
@PostMapping
(
"/single/cid"
)
public
CommonResult
pushSingleCid
(
@RequestBody
InformForm
informForm
)
{
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
CommonResult
commonResult
=
ValidatorParam
.
validPushSingleAlia
s
(
informForm
);
if
(
commonR
esult
!=
null
)
{
return
commonR
esult
;
CommonResult
result
=
ValidatorParam
.
validPushParam
s
(
informForm
);
if
(
r
esult
!=
null
)
{
return
r
esult
;
}
CommonResult
result
=
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
RIDS
);
result
=
ValidatorParam
.
validPushSingleAlias
(
informForm
);
if
(
result
!=
null
)
{
return
result
;
}
result
=
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
RIDS
);
if
(
result
!=
null
)
{
return
CommonResult
.
success
();
}
return
geTuiService
.
pushSingleCid
(
informForm
);
}
/**
* 别名批量推送
*/
@PostMapping
(
"/list/alias"
)
public
CommonResult
pushListMessage
(
@RequestBody
InformForm
informForm
)
{
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
String
result
=
geTuiService
.
pushListMessage
(
informForm
,
true
);
if
(
StringUtils
.
isEmpty
(
result
))
{
return
CommonResult
.
failed
(
"推送失败"
);
}
else
{
return
CommonResult
.
success
(
result
,
"推送成功"
);
}
}
}
src/main/java/com/weface/dto/InformForm.java
View file @
ed53074b
...
...
@@ -39,8 +39,12 @@ public class InformForm {
private
String
phone
;
//推送模板
private
Integer
messageTemplate
;
//显示样式标识- 0:默认 - 1:长内容 - 2:大图 - 3:横幅 - 4:自定义样式
private
Integer
style
;
//推送内容,配合style参数使用- style=0 不生效 - style=1 部分机型可以生效覆盖- style=2 传入图片链接,部分低版本手机不支持- style=3 对应传入文字内容默认: 0
private
String
content
;
//推送大图标的url地址小米厂商对图片尺寸有严格要求
private
String
image
;
public
interface
PushValid
{
}
...
...
src/main/java/com/weface/serviceimpl/PushLogServiceImpl.java
View file @
ed53074b
package
com
.
weface
.
serviceimpl
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
...
...
@@ -77,8 +78,11 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
pushLogEntity
.
setId
(
id
);
pushLogEntity
.
setAppName
(
informForm
.
getEquipmentType
());
pushLogEntity
.
setPushType
(
pushType
);
if
(
StringUtils
.
isNotEmpty
(
taskId
)
&&
taskId
.
length
()
>
200
)
{
taskId
=
taskId
.
substring
(
0
,
200
);
}
pushLogEntity
.
setTaskId
(
taskId
);
if
(
result
.
length
()
>
200
)
{
if
(
StringUtils
.
isNotEmpty
(
result
)
&&
result
.
length
()
>
200
)
{
result
=
result
.
substring
(
0
,
200
);
}
pushLogEntity
.
setResult
(
result
);
...
...
@@ -91,9 +95,30 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
if
(
messageTemplate
!=
null
)
{
pushLogEntity
.
setMessageTemplate
(
messageTemplate
);
}
pushLogEntity
.
setPushTarget
(
informForm
.
getCid
()
==
null
?
"all"
:
informForm
.
getCid
());
pushLogEntity
.
setPushContent
(
informForm
.
getBody
());
String
cid
=
informForm
.
getCid
();
String
pushTarget
;
if
(
StringUtils
.
isEmpty
(
cid
))
{
pushTarget
=
"all"
;
}
else
{
int
length
=
cid
.
length
();
if
(
length
>
200
)
{
pushTarget
=
"toListMessage"
;
}
else
{
pushTarget
=
cid
;
}
}
pushLogEntity
.
setPushTarget
(
pushTarget
);
String
body
=
informForm
.
getBody
();
if
(
StringUtils
.
isNotEmpty
(
body
)
&&
body
.
length
()
>
200
)
{
body
=
body
.
substring
(
0
,
200
);
}
pushLogEntity
.
setPushContent
(
body
);
pushLogEntity
.
setArriveStatus
(
1001
);
String
jsonStr
=
JSONUtil
.
toJsonStr
(
informForm
);
if
(
jsonStr
.
length
()
>
200
)
{
jsonStr
=
jsonStr
.
substring
(
0
,
200
);
}
pushLogEntity
.
setBas1
(
jsonStr
);
pushLogEntity
.
setUpdateTime
(
new
Date
());
return
pushLogEntity
;
}
...
...
src/main/java/com/weface/task/UserTagsTask.java
View file @
ed53074b
...
...
@@ -75,6 +75,7 @@ public class UserTagsTask {
*/
@Scheduled
(
cron
=
"0 0 8 1,15 * ?"
)
public
void
timingPush
()
{
log
.
error
(
"开始推送1,15号"
);
//判断当前是否为当月1/15号
if
(
DateUtils
.
isToday
(
1
)
||
DateUtils
.
isToday
(
15
))
{
//获取推送配置信息
...
...
@@ -87,14 +88,14 @@ public class UserTagsTask {
return
;
}
//查询老用户
List
<
String
>
list
=
pushLogService
.
getOrderUidList
().
stream
().
filter
(
org
.
apache
.
commons
.
lang3
.
StringUtils
::
isNumeric
).
collect
(
Collectors
.
toList
());
List
<
String
>
list
=
pushLogService
.
getOrderUidList
().
stream
().
filter
(
org
.
apache
.
commons
.
lang3
.
StringUtils
::
isNumeric
).
distinct
().
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
//将推送配置json转为推送实体类
InformForm
form
=
JSONObject
.
parseObject
(
configContent
,
InformForm
.
class
);
//当天是否为15号
if
(
DateUtils
.
isToday
(
15
))
{
//查询14天前至今有缴费记录用户
List
<
String
>
record
=
pushLogService
.
getPayCostRecord
().
stream
().
filter
(
org
.
apache
.
commons
.
lang3
.
StringUtils
::
isNumeric
).
collect
(
Collectors
.
toList
());
List
<
String
>
record
=
pushLogService
.
getPayCostRecord
().
stream
().
filter
(
org
.
apache
.
commons
.
lang3
.
StringUtils
::
isNumeric
).
distinct
().
collect
(
Collectors
.
toList
());
//过滤已缴费用户
if
(!
CollectionUtils
.
isEmpty
(
record
))
{
list
.
removeAll
(
record
);
...
...
@@ -116,6 +117,7 @@ public class UserTagsTask {
//个推批量推送
geTuiService
.
pushListMessage
(
form
,
true
);
}
log
.
error
(
"本次推送目标数:{}"
,
list
.
size
());
}
}
}
...
...
@@ -246,7 +248,7 @@ public class UserTagsTask {
//List<UserMenusEntity> afterTag = getAfterTag(id, max, tags);
userMenusList
=
getAfterTag
(
id
,
max
,
tags
);
//if (afterTag != null) {
// userMenusList.addAll(afterTag);
// userMenusList.addAll(afterTag);
//}
/*} else {
//过滤用户gid
...
...
src/test/java/com/weface/PushMessageApplicationTests.java
View file @
ed53074b
...
...
@@ -111,19 +111,17 @@ class PushMessageApplicationTests {
@Test
void
testRevoke
()
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"request_id"
,
String
.
valueOf
(
SnowIdUtil
.
nextId
()));
map
.
put
(
"audience"
,
"all"
);
String
taskId
=
"RASA_0726_e51c93e787d103e072e4cd2cd43e8500"
;
String
equipmentType
=
"kksh"
;
String
s
=
geTuiService
.
revokeTask
(
taskId
,
equipmentType
);
System
.
out
.
println
(
s
);
}
Map
<
String
,
Object
>
push_message
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
revoke
=
new
HashMap
<>();
revoke
.
put
(
"old_task_id"
,
"RASA_0127_011f801354c5236738787cdda86cf232"
);
revoke
.
put
(
"force"
,
false
);
push_message
.
put
(
"revoke"
,
revoke
);
map
.
put
(
"push_message"
,
push_message
);
String
url
=
GeTuiService
.
GE_TUI_BASE_URL
+
geTuiService
.
getAppId
(
"kksh"
)
+
"/push/all"
;
String
kk_sh_token_ge_tui
=
geTuiService
.
getAuthToken
(
"kk_sh_token_ge_tui"
);
String
s
=
geTuiService
.
generalPost
(
url
,
kk_sh_token_ge_tui
,
map
);
@Test
void
testPushResult
(){
String
taskId
=
"RASA_0726_e51c93e787d103e072e4cd2cd43e8500"
;
String
equipmentType
=
"kksh"
;
String
s
=
geTuiService
.
getReportByTaskId
(
taskId
,
equipmentType
);
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