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
2acfaec5
Commit
2acfaec5
authored
Nov 01, 2022
by
renandong
🇨🇳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1,推送消息增加可推送长文本和大图
parent
24bda6f4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
16 deletions
+97
-16
ValidatorParam.java
...main/java/com/weface/common/validator/ValidatorParam.java
+26
-0
MobPushService.java
src/main/java/com/weface/component/MobPushService.java
+39
-6
PushController.java
src/main/java/com/weface/controller/PushController.java
+20
-8
InformForm.java
src/main/java/com/weface/dto/InformForm.java
+6
-2
PushLogServiceImpl.java
src/main/java/com/weface/serviceimpl/PushLogServiceImpl.java
+6
-0
No files found.
src/main/java/com/weface/common/validator/ValidatorParam.java
View file @
2acfaec5
...
@@ -5,13 +5,39 @@ import com.weface.code.ResultCode;
...
@@ -5,13 +5,39 @@ import com.weface.code.ResultCode;
import
com.weface.dto.InformForm
;
import
com.weface.dto.InformForm
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.Objects
;
/**
/**
* @author : Administrator
* @author : Administrator
* @date : 2022/4/21 14:28
* @date : 2022/4/21 14:28
*/
*/
public
class
ValidatorParam
{
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
)
{
public
static
CommonResult
validPushSingleAlias
(
InformForm
informForm
)
{
String
body
=
informForm
.
getBody
();
String
body
=
informForm
.
getBody
();
if
(
body
.
length
()
>
60
)
{
if
(
body
.
length
()
>
60
)
{
...
...
src/main/java/com/weface/component/MobPushService.java
View file @
2acfaec5
...
@@ -15,6 +15,7 @@ import com.weface.common.utils.Model;
...
@@ -15,6 +15,7 @@ import com.weface.common.utils.Model;
import
com.weface.dto.InformForm
;
import
com.weface.dto.InformForm
;
import
com.weface.service.PushLogService
;
import
com.weface.service.PushLogService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -152,7 +153,12 @@ public class MobPushService {
...
@@ -152,7 +153,12 @@ public class MobPushService {
return
Model
.
error
();
return
Model
.
error
();
}
}
/**
* 通过 workId查询当前消息推送结果
*
* @param workId 推送id
* @return 是否收到
*/
public
boolean
getPushInfoById
(
String
workId
)
{
public
boolean
getPushInfoById
(
String
workId
)
{
String
reqUrl
=
"http://api.push.mob.com/v3/stats/getByWorkId"
;
String
reqUrl
=
"http://api.push.mob.com/v3/stats/getByWorkId"
;
Map
<
String
,
Object
>
request
=
new
HashMap
<>();
Map
<
String
,
Object
>
request
=
new
HashMap
<>();
...
@@ -221,7 +227,7 @@ public class MobPushService {
...
@@ -221,7 +227,7 @@ public class MobPushService {
//推送类型:1通知;2自定义
//推送类型:1通知;2自定义
pushNotify
.
put
(
"type"
,
1
);
pushNotify
.
put
(
"type"
,
1
);
//android通知消息, type=1, android
//android通知消息, type=1, android
Map
<
String
,
Object
>
androidNotify
=
getAndroidNotify
();
Map
<
String
,
Object
>
androidNotify
=
getAndroidNotify
(
informForm
);
if
(!
androidNotify
.
isEmpty
())
{
if
(!
androidNotify
.
isEmpty
())
{
pushNotify
.
put
(
"androidNotify"
,
androidNotify
);
pushNotify
.
put
(
"androidNotify"
,
androidNotify
);
}
}
...
@@ -236,7 +242,7 @@ public class MobPushService {
...
@@ -236,7 +242,7 @@ public class MobPushService {
//推送时,不走厂商通道。1: 开启,不走厂商通道;其它,关闭 ,默认关闭。
//推送时,不走厂商通道。1: 开启,不走厂商通道;其它,关闭 ,默认关闭。
pushNotify
.
put
(
"skipFactory"
,
0
);
pushNotify
.
put
(
"skipFactory"
,
0
);
//推送策略: * 1:先走tcp,再走厂商 * 2:先走厂商,再走tcp * 3:只走厂商 * 4:只走tcp (厂商透传policy只支持策略3或4)
//推送策略: * 1:先走tcp,再走厂商 * 2:先走厂商,再走tcp * 3:只走厂商 * 4:只走tcp (厂商透传policy只支持策略3或4)
pushNotify
.
put
(
"policy"
,
2
);
pushNotify
.
put
(
"policy"
,
1
);
//拓展参数
//拓展参数
pushNotify
.
put
(
"extrasMapList"
,
getExtrasMapList
(
informForm
));
pushNotify
.
put
(
"extrasMapList"
,
getExtrasMapList
(
informForm
));
return
pushNotify
;
return
pushNotify
;
...
@@ -391,16 +397,43 @@ public class MobPushService {
...
@@ -391,16 +397,43 @@ public class MobPushService {
/**
/**
* 安卓通知细节配置
* 安卓通知细节配置
*
*
* @param informForm 推送消息内容
* @return 安卓细节
* @return 安卓细节
*/
*/
private
Map
<
String
,
Object
>
getAndroidNotify
()
{
private
Map
<
String
,
Object
>
getAndroidNotify
(
InformForm
informForm
)
{
Map
<
String
,
Object
>
androidNotify
=
new
HashMap
<>(
1
);
Map
<
String
,
Object
>
androidNotify
=
new
HashMap
<>(
1
);
androidNotify
.
put
(
"warn"
,
"123"
);
androidNotify
.
put
(
"warn"
,
"123"
);
//androidNotify.put("content", new String[]{"测试这是一条数据"});
Integer
style
=
informForm
.
getStyle
();
//androidNotify.put("style", "3");
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
;
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通知细节配置
* ios通知细节配置
*
*
...
...
src/main/java/com/weface/controller/PushController.java
View file @
2acfaec5
...
@@ -51,6 +51,10 @@ public class PushController {
...
@@ -51,6 +51,10 @@ public class PushController {
public
CommonResult
pushAll
(
InformForm
informForm
)
{
public
CommonResult
pushAll
(
InformForm
informForm
)
{
log
.
error
(
"群推内容:{}"
,
JSONObject
.
toJSONString
(
informForm
));
log
.
error
(
"群推内容:{}"
,
JSONObject
.
toJSONString
(
informForm
));
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
CommonResult
result
=
ValidatorParam
.
validPushParams
(
informForm
);
if
(
result
!=
null
)
{
return
result
;
}
if
(
informForm
.
getEquipmentType
().
equals
(
"kksh"
))
{
if
(
informForm
.
getEquipmentType
().
equals
(
"kksh"
))
{
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
RADIO
);
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
RADIO
);
}
}
...
@@ -63,11 +67,15 @@ public class PushController {
...
@@ -63,11 +67,15 @@ public class PushController {
@PostMapping
(
"/single/alias"
)
@PostMapping
(
"/single/alias"
)
public
CommonResult
pushSingleAlias
(
@RequestBody
InformForm
informForm
)
{
public
CommonResult
pushSingleAlias
(
@RequestBody
InformForm
informForm
)
{
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
CommonResult
commonResult
=
ValidatorParam
.
validPushSingleAlias
(
informForm
);
CommonResult
result
=
ValidatorParam
.
validPushParams
(
informForm
);
if
(
commonResult
!=
null
)
{
if
(
result
!=
null
)
{
return
commonResult
;
return
result
;
}
result
=
ValidatorParam
.
validPushSingleAlias
(
informForm
);
if
(
result
!=
null
)
{
return
result
;
}
}
CommonResult
result
=
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
ALIAS
);
result
=
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
ALIAS
);
if
(
result
!=
null
)
{
if
(
result
!=
null
)
{
return
CommonResult
.
success
();
return
CommonResult
.
success
();
}
}
...
@@ -80,11 +88,15 @@ public class PushController {
...
@@ -80,11 +88,15 @@ public class PushController {
@PostMapping
(
"/single/cid"
)
@PostMapping
(
"/single/cid"
)
public
CommonResult
pushSingleCid
(
@RequestBody
InformForm
informForm
)
{
public
CommonResult
pushSingleCid
(
@RequestBody
InformForm
informForm
)
{
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
ValidatorUtils
.
validateEntity
(
informForm
,
InformForm
.
PushValid
.
class
);
CommonResult
commonResult
=
ValidatorParam
.
validPushSingleAlias
(
informForm
);
CommonResult
result
=
ValidatorParam
.
validPushParams
(
informForm
);
if
(
commonResult
!=
null
)
{
if
(
result
!=
null
)
{
return
commonResult
;
return
result
;
}
result
=
ValidatorParam
.
validPushSingleAlias
(
informForm
);
if
(
result
!=
null
)
{
return
result
;
}
}
CommonResult
result
=
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
RIDS
);
result
=
mobPushService
.
mobPush
(
informForm
,
Constant
.
PushTarget
.
RIDS
);
if
(
result
!=
null
)
{
if
(
result
!=
null
)
{
return
CommonResult
.
success
();
return
CommonResult
.
success
();
}
}
...
...
src/main/java/com/weface/dto/InformForm.java
View file @
2acfaec5
...
@@ -39,8 +39,12 @@ public class InformForm {
...
@@ -39,8 +39,12 @@ public class InformForm {
private
String
phone
;
private
String
phone
;
//推送模板
//推送模板
private
Integer
messageTemplate
;
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
{
public
interface
PushValid
{
}
}
...
...
src/main/java/com/weface/serviceimpl/PushLogServiceImpl.java
View file @
2acfaec5
package
com
.
weface
.
serviceimpl
;
package
com
.
weface
.
serviceimpl
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
...
@@ -113,6 +114,11 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
...
@@ -113,6 +114,11 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
}
}
pushLogEntity
.
setPushContent
(
body
);
pushLogEntity
.
setPushContent
(
body
);
pushLogEntity
.
setArriveStatus
(
1001
);
pushLogEntity
.
setArriveStatus
(
1001
);
String
jsonStr
=
JSONUtil
.
toJsonStr
(
informForm
);
if
(
jsonStr
.
length
()
>
200
)
{
jsonStr
=
jsonStr
.
substring
(
0
,
200
);
}
pushLogEntity
.
setBas1
(
jsonStr
);
pushLogEntity
.
setUpdateTime
(
new
Date
());
pushLogEntity
.
setUpdateTime
(
new
Date
());
return
pushLogEntity
;
return
pushLogEntity
;
}
}
...
...
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