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
f4dd76c4
Commit
f4dd76c4
authored
Jan 27, 2022
by
renandong
🇨🇳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1,群推参数从配置文件中取
parent
17f7a014
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
65 deletions
+118
-65
GeTuiService.java
src/main/java/com/weface/component/GeTuiService.java
+86
-46
MenuService.java
src/main/java/com/weface/component/MenuService.java
+7
-4
PushController.java
src/main/java/com/weface/controller/PushController.java
+5
-2
application.yml
src/main/resources/application.yml
+2
-1
PushMessageApplicationTests.java
src/test/java/com/weface/PushMessageApplicationTests.java
+18
-12
No files found.
src/main/java/com/weface/component/GeTui
Utils
.java
→
src/main/java/com/weface/component/GeTui
Service
.java
View file @
f4dd76c4
...
@@ -14,11 +14,15 @@ import com.weface.common.exception.RRException;
...
@@ -14,11 +14,15 @@ import com.weface.common.exception.RRException;
import
com.weface.common.utils.Base64Util
;
import
com.weface.common.utils.Base64Util
;
import
com.weface.common.utils.HttpUtil
;
import
com.weface.common.utils.HttpUtil
;
import
com.weface.common.utils.RedisUtil
;
import
com.weface.common.utils.RedisUtil
;
import
com.weface.config.GeTuiApp
;
import
com.weface.config.GeTuiConfig
;
import
com.weface.dto.InformForm
;
import
com.weface.dto.InformForm
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -30,20 +34,12 @@ import java.util.concurrent.TimeUnit;
...
@@ -30,20 +34,12 @@ import java.util.concurrent.TimeUnit;
* @author Administrator
* @author Administrator
* @CreateTime: 2021/11/2
* @CreateTime: 2021/11/2
*/
*/
@Component
@Slf4j
@Slf4j
public
class
GeTuiUtils
{
public
class
GeTuiService
{
public
static
final
String
KK_SH_APP_ID
=
"CYol79N33N71BV6dcjrqj3"
;
public
static
final
String
KK_SH_MASTER_SECRET
=
"mekLZ4frLu7RHtKsN9mQn"
;
public
static
final
String
KK_SH_APP_KEY
=
"rdLx5zumRK7oEme8MheAh8"
;
public
static
final
String
KK_SB_APP_ID
=
"Ued41NRq7j9Nh1qI81gQ54"
;
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"
;
@Resource
private
GeTuiApp
geTuiApp
;
public
static
final
String
GE_TUI_BASE_URL
=
"https://restapi.getui.com/v2/"
;
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
BASEURL
=
"https://openapi-gi.getui.com/v2/"
;
public
static
final
String
ENCODING
=
"UTF-8"
;
public
static
final
String
ENCODING
=
"UTF-8"
;
...
@@ -60,7 +56,11 @@ public class GeTuiUtils {
...
@@ -60,7 +56,11 @@ public class GeTuiUtils {
* @param key 缓存key
* @param key 缓存key
* @return 从缓存中拿token
* @return 从缓存中拿token
*/
*/
public
static
String
getAuthToken
(
String
key
)
{
public
String
getAuthToken
(
String
key
)
{
GeTuiConfig
kksh
=
getConfig
(
"kksh"
);
GeTuiConfig
kksb
=
getConfig
(
"kksb"
);
GeTuiConfig
kkwj
=
getConfig
(
"kkwj"
);
GeTuiConfig
kkmz
=
getConfig
(
"kkmz"
);
String
authToken
=
""
;
String
authToken
=
""
;
try
{
try
{
boolean
flag
=
false
;
boolean
flag
=
false
;
...
@@ -77,38 +77,45 @@ public class GeTuiUtils {
...
@@ -77,38 +77,45 @@ public class GeTuiUtils {
String
geTui
=
null
;
String
geTui
=
null
;
switch
(
key
)
{
switch
(
key
)
{
case
"kk_sh_token"
:
case
"kk_sh_token"
:
authToken
=
getAuth
(
KK_SH_APP_ID
,
KK_SH_APP_KEY
,
KK_SH_MASTER_SECRET
);
authToken
=
getAuth
(
kksh
.
getAppId
(),
kksh
.
getAppkey
(),
kksh
.
getMastersecret
()
);
if
(
ObjectUtil
.
isNull
(
authToken
))
{
if
(
ObjectUtil
.
isNull
(
authToken
))
{
throw
new
RRException
(
"获取看看生活个像token失败"
);
throw
new
RRException
(
"获取看看生活个像token失败"
);
}
}
break
;
break
;
case
"kk_sb_token"
:
case
"kk_sb_token"
:
authToken
=
getAuth
(
KK_SB_APP_ID
,
KK_SB_APP_KEY
,
KK_SB_MASTER_SECRET
);
authToken
=
getAuth
(
kksb
.
getAppId
(),
kksb
.
getAppkey
(),
kksb
.
getMastersecret
()
);
if
(
ObjectUtil
.
isNull
(
authToken
))
{
if
(
ObjectUtil
.
isNull
(
authToken
))
{
throw
new
RRException
(
"获取看看社保个像token失败"
);
throw
new
RRException
(
"获取看看社保个像token失败"
);
}
}
break
;
break
;
case
"kk_sh_token_ge_tui"
:
case
"kk_sh_token_ge_tui"
:
authToken
=
getGeTuiAuth
(
KK_SH_APP_ID
,
KK_SH_APP_KEY
,
KK_SH_MASTER_SECRET
);
authToken
=
getGeTuiAuth
(
kksh
.
getAppId
(),
kksh
.
getAppkey
(),
kksh
.
getMastersecret
()
);
if
(
ObjectUtil
.
isNull
(
authToken
))
{
if
(
ObjectUtil
.
isNull
(
authToken
))
{
throw
new
RRException
(
"获取看看生活个推token失败"
);
throw
new
RRException
(
"获取看看生活个推token失败"
);
}
}
geTui
=
key
;
geTui
=
key
;
break
;
break
;
case
"kk_sb_token_ge_tui"
:
case
"kk_sb_token_ge_tui"
:
authToken
=
getGeTuiAuth
(
KK_SB_APP_ID
,
KK_SB_APP_KEY
,
KK_SB_MASTER_SECRET
);
authToken
=
getGeTuiAuth
(
kksb
.
getAppId
(),
kksb
.
getAppkey
(),
kksb
.
getMastersecret
()
);
if
(
ObjectUtil
.
isNull
(
authToken
))
{
if
(
ObjectUtil
.
isNull
(
authToken
))
{
throw
new
RRException
(
"获取看看社保个推token失败"
);
throw
new
RRException
(
"获取看看社保个推token失败"
);
}
}
geTui
=
key
;
geTui
=
key
;
break
;
break
;
case
"kk_wj_token_ge_tui"
:
case
"kk_wj_token_ge_tui"
:
authToken
=
getGeTuiAuth
(
KK_WJ_APP_ID
,
KK_WJ_APP_KEY
,
KK_WJ_MASTER_SECRET
);
authToken
=
getGeTuiAuth
(
kkwj
.
getAppId
(),
kkwj
.
getAppkey
(),
kkwj
.
getMastersecret
()
);
if
(
ObjectUtil
.
isNull
(
authToken
))
{
if
(
ObjectUtil
.
isNull
(
authToken
))
{
throw
new
RRException
(
"获取看看卫建个推token失败"
);
throw
new
RRException
(
"获取看看卫建个推token失败"
);
}
}
geTui
=
key
;
geTui
=
key
;
break
;
break
;
case
"kk_mz_token_ge_tui"
:
authToken
=
getGeTuiAuth
(
kkmz
.
getAppId
(),
kkmz
.
getAppkey
(),
kkmz
.
getMastersecret
());
if
(
ObjectUtil
.
isNull
(
authToken
))
{
throw
new
RRException
(
"获取看看民政个推token失败"
);
}
geTui
=
key
;
break
;
default
:
default
:
break
;
break
;
}
}
...
@@ -134,7 +141,7 @@ public class GeTuiUtils {
...
@@ -134,7 +141,7 @@ public class GeTuiUtils {
*
*
* @return JSONObject
* @return JSONObject
*/
*/
private
static
String
getAuth
(
String
appId
,
String
appKey
,
String
masterSecret
)
{
private
String
getAuth
(
String
appId
,
String
appKey
,
String
masterSecret
)
{
try
{
try
{
String
getAccessTokenUrl
=
BASEURL
+
appId
+
"/auth_sign"
;
String
getAccessTokenUrl
=
BASEURL
+
appId
+
"/auth_sign"
;
Long
timestamp
=
System
.
currentTimeMillis
();
Long
timestamp
=
System
.
currentTimeMillis
();
...
@@ -161,7 +168,7 @@ public class GeTuiUtils {
...
@@ -161,7 +168,7 @@ public class GeTuiUtils {
*
*
* @return JSONObject
* @return JSONObject
*/
*/
public
static
String
getGeTuiAuth
(
String
appId
,
String
appKey
,
String
masterSecret
)
{
public
String
getGeTuiAuth
(
String
appId
,
String
appKey
,
String
masterSecret
)
{
try
{
try
{
// 获取token地址
// 获取token地址
log
.
info
(
"开始获取个推token"
);
log
.
info
(
"开始获取个推token"
);
...
@@ -185,6 +192,26 @@ public class GeTuiUtils {
...
@@ -185,6 +192,26 @@ public class GeTuiUtils {
return
null
;
return
null
;
}
}
/**
* 获取appId
*
* @param appName app名称
* @return appId
*/
public
String
getAppId
(
String
appName
)
{
return
getConfig
(
appName
).
getAppId
();
}
/**
* 获取app配置
*
* @param appName app名称
* @return app配置
*/
public
GeTuiConfig
getConfig
(
String
appName
)
{
return
geTuiApp
.
getApps
().
get
(
appName
);
}
/**
/**
* 获取看看生活个像
* 获取看看生活个像
*
*
...
@@ -193,8 +220,8 @@ public class GeTuiUtils {
...
@@ -193,8 +220,8 @@ public class GeTuiUtils {
* @return 请求结果
* @return 请求结果
* @throws Exception 抛出异常
* @throws Exception 抛出异常
*/
*/
public
static
String
queryTagKKSH
(
List
<
String
>
gidList
,
String
token
)
throws
Exception
{
public
String
queryTagKKSH
(
List
<
String
>
gidList
,
String
token
)
throws
Exception
{
return
queryTag
(
gidList
,
token
,
KK_SH_APP_ID
);
return
queryTag
(
gidList
,
token
,
getAppId
(
"kksh"
)
);
}
}
/**
/**
...
@@ -205,8 +232,8 @@ public class GeTuiUtils {
...
@@ -205,8 +232,8 @@ public class GeTuiUtils {
* @return 请求结果
* @return 请求结果
* @throws Exception 抛出异常
* @throws Exception 抛出异常
*/
*/
public
static
String
queryTagKKSB
(
List
<
String
>
gidList
,
String
token
)
throws
Exception
{
public
String
queryTagKKSB
(
List
<
String
>
gidList
,
String
token
)
throws
Exception
{
return
queryTag
(
gidList
,
token
,
KK_SB_APP_ID
);
return
queryTag
(
gidList
,
token
,
getAppId
(
"kksb"
)
);
}
}
/**
/**
...
@@ -217,7 +244,7 @@ public class GeTuiUtils {
...
@@ -217,7 +244,7 @@ public class GeTuiUtils {
* @return 执行结果
* @return 执行结果
* @throws Exception 抛出异常
* @throws Exception 抛出异常
*/
*/
private
static
String
queryTag
(
List
<
String
>
gidList
,
String
token
,
String
appId
)
throws
Exception
{
private
String
queryTag
(
List
<
String
>
gidList
,
String
token
,
String
appId
)
throws
Exception
{
//请求url
//请求url
String
getUsersCidUrl
=
"https://openapi-gi.getui.com/v3/"
+
appId
+
"/query_tag"
;
String
getUsersCidUrl
=
"https://openapi-gi.getui.com/v3/"
+
appId
+
"/query_tag"
;
//将token以及用户ID封装调用画像查询接口
//将token以及用户ID封装调用画像查询接口
...
@@ -233,11 +260,12 @@ public class GeTuiUtils {
...
@@ -233,11 +260,12 @@ public class GeTuiUtils {
* 删除鉴权token
* 删除鉴权token
*
*
* @param token 接口调用凭证token
* @param token 接口调用凭证token
* @param appId appId
* @return 是否成功
* @return 是否成功
*/
*/
public
static
boolean
delToken
(
String
token
)
{
public
boolean
delToken
(
String
token
,
String
appId
)
{
try
{
try
{
String
body
=
HttpRequest
.
delete
(
GE_TUI_BASE_URL
+
KK_SH_APP_ID
+
"/auth"
+
token
).
execute
().
body
();
String
body
=
HttpRequest
.
delete
(
GE_TUI_BASE_URL
+
appId
+
"/auth"
+
token
).
execute
().
body
();
if
(
HttpUtil
.
isJson2
(
body
))
{
if
(
HttpUtil
.
isJson2
(
body
))
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
body
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
body
);
return
jsonObject
.
containsKey
(
"code"
)
&&
jsonObject
.
getInteger
(
"code"
)
==
0
;
return
jsonObject
.
containsKey
(
"code"
)
&&
jsonObject
.
getInteger
(
"code"
)
==
0
;
...
@@ -257,7 +285,7 @@ public class GeTuiUtils {
...
@@ -257,7 +285,7 @@ public class GeTuiUtils {
* @param token 接口访问凭据
* @param token 接口访问凭据
* @return 消息推送结果
* @return 消息推送结果
*/
*/
public
static
String
singlePushAlias
(
Integer
device
,
MessageTemplate
messageTemplate
,
String
appId
,
String
token
)
throws
UnsupportedEncodingException
{
public
String
singlePushAlias
(
Integer
device
,
MessageTemplate
messageTemplate
,
String
appId
,
String
token
)
throws
UnsupportedEncodingException
{
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
device
,
false
,
1
,
messageTemplate
);
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
device
,
false
,
1
,
messageTemplate
);
//请求url
//请求url
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/single/alias"
;
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/single/alias"
;
...
@@ -268,12 +296,13 @@ public class GeTuiUtils {
...
@@ -268,12 +296,13 @@ public class GeTuiUtils {
/**
/**
* 【toSingle】执行cid单推
* 【toSingle】执行cid单推
*
*
* @param
appId appId
* @param
device 设备类型
* @param messageTemplate 消息
* @param messageTemplate 消息
* @param appId appId
* @param token 鉴权
* @param token 鉴权
* @return 执行结果
* @return 执行结果
*/
*/
public
static
String
singlePushCid
(
Integer
device
,
String
appId
,
MessageTemplate
messageTemplate
,
String
token
)
throws
UnsupportedEncodingException
{
public
String
singlePushCid
(
Integer
device
,
MessageTemplate
messageTemplate
,
String
appId
,
String
token
)
throws
UnsupportedEncodingException
{
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
device
,
false
,
0
,
messageTemplate
);
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
device
,
false
,
0
,
messageTemplate
);
//请求url
//请求url
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/single/cid"
;
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/single/cid"
;
...
@@ -284,11 +313,13 @@ public class GeTuiUtils {
...
@@ -284,11 +313,13 @@ public class GeTuiUtils {
/**
/**
* 创建消息拿到任务id
* 创建消息拿到任务id
*
*
* @param device 设备类型
* @param messageTemplate 消息模板
* @param messageTemplate 消息模板
* @param appId appId
* @param token token
* @param token token
* @return 任务id
* @return 任务id
*/
*/
public
static
String
getTaskId
(
Integer
device
,
String
appId
,
MessageTemplate
messageTemplate
,
String
token
)
throws
UnsupportedEncodingException
{
public
String
getTaskId
(
Integer
device
,
MessageTemplate
messageTemplate
,
String
appId
,
String
token
)
throws
UnsupportedEncodingException
{
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
device
,
true
,
1
,
messageTemplate
);
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
device
,
true
,
1
,
messageTemplate
);
//请求url
//请求url
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/list/message"
;
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/list/message"
;
...
@@ -306,8 +337,8 @@ public class GeTuiUtils {
...
@@ -306,8 +337,8 @@ public class GeTuiUtils {
* @param is_async 是否异步
* @param is_async 是否异步
* @return 执行结果
* @return 执行结果
*/
*/
public
static
String
listPushCid
(
String
[]
cid
,
String
token
,
String
taskId
,
boolean
is_async
)
{
public
String
listPushCid
(
String
[]
cid
,
String
token
,
String
taskId
,
boolean
is_async
)
{
String
url
=
GE_TUI_BASE_URL
+
KK_SH_APP_ID
+
"/push/list/cid"
;
String
url
=
GE_TUI_BASE_URL
+
getAppId
(
"kksh"
)
+
"/push/list/cid"
;
Map
<
String
,
Object
>
cids
=
new
HashMap
<>(
1
);
Map
<
String
,
Object
>
cids
=
new
HashMap
<>(
1
);
cids
.
put
(
"cid"
,
cid
);
cids
.
put
(
"cid"
,
cid
);
return
listPushTaskId
(
url
,
token
,
taskId
,
is_async
,
cids
);
return
listPushTaskId
(
url
,
token
,
taskId
,
is_async
,
cids
);
...
@@ -322,8 +353,8 @@ public class GeTuiUtils {
...
@@ -322,8 +353,8 @@ public class GeTuiUtils {
* @param is_async 是否异步
* @param is_async 是否异步
* @return 执行结果
* @return 执行结果
*/
*/
public
static
String
listPushAlias
(
String
[]
alias
,
String
token
,
String
taskId
,
boolean
is_async
)
{
public
String
listPushAlias
(
String
[]
alias
,
String
token
,
String
taskId
,
boolean
is_async
)
{
String
url
=
GE_TUI_BASE_URL
+
KK_SH_APP_ID
+
"/push/list/alias"
;
String
url
=
GE_TUI_BASE_URL
+
getAppId
(
"kksh"
)
+
"/push/list/alias"
;
Map
<
String
,
Object
>
aliass
=
new
HashMap
<>(
1
);
Map
<
String
,
Object
>
aliass
=
new
HashMap
<>(
1
);
aliass
.
put
(
"alias"
,
alias
);
aliass
.
put
(
"alias"
,
alias
);
return
listPushTaskId
(
url
,
token
,
taskId
,
is_async
,
aliass
);
return
listPushTaskId
(
url
,
token
,
taskId
,
is_async
,
aliass
);
...
@@ -339,7 +370,7 @@ public class GeTuiUtils {
...
@@ -339,7 +370,7 @@ public class GeTuiUtils {
* @param hashMao 推送目标用户
* @param hashMao 推送目标用户
* @return 执行结果
* @return 执行结果
*/
*/
private
static
String
listPushTaskId
(
String
url
,
String
token
,
String
taskId
,
boolean
is_async
,
Map
<
String
,
Object
>
hashMao
)
{
private
String
listPushTaskId
(
String
url
,
String
token
,
String
taskId
,
boolean
is_async
,
Map
<
String
,
Object
>
hashMao
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
3
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
3
);
map
.
put
(
"audience"
,
hashMao
);
map
.
put
(
"audience"
,
hashMao
);
map
.
put
(
"taskid"
,
taskId
);
map
.
put
(
"taskid"
,
taskId
);
...
@@ -353,9 +384,14 @@ public class GeTuiUtils {
...
@@ -353,9 +384,14 @@ public class GeTuiUtils {
* @param informForm 消息
* @param informForm 消息
* @return 执行状态
* @return 执行状态
*/
*/
public
static
CommonResult
listPush
(
InformForm
informForm
)
{
public
CommonResult
listPush
(
InformForm
informForm
)
{
MessageTemplate
messageTemplate
=
new
MessageTemplate
();
MessageTemplate
messageTemplate
=
new
MessageTemplate
();
try
{
try
{
GeTuiConfig
kksh
=
getConfig
(
"kksh"
);
GeTuiConfig
kksb
=
getConfig
(
"kksb"
);
GeTuiConfig
kkwj
=
getConfig
(
"kkwj"
);
GeTuiConfig
kkmz
=
getConfig
(
"kkmz"
);
Integer
device
=
informForm
.
getDevice
();
Integer
device
=
informForm
.
getDevice
();
if
(
device
==
null
)
{
if
(
device
==
null
)
{
device
=
4
;
device
=
4
;
...
@@ -376,16 +412,20 @@ public class GeTuiUtils {
...
@@ -376,16 +412,20 @@ public class GeTuiUtils {
//看看生活
//看看生活
case
"kksh"
:
case
"kksh"
:
String
kk_sh_token_ge_tui
=
getAuthToken
(
"kk_sh_token_ge_tui"
);
String
kk_sh_token_ge_tui
=
getAuthToken
(
"kk_sh_token_ge_tui"
);
result
=
GeTuiUtils
.
listPushToApp
(
device
,
messageTemplate
,
KK_SH_APP_ID
,
kk_sh_token_ge_tui
);
result
=
listPushToApp
(
device
,
messageTemplate
,
kksh
.
getAppId
()
,
kk_sh_token_ge_tui
);
break
;
break
;
//看看社保
//看看社保
case
"kksb"
:
case
"kksb"
:
String
kk_sb_token_ge_tui
=
getAuthToken
(
"kk_sb_token_ge_tui"
);
String
kk_sb_token_ge_tui
=
getAuthToken
(
"kk_sb_token_ge_tui"
);
result
=
GeTuiUtils
.
listPushToApp
(
device
,
messageTemplate
,
KK_SB_APP_ID
,
kk_sb_token_ge_tui
);
result
=
listPushToApp
(
device
,
messageTemplate
,
kksb
.
getAppId
()
,
kk_sb_token_ge_tui
);
break
;
break
;
case
"kkwj"
:
case
"kkwj"
:
String
kk_wj_token_ge_tui
=
getAuthToken
(
"kk_wj_token_ge_tui"
);
String
kk_wj_token_ge_tui
=
getAuthToken
(
"kk_wj_token_ge_tui"
);
result
=
GeTuiUtils
.
listPushToApp
(
device
,
messageTemplate
,
KK_WJ_APP_ID
,
kk_wj_token_ge_tui
);
result
=
listPushToApp
(
device
,
messageTemplate
,
kkwj
.
getAppId
(),
kk_wj_token_ge_tui
);
break
;
case
"kkmz"
:
String
kk_mz_token_ge_tui
=
getAuthToken
(
"kk_mz_token_ge_tui"
);
result
=
listPushToApp
(
device
,
messageTemplate
,
kkmz
.
getAppId
(),
kk_mz_token_ge_tui
);
break
;
break
;
default
:
default
:
break
;
break
;
...
@@ -411,7 +451,7 @@ public class GeTuiUtils {
...
@@ -411,7 +451,7 @@ public class GeTuiUtils {
* @param token token
* @param token token
* @return 执行结果
* @return 执行结果
*/
*/
public
static
String
listPushToApp
(
Integer
device
,
MessageTemplate
messageTemplate
,
String
appId
,
String
token
)
throws
UnsupportedEncodingException
{
public
String
listPushToApp
(
Integer
device
,
MessageTemplate
messageTemplate
,
String
appId
,
String
token
)
throws
UnsupportedEncodingException
{
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
device
,
false
,
1
,
messageTemplate
);
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
device
,
false
,
1
,
messageTemplate
);
//请求url
//请求url
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/all"
;
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/all"
;
...
@@ -425,7 +465,7 @@ public class GeTuiUtils {
...
@@ -425,7 +465,7 @@ public class GeTuiUtils {
* @param messageTemplate 消息模板
* @param messageTemplate 消息模板
* @return map对象
* @return map对象
*/
*/
public
static
Map
<
String
,
Object
>
convertBeanToMap
(
Integer
device
,
boolean
flag
,
int
type
,
MessageTemplate
messageTemplate
)
throws
UnsupportedEncodingException
{
public
Map
<
String
,
Object
>
convertBeanToMap
(
Integer
device
,
boolean
flag
,
int
type
,
MessageTemplate
messageTemplate
)
throws
UnsupportedEncodingException
{
if
(
messageTemplate
==
null
)
{
if
(
messageTemplate
==
null
)
{
return
null
;
return
null
;
}
}
...
@@ -498,7 +538,7 @@ public class GeTuiUtils {
...
@@ -498,7 +538,7 @@ public class GeTuiUtils {
* @param push_message 消息
* @param push_message 消息
* @return json
* @return json
*/
*/
public
static
cn
.
hutool
.
json
.
JSONObject
setChannel
(
MessageTemplate
.
PushMessage
push_message
)
throws
UnsupportedEncodingException
{
public
cn
.
hutool
.
json
.
JSONObject
setChannel
(
MessageTemplate
.
PushMessage
push_message
)
throws
UnsupportedEncodingException
{
Map
<
String
,
Object
>
channel
=
new
HashMap
<>();
Map
<
String
,
Object
>
channel
=
new
HashMap
<>();
//获取ios配置
//获取ios配置
channel
.
put
(
"ios"
,
getIosChannel
(
push_message
));
channel
.
put
(
"ios"
,
getIosChannel
(
push_message
));
...
@@ -513,7 +553,7 @@ public class GeTuiUtils {
...
@@ -513,7 +553,7 @@ public class GeTuiUtils {
* @param push_message 消息
* @param push_message 消息
* @return ios配置
* @return ios配置
*/
*/
private
static
Map
<
String
,
Object
>
getIosChannel
(
MessageTemplate
.
PushMessage
push_message
)
throws
UnsupportedEncodingException
{
private
Map
<
String
,
Object
>
getIosChannel
(
MessageTemplate
.
PushMessage
push_message
)
throws
UnsupportedEncodingException
{
Map
<
String
,
Object
>
ios
=
new
HashMap
<>();
Map
<
String
,
Object
>
ios
=
new
HashMap
<>();
ios
.
put
(
"type"
,
"notify"
);
ios
.
put
(
"type"
,
"notify"
);
// ios.put("auto_badge", "+1");
// ios.put("auto_badge", "+1");
...
@@ -539,7 +579,7 @@ public class GeTuiUtils {
...
@@ -539,7 +579,7 @@ public class GeTuiUtils {
* @param push_message 消息
* @param push_message 消息
* @return android配置
* @return android配置
*/
*/
private
static
Map
<
String
,
Object
>
getAndroidChannel
(
MessageTemplate
.
PushMessage
push_message
)
throws
UnsupportedEncodingException
{
private
Map
<
String
,
Object
>
getAndroidChannel
(
MessageTemplate
.
PushMessage
push_message
)
throws
UnsupportedEncodingException
{
Map
<
String
,
Object
>
android
=
new
HashMap
<>();
Map
<
String
,
Object
>
android
=
new
HashMap
<>();
Map
<
String
,
Object
>
ups
=
new
HashMap
<>();
Map
<
String
,
Object
>
ups
=
new
HashMap
<>();
MessageTemplate
.
PushMessage
.
Transmission
transmission
=
push_message
.
getTransmission
();
MessageTemplate
.
PushMessage
.
Transmission
transmission
=
push_message
.
getTransmission
();
...
@@ -565,7 +605,7 @@ public class GeTuiUtils {
...
@@ -565,7 +605,7 @@ public class GeTuiUtils {
* @param map 请求体参数
* @param map 请求体参数
* @return 结果
* @return 结果
*/
*/
public
static
String
generalPost
(
String
url
,
String
token
,
Map
<
String
,
Object
>
map
)
{
public
String
generalPost
(
String
url
,
String
token
,
Map
<
String
,
Object
>
map
)
{
HttpRequest
post
=
HttpRequest
.
post
(
url
);
HttpRequest
post
=
HttpRequest
.
post
(
url
);
//设置请求头token
//设置请求头token
post
.
header
(
"token"
,
token
);
post
.
header
(
"token"
,
token
);
...
...
src/main/java/com/weface/component/MenuService.java
View file @
f4dd76c4
...
@@ -14,6 +14,7 @@ import com.weface.entity.UserTagEntity;
...
@@ -14,6 +14,7 @@ import com.weface.entity.UserTagEntity;
import
com.weface.entity.UserMenusEntity
;
import
com.weface.entity.UserMenusEntity
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.*
;
import
java.util.*
;
...
@@ -26,6 +27,8 @@ import java.util.*;
...
@@ -26,6 +27,8 @@ import java.util.*;
@Component
@Component
public
class
MenuService
{
public
class
MenuService
{
@Autowired
private
GeTuiService
geTuiService
;
/**
/**
* 从map中解析标签并收集关系表数据
* 从map中解析标签并收集关系表数据
...
@@ -88,9 +91,9 @@ public class MenuService {
...
@@ -88,9 +91,9 @@ public class MenuService {
//获取token
//获取token
String
kk_sh_token
=
"kk_sh_token"
;
String
kk_sh_token
=
"kk_sh_token"
;
try
{
try
{
String
authToken
=
GeTuiUtils
.
getAuthToken
(
kk_sh_token
);
String
authToken
=
geTuiService
.
getAuthToken
(
kk_sh_token
);
//将token以及用户ID封装调用画像查询接口
//将token以及用户ID封装调用画像查询接口
String
result
=
GeTuiUtils
.
queryTagKKSH
(
gidList
,
authToken
);
String
result
=
geTuiService
.
queryTagKKSH
(
gidList
,
authToken
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
//判断返回json内是否包含要解析的userTag
//判断返回json内是否包含要解析的userTag
if
(
jsonObject
.
containsKey
(
"userTag"
))
{
if
(
jsonObject
.
containsKey
(
"userTag"
))
{
...
@@ -125,9 +128,9 @@ public class MenuService {
...
@@ -125,9 +128,9 @@ public class MenuService {
private
List
<
Map
<
String
,
Object
>>
getSBTags
(
List
<
String
>
gidList
,
List
<
MenuTagsEntity
>
tags
)
throws
Exception
{
private
List
<
Map
<
String
,
Object
>>
getSBTags
(
List
<
String
>
gidList
,
List
<
MenuTagsEntity
>
tags
)
throws
Exception
{
String
kk_sb_token
=
"kk_sb_token"
;
String
kk_sb_token
=
"kk_sb_token"
;
//获取token
//获取token
String
authToken
=
GeTuiUtils
.
getAuthToken
(
kk_sb_token
);
String
authToken
=
geTuiService
.
getAuthToken
(
kk_sb_token
);
//将token以及用户ID封装调用画像查询接口
//将token以及用户ID封装调用画像查询接口
String
result
=
GeTuiUtils
.
queryTagKKSB
(
gidList
,
authToken
);
String
result
=
geTuiService
.
queryTagKKSB
(
gidList
,
authToken
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
//判断返回json内是否包含要解析的userTag
//判断返回json内是否包含要解析的userTag
if
(
jsonObject
.
containsKey
(
"userTag"
))
{
if
(
jsonObject
.
containsKey
(
"userTag"
))
{
...
...
src/main/java/com/weface/controller/PushController.java
View file @
f4dd76c4
package
com
.
weface
.
controller
;
package
com
.
weface
.
controller
;
import
com.weface.code.CommonResult
;
import
com.weface.code.CommonResult
;
import
com.weface.component.GeTui
Utils
;
import
com.weface.component.GeTui
Service
;
import
com.weface.dto.InformForm
;
import
com.weface.dto.InformForm
;
import
com.weface.dto.MsgDTO
;
import
com.weface.dto.MsgDTO
;
import
com.weface.dto.PushDTO
;
import
com.weface.dto.PushDTO
;
...
@@ -24,6 +24,9 @@ public class PushController {
...
@@ -24,6 +24,9 @@ public class PushController {
@Autowired
@Autowired
private
PushService
pushService
;
private
PushService
pushService
;
@Autowired
private
GeTuiService
geTuiService
;
@PostMapping
(
"list"
)
@PostMapping
(
"list"
)
public
CommonResult
pushList
(
@RequestBody
PushDTO
param
)
throws
Exception
{
public
CommonResult
pushList
(
@RequestBody
PushDTO
param
)
throws
Exception
{
...
@@ -37,6 +40,6 @@ public class PushController {
...
@@ -37,6 +40,6 @@ public class PushController {
@PostMapping
(
"/all"
)
@PostMapping
(
"/all"
)
public
CommonResult
pushAll
(
@Validated
({
Default
.
class
})
InformForm
informForm
)
{
public
CommonResult
pushAll
(
@Validated
({
Default
.
class
})
InformForm
informForm
)
{
return
GeTuiUtils
.
listPush
(
informForm
);
return
geTuiService
.
listPush
(
informForm
);
}
}
}
}
src/main/resources/application.yml
View file @
f4dd76c4
...
@@ -32,7 +32,8 @@ getui:
...
@@ -32,7 +32,8 @@ getui:
apps
:
{
apps
:
{
kkwj
:
{
appkey
:
"
vIBAFNAEk88qekbfS3miE8"
,
mastersecret
:
"
JojRk0duJd6oXiHIyFPqj"
,
appId
:
"
LhnWI1t7hc7ABsYbWokXD6"
,
baseUrl
:
"
http://api.getui.com/apiex.htm"
},
kkwj
:
{
appkey
:
"
vIBAFNAEk88qekbfS3miE8"
,
mastersecret
:
"
JojRk0duJd6oXiHIyFPqj"
,
appId
:
"
LhnWI1t7hc7ABsYbWokXD6"
,
baseUrl
:
"
http://api.getui.com/apiex.htm"
},
kkmz
:
{
appkey
:
"
ywXeatlN0k5vDkHDQCqb87"
,
mastersecret
:
"
Jt4Rj3b3YA6qJkOmkN8HG3"
,
appId
:
"
739bQ9FSze62zjgXsZtAF4"
,
baseUrl
:
"
http://api.getui.com/apiex.htm"
},
kkmz
:
{
appkey
:
"
ywXeatlN0k5vDkHDQCqb87"
,
mastersecret
:
"
Jt4Rj3b3YA6qJkOmkN8HG3"
,
appId
:
"
739bQ9FSze62zjgXsZtAF4"
,
baseUrl
:
"
http://api.getui.com/apiex.htm"
},
kksh
:
{
appkey
:
"
rdLx5zumRK7oEme8MheAh8"
,
mastersecret
:
"
mekLZ4frLu7RHtKsN9mQn"
,
appId
:
"
CYol79N33N71BV6dcjrqj3"
,
baseUrl
:
"
http://api.getui.com/apiex.htm"
}
kksh
:
{
appkey
:
"
rdLx5zumRK7oEme8MheAh8"
,
mastersecret
:
"
mekLZ4frLu7RHtKsN9mQn"
,
appId
:
"
CYol79N33N71BV6dcjrqj3"
,
baseUrl
:
"
http://api.getui.com/apiex.htm"
},
kksb
:
{
appkey
:
"
2tLtJhcpij7lu3ksutgpU3"
,
mastersecret
:
"
b8MSgB7j8PAImc3eN0yuL9"
,
appId
:
"
Ued41NRq7j9Nh1qI81gQ54"
,
baseUrl
:
"
http://api.getui.com/apiex.htm"
}
}
}
#mybatis
#mybatis
...
...
src/test/java/com/weface/PushMessageApplicationTests.java
View file @
f4dd76c4
...
@@ -2,11 +2,10 @@ package com.weface;
...
@@ -2,11 +2,10 @@ package com.weface;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.http.HtmlUtil
;
import
com.weface.component.GeTuiService
;
import
com.weface.code.CommonResult
;
import
com.weface.component.GeTuiUtils
;
import
com.weface.component.MenuService
;
import
com.weface.component.MenuService
;
import
com.weface.component.MessageTemplate
;
import
com.weface.component.MessageTemplate
;
import
com.weface.config.GeTuiApp
;
import
com.weface.dto.InformForm
;
import
com.weface.dto.InformForm
;
import
com.weface.entity.MenuTagsEntity
;
import
com.weface.entity.MenuTagsEntity
;
import
com.weface.entity.UserTagEntity
;
import
com.weface.entity.UserTagEntity
;
...
@@ -19,6 +18,7 @@ import org.junit.jupiter.api.Test;
...
@@ -19,6 +18,7 @@ import org.junit.jupiter.api.Test;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
javax.annotation.Resource
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -40,6 +40,12 @@ class PushMessageApplicationTests {
...
@@ -40,6 +40,12 @@ class PushMessageApplicationTests {
@Autowired
@Autowired
private
MenuTagsService
menuTagsService
;
private
MenuTagsService
menuTagsService
;
@Autowired
private
GeTuiService
geTuiService
;
@Resource
private
GeTuiApp
geTuiApp
;
@Test
@Test
void
contextLoads
()
{
void
contextLoads
()
{
}
}
...
@@ -96,11 +102,11 @@ class PushMessageApplicationTests {
...
@@ -96,11 +102,11 @@ class PushMessageApplicationTests {
void
testConventTemplate
()
throws
UnsupportedEncodingException
{
void
testConventTemplate
()
throws
UnsupportedEncodingException
{
InformForm
informForm
=
new
InformForm
();
InformForm
informForm
=
new
InformForm
();
String
[]
alias
=
{
"kksh_10131492"
};
//
String[] alias = {"kksh_10131492"};
//
String[] alias = {"kksh_59354"};
String
[]
alias
=
{
"kksh_59354"
};
// String token = GeTuiUtils
.getAuthToken("kk_sh_token_ge_tui");
String
token
=
geTuiService
.
getAuthToken
(
"kk_sh_token_ge_tui"
);
String
token
=
GeTuiUtils
.
getAuthToken
(
"kk_sb_token_ge_tui"
);
// String token = geTuiService
.getAuthToken("kk_sb_token_ge_tui");
informForm
.
setTitle
(
"河南一名小学生确诊阳性!"
);
informForm
.
setTitle
(
"河南一名小学生确诊阳性!"
);
informForm
.
setBody
(
"1月23日新增一例本土确诊病例!为11岁小学生"
);
informForm
.
setBody
(
"1月23日新增一例本土确诊病例!为11岁小学生"
);
...
@@ -121,8 +127,8 @@ class PushMessageApplicationTests {
...
@@ -121,8 +127,8 @@ class PushMessageApplicationTests {
pushMessage
.
setTransmission
(
transmission
);
pushMessage
.
setTransmission
(
transmission
);
messageTemplate
.
setPush_message
(
pushMessage
);
messageTemplate
.
setPush_message
(
pushMessage
);
// String s = GeTuiUtils.singlePushAlias(4, messageTemplate, GeTuiUtils.KK_SH_APP_ID
, token);
String
s
=
geTuiService
.
singlePushAlias
(
4
,
messageTemplate
,
geTuiService
.
getAppId
(
"kksh"
)
,
token
);
String
s
=
GeTuiUtils
.
singlePushAlias
(
1
,
messageTemplate
,
GeTuiUtils
.
KK_SB_APP_ID
,
token
);
// String s = geTuiService.singlePushAlias(1, messageTemplate, geTuiService.getAppId("kksb")
, token);
System
.
out
.
println
(
s
);
System
.
out
.
println
(
s
);
}
}
...
@@ -139,9 +145,9 @@ class PushMessageApplicationTests {
...
@@ -139,9 +145,9 @@ class PushMessageApplicationTests {
revoke
.
put
(
"force"
,
false
);
revoke
.
put
(
"force"
,
false
);
push_message
.
put
(
"revoke"
,
revoke
);
push_message
.
put
(
"revoke"
,
revoke
);
map
.
put
(
"push_message"
,
push_message
);
map
.
put
(
"push_message"
,
push_message
);
String
url
=
GeTui
Utils
.
GE_TUI_BASE_URL
+
GeTuiUtils
.
KK_SH_APP_ID
+
"/push/all"
;
String
url
=
GeTui
Service
.
GE_TUI_BASE_URL
+
geTuiService
.
getAppId
(
"kksh"
)
+
"/push/all"
;
String
kk_sh_token_ge_tui
=
GeTuiUtils
.
getAuthToken
(
"kk_sh_token_ge_tui"
);
String
kk_sh_token_ge_tui
=
geTuiService
.
getAuthToken
(
"kk_sh_token_ge_tui"
);
String
s
=
GeTuiUtils
.
generalPost
(
url
,
kk_sh_token_ge_tui
,
map
);
String
s
=
geTuiService
.
generalPost
(
url
,
kk_sh_token_ge_tui
,
map
);
System
.
out
.
println
(
s
);
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