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
256720fd
Commit
256720fd
authored
Jan 25, 2022
by
renandong
🇨🇳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1,调整定时任务每晚23点执行
parent
c6497559
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
9 deletions
+140
-9
GeTuiUtils.java
src/main/java/com/weface/component/GeTuiUtils.java
+75
-3
PushController.java
src/main/java/com/weface/controller/PushController.java
+10
-0
InformForm.java
src/main/java/com/weface/dto/InformForm.java
+22
-0
PushMessageApplicationTests.java
src/test/java/com/weface/PushMessageApplicationTests.java
+33
-6
No files found.
src/main/java/com/weface/component/GeTuiUtils.java
View file @
256720fd
package
com
.
weface
.
component
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.http.HttpException
;
...
...
@@ -8,10 +9,12 @@ import cn.hutool.http.HttpRequest;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.weface.code.CommonResult
;
import
com.weface.common.exception.RRException
;
import
com.weface.common.utils.Base64Util
;
import
com.weface.common.utils.HttpUtil
;
import
com.weface.common.utils.RedisUtil
;
import
com.weface.dto.InformForm
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -35,6 +38,10 @@ public class GeTuiUtils {
public
static
final
String
KK_SB_MASTER_SECRET
=
"b8MSgB7j8PAImc3eN0yuL9"
;
public
static
final
String
KK_SB_APP_KEY
=
"2tLtJhcpij7lu3ksutgpU3"
;
public
static
final
String
KK_WJ_APP_ID
=
"LhnWI1t7hc7ABsYbWokXD6"
;
public
static
final
String
KK_WJ_MASTER_SECRET
=
"JojRk0duJd6oXiHIyFPqj"
;
public
static
final
String
KK_WJ_APP_KEY
=
"vIBAFNAEk88qekbfS3miE8"
;
public
static
final
String
GE_TUI_BASE_URL
=
"https://restapi.getui.com/v2/"
;
public
static
final
String
BASEURL
=
"https://openapi-gi.getui.com/v2/"
;
public
static
final
String
ENCODING
=
"UTF-8"
;
...
...
@@ -93,6 +100,13 @@ public class GeTuiUtils {
}
geTui
=
key
;
break
;
case
"kk_wj_token_ge_tui"
:
authToken
=
getGeTuiAuth
(
KK_WJ_APP_ID
,
KK_WJ_APP_KEY
,
KK_WJ_MASTER_SECRET
);
if
(
ObjectUtil
.
isNull
(
authToken
))
{
throw
new
RRException
(
"获取看看卫建个推token失败"
);
}
geTui
=
key
;
break
;
default
:
break
;
}
...
...
@@ -237,14 +251,15 @@ public class GeTuiUtils {
* 【toSingle】执行别名单推
*
* @param alias 用户别名
* @param appId 应用id
* @param messageTemplate 消息模板
* @param token 接口访问凭据
* @return 消息推送结果
*/
public
static
String
singlePushAlias
(
String
[]
alias
,
MessageTemplate
messageTemplate
,
String
token
)
{
public
static
String
singlePushAlias
(
String
[]
alias
,
String
appId
,
MessageTemplate
messageTemplate
,
String
token
)
{
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
alias
,
messageTemplate
);
//请求url
String
url
=
GE_TUI_BASE_URL
+
KK_SH_APP_ID
+
"/push/single/alias"
;
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/single/alias"
;
log
.
info
(
"执行别名单推"
);
return
generalPost
(
url
,
token
,
map
);
}
...
...
@@ -315,6 +330,57 @@ public class GeTuiUtils {
return
generalPost
(
url
,
token
,
map
);
}
/**
* 群推
*
* @param informForm 消息
* @return 执行状态
*/
public
static
CommonResult
listPush
(
InformForm
informForm
)
{
MessageTemplate
messageTemplate
=
new
MessageTemplate
();
messageTemplate
.
setAudience
(
new
MessageTemplate
.
Audience
(
informForm
.
getAlias
()));
MessageTemplate
.
Settings
settings
=
new
MessageTemplate
.
Settings
();
settings
.
setTtl
(
3600000
);
messageTemplate
.
setSettings
(
settings
);
MessageTemplate
.
PushMessage
pushMessage
=
new
MessageTemplate
.
PushMessage
();
MessageTemplate
.
PushMessage
.
Notification
notification
=
new
MessageTemplate
.
PushMessage
.
Notification
();
BeanUtil
.
copyProperties
(
informForm
,
notification
,
CopyOptions
.
create
().
ignoreNullValue
());
notification
.
setChannel_level
(
4
);
pushMessage
.
setNotification
(
notification
);
messageTemplate
.
setPush_message
(
pushMessage
);
String
result
=
null
;
switch
(
informForm
.
getEquipmentType
())
{
//看看生活
case
"kksh"
:
String
kk_sh_token_ge_tui
=
getAuthToken
(
"kk_sh_token_ge_tui"
);
result
=
GeTuiUtils
.
listPushToApp
(
messageTemplate
,
KK_SH_APP_ID
,
kk_sh_token_ge_tui
);
break
;
//看看社保
case
"kksb"
:
String
kk_sb_token_ge_tui
=
getAuthToken
(
"kk_sb_token_ge_tui"
);
result
=
GeTuiUtils
.
listPushToApp
(
messageTemplate
,
KK_SB_APP_ID
,
kk_sb_token_ge_tui
);
break
;
case
"kkwj"
:
String
kk_wj_token_ge_tui
=
getAuthToken
(
"kk_wj_token_ge_tui"
);
result
=
GeTuiUtils
.
listPushToApp
(
messageTemplate
,
KK_WJ_APP_ID
,
kk_wj_token_ge_tui
);
break
;
default
:
break
;
}
if
(
result
==
null
)
{
return
CommonResult
.
failed
();
}
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
if
((
jsonObject
.
containsKey
(
"code"
)
&&
jsonObject
.
getInteger
(
"code"
)
==
0
))
{
JSONObject
data
=
jsonObject
.
getJSONObject
(
"data"
);
return
CommonResult
.
success
(
data
);
}
return
CommonResult
.
failed
();
}
/**
* 【toApp】执行群推
*
...
...
@@ -457,7 +523,13 @@ public class GeTuiUtils {
informAndroid
.
put
(
"title"
,
notification
.
getTitle
());
informAndroid
.
put
(
"body"
,
notification
.
getBody
());
informAndroid
.
put
(
"click_type"
,
notification
.
getClick_type
());
switch
(
notification
.
getClick_type
())
{
case
"url"
:
informAndroid
.
put
(
"url"
,
notification
.
getUrl
());
break
;
case
"intent"
:
informAndroid
.
put
(
"intent"
,
notification
.
getIntent
());
}
ups
.
put
(
"notification"
,
informAndroid
);
android
.
put
(
"ups"
,
ups
);
...
...
src/main/java/com/weface/controller/PushController.java
View file @
256720fd
package
com
.
weface
.
controller
;
import
com.weface.code.CommonResult
;
import
com.weface.component.GeTuiUtils
;
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
*/
...
...
@@ -29,4 +34,9 @@ public class PushController {
public
CommonResult
pushSingle
(
@RequestBody
MsgDTO
param
)
{
return
pushService
.
pushSingle
(
param
);
}
@PostMapping
(
"/all"
)
public
CommonResult
pushAll
(
@RequestBody
@Validated
({
Default
.
class
})
InformForm
informForm
)
{
return
GeTuiUtils
.
listPush
(
informForm
);
}
}
src/main/java/com/weface/dto/InformForm.java
0 → 100644
View file @
256720fd
package
com
.
weface
.
dto
;
import
lombok.Data
;
import
javax.validation.constraints.NotBlank
;
/**
* @author : Administrator
*/
@Data
public
class
InformForm
{
@NotBlank
private
String
title
;
@NotBlank
private
String
body
;
@NotBlank
private
String
click_type
;
private
String
url
;
private
String
[]
alias
;
@NotBlank
private
String
equipmentType
;
}
src/test/java/com/weface/PushMessageApplicationTests.java
View file @
256720fd
package
com
.
weface
;
import
cn.hutool.core.util.IdUtil
;
import
com.weface.component.GeTuiUtils
;
import
com.weface.component.MenuService
;
import
com.weface.component.MessageTemplate
;
...
...
@@ -15,7 +16,10 @@ import org.junit.jupiter.api.Test;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.CountDownLatch
;
...
...
@@ -87,7 +91,7 @@ class PushMessageApplicationTests {
}
@Test
void
testConventTemplate
()
{
void
testConventTemplate
()
throws
UnsupportedEncodingException
{
//String[] alias = {"kksh_10255318"};
//String[] alias = {"kksh_10131492"};
String
[]
alias
=
{
"kksh_59354"
};
...
...
@@ -100,17 +104,40 @@ class PushMessageApplicationTests {
MessageTemplate
.
PushMessage
pushMessage
=
new
MessageTemplate
.
PushMessage
();
MessageTemplate
.
PushMessage
.
Notification
notification
=
new
MessageTemplate
.
PushMessage
.
Notification
();
notification
.
setTitle
(
"看看生活提醒"
);
notification
.
setBody
(
"看看生活->让领钱更简单"
);
notification
.
setClick_type
(
"url"
);
notification
.
setUrl
(
"https://www.baidu.com/"
);
notification
.
setTitle
(
"河南一名小学生确诊阳性!"
);
notification
.
setBody
(
"1月23日新增一例本土确诊病例!为11岁小学生"
);
notification
.
setClick_type
(
"intent"
);
String
pack
=
"com.weface.kksocialsecurity/com.weface.kksocialsecurity.activity.WellcomeActivity"
;
String
str
=
"intent:#Intent;component=%s;S.kkparam={\"content\": \"%s\", \"ispush\": \"1\", \"preload\": \"2\", \"push_type\": \"0\", \"pushlabel\": \"\", \"pushts\": \"1561619033\", \"title\": \"%s\", \"url\": \"%s\"};end"
;
String
url
=
"https://kk.weface.com.cn/news/page/?id=c0933d0e2fc85f7333b6202dff0e611c&type=hot&from=101"
;
String
intent
=
String
.
format
(
str
,
pack
,
notification
.
getBody
(),
notification
.
getTitle
(),
URLEncoder
.
encode
(
url
,
"UTF-8"
));
// String intent = "intent:#Intent;component=com.weface.kksocialsecurity/com.weface.kksocialsecurity.activity.WellcomeActivity;S.kkparam={\"content\": \"1月23日新增一例本土确诊病例!为11岁小学生\", \"ispush\": \"1\", \"preload\": \"2\", \"push_type\": \"0\", \"pushlabel\": \"\", \"pushts\": \"1561619033\", \"title\": \"河南一名小学生确诊阳性!\", \"url\": \"https://kk.weface.com.cn/news/page/?id=c0933d0e2fc85f7333b6202dff0e611c&type=hot&from=101\"};end";
notification
.
setIntent
(
intent
);
notification
.
setChannel_level
(
4
);
pushMessage
.
setNotification
(
notification
);
messageTemplate
.
setPush_message
(
pushMessage
);
String
s
=
GeTuiUtils
.
singlePushAlias
(
alias
,
messageTemplate
,
token
);
String
s
=
GeTuiUtils
.
singlePushAlias
(
alias
,
GeTuiUtils
.
KK_SH_APP_ID
,
messageTemplate
,
token
);
System
.
out
.
println
(
s
);
}
@Test
void
testRevoke
()
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"request_id"
,
String
.
valueOf
(
IdUtil
.
getSnowflake
(
1
,
1
).
nextId
()));
map
.
put
(
"audience"
,
"all"
);
Map
<
String
,
Object
>
push_message
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
revoke
=
new
HashMap
<>();
revoke
.
put
(
"old_task_id"
,
"RASA_0124_1679436c706dc2ea869c7c43eed0fb7d"
);
revoke
.
put
(
"force"
,
false
);
push_message
.
put
(
"revoke"
,
revoke
);
map
.
put
(
"push_message"
,
push_message
);
String
url
=
GeTuiUtils
.
GE_TUI_BASE_URL
+
GeTuiUtils
.
KK_SH_APP_ID
+
"/push/all"
;
String
kk_sh_token_ge_tui
=
GeTuiUtils
.
getAuthToken
(
"kk_sh_token_ge_tui"
);
String
s
=
GeTuiUtils
.
generalPost
(
url
,
kk_sh_token_ge_tui
,
map
);
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