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
62b49ac1
Commit
62b49ac1
authored
Apr 20, 2022
by
renandong
🇨🇳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1,消息单推
2,推送回调
parent
6dc5c169
Changes
23
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
817 additions
and
225 deletions
+817
-225
PushResultCode.java
src/main/java/com/weface/code/PushResultCode.java
+23
-0
SnowIdUtil.java
src/main/java/com/weface/common/utils/SnowIdUtil.java
+25
-0
GeTuiPush.java
src/main/java/com/weface/component/GeTuiPush.java
+3
-3
GeTuiService.java
src/main/java/com/weface/component/GeTuiService.java
+243
-143
MenuService.java
src/main/java/com/weface/component/MenuService.java
+3
-6
MessageTemplate.java
src/main/java/com/weface/component/MessageTemplate.java
+1
-1
PushCallBackController.java
...in/java/com/weface/controller/PushCallBackController.java
+30
-0
PushController.java
src/main/java/com/weface/controller/PushController.java
+10
-0
PushCallBackDao.java
src/main/java/com/weface/dao/PushCallBackDao.java
+16
-0
PushLogDao.java
src/main/java/com/weface/dao/PushLogDao.java
+16
-0
InformForm.java
src/main/java/com/weface/dto/InformForm.java
+8
-1
PushCallBackEntity.java
src/main/java/com/weface/entity/PushCallBackEntity.java
+85
-0
PushLogEntity.java
src/main/java/com/weface/entity/PushLogEntity.java
+65
-0
PushCallBackService.java
src/main/java/com/weface/service/PushCallBackService.java
+18
-0
PushLogService.java
src/main/java/com/weface/service/PushLogService.java
+17
-0
MenuTagsServiceImpl.java
...main/java/com/weface/serviceimpl/MenuTagsServiceImpl.java
+3
-5
PushCallBackServiceImpl.java
.../java/com/weface/serviceimpl/PushCallBackServiceImpl.java
+108
-0
PushLogServiceImpl.java
src/main/java/com/weface/serviceimpl/PushLogServiceImpl.java
+55
-0
UserMenusServiceImpl.java
...ain/java/com/weface/serviceimpl/UserMenusServiceImpl.java
+3
-5
UserTagsTask.java
src/main/java/com/weface/task/UserTagsTask.java
+2
-1
PushCallBackDao.xml
src/main/resources/mapper/PushCallBackDao.xml
+26
-0
PushLogDao.xml
src/main/resources/mapper/PushLogDao.xml
+21
-0
PushMessageApplicationTests.java
src/test/java/com/weface/PushMessageApplicationTests.java
+36
-60
No files found.
src/main/java/com/weface/code/PushResultCode.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
code
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
/**
* @author : Administrator
* @date : 2022/4/19 14:35
*/
@Data
@Accessors
(
chain
=
true
)
public
class
PushResultCode
{
private
int
code
;
private
String
result
;
public
static
PushResultCode
ok
()
{
return
new
PushResultCode
().
setCode
(
0
).
setResult
(
"ok"
);
}
public
static
PushResultCode
error
()
{
return
new
PushResultCode
().
setCode
(
1
).
setResult
(
"error"
);
}
}
src/main/java/com/weface/common/utils/SnowIdUtil.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
common
.
utils
;
import
cn.hutool.core.lang.Snowflake
;
import
cn.hutool.core.util.IdUtil
;
/**
* @author : Administrator
* @date : 2022/2/16 14:58
*/
public
class
SnowIdUtil
{
private
static
final
Snowflake
SNOWFLAKE
;
static
{
SNOWFLAKE
=
IdUtil
.
getSnowflake
(
1
,
1
);
}
/**
* 通过雪花算法获取id,统一封装调用
*
* @return id
*/
public
static
Long
nextId
()
{
return
SNOWFLAKE
.
nextId
();
}
}
src/main/java/com/weface/component/GeTuiPush.java
View file @
62b49ac1
package
com
.
weface
.
component
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
com.weface.common.utils.SnowIdUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -49,7 +49,7 @@ public class GeTuiPush {
public
void
toSinglePush
(
String
alia
)
{
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"request_id"
,
String
.
valueOf
(
IdUtil
.
createSnowflake
(
1
,
1
)
.
nextId
()));
param
.
put
(
"request_id"
,
String
.
valueOf
(
SnowIdUtil
.
nextId
()));
Map
<
String
,
Object
>
audience
=
new
HashMap
<>();
List
<
String
>
alias
=
new
ArrayList
<>();
alias
.
add
(
alia
);
...
...
@@ -75,7 +75,7 @@ public class GeTuiPush {
public
void
toSingleBatchPush
(
String
alia
)
{
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"request_id"
,
String
.
valueOf
(
IdUtil
.
createSnowflake
(
1
,
1
)
.
nextId
()));
param
.
put
(
"request_id"
,
String
.
valueOf
(
SnowIdUtil
.
nextId
()));
Map
<
String
,
Object
>
audience
=
new
HashMap
<>();
List
<
String
>
alias
=
new
ArrayList
<>();
alias
.
add
(
alia
);
...
...
src/main/java/com/weface/component/GeTuiService.java
View file @
62b49ac1
This diff is collapsed.
Click to expand it.
src/main/java/com/weface/component/MenuService.java
View file @
62b49ac1
...
...
@@ -3,15 +3,13 @@ package com.weface.component;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.convert.ConvertException
;
import
cn.hutool.core.lang.Snowflake
;
import
cn.hutool.core.lang.TypeReference
;
import
cn.hutool.core.util.IdUtil
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.weface.common.utils.SnowIdUtil
;
import
com.weface.entity.MenuTagsEntity
;
import
com.weface.entity.UserTagEntity
;
import
com.weface.entity.UserMenusEntity
;
import
com.weface.entity.UserTagEntity
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -38,7 +36,6 @@ public class MenuService {
*/
public
List
<
UserMenusEntity
>
getTagUser
(
Map
<
String
,
Object
>
map
,
List
<
UserTagEntity
>
userInfo
)
{
try
{
Snowflake
snowflake
=
IdUtil
.
getSnowflake
(
1
,
1
);
//获取所有用户标签
List
<
Map
<
String
,
Object
>>
userTag
=
Convert
.
convert
(
new
TypeReference
<
List
<
Map
<
String
,
Object
>>>()
{
},
map
.
get
(
"userTag"
));
...
...
@@ -62,7 +59,7 @@ public class MenuService {
for
(
Long
aLong
:
list
)
{
//填充数据
UserMenusEntity
userMenusEntity
=
new
UserMenusEntity
();
userMenusEntity
.
setId
(
snowflake
.
nextId
());
userMenusEntity
.
setId
(
SnowIdUtil
.
nextId
());
userMenusEntity
.
setUserId
(
uid
);
userMenusEntity
.
setTagsId
(
aLong
);
userMenusEntity
.
setIsValid
(
1
);
...
...
src/main/java/com/weface/component/MessageTemplate.java
View file @
62b49ac1
...
...
@@ -107,7 +107,7 @@ public class MessageTemplate implements Serializable {
private
String
content
;
private
String
url
;
//0:h5 1:app原生
private
String
push_t
ype
;
private
Integer
pushT
ype
;
//跳转功能名称
private
String
className
;
//功能标题
...
...
src/main/java/com/weface/controller/PushCallBackController.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
controller
;
import
com.weface.code.PushResultCode
;
import
com.weface.service.PushCallBackService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
/**
* @author : Administrator
* @date : 2022/4/19 13:51
*/
@RestController
@RequestMapping
(
"/push"
)
public
class
PushCallBackController
{
@Autowired
private
PushCallBackService
pushCallBackService
;
@PostMapping
(
"/call/back/info"
)
public
PushResultCode
callBackForPush
(
HttpServletRequest
request
)
throws
IOException
{
return
pushCallBackService
.
saveCallBackInfo
(
request
);
}
}
\ No newline at end of file
src/main/java/com/weface/controller/PushController.java
View file @
62b49ac1
...
...
@@ -42,4 +42,14 @@ public class PushController {
public
CommonResult
pushAll
(
@Validated
({
Default
.
class
})
InformForm
informForm
)
{
return
geTuiService
.
listPush
(
informForm
);
}
@PostMapping
(
"/single/alias"
)
public
CommonResult
pushSingleAlias
(
@Validated
({
Default
.
class
})
InformForm
informForm
)
{
return
geTuiService
.
pushSingleAlias
(
informForm
);
}
@PostMapping
(
"/single/cid"
)
public
CommonResult
pushSingleCid
(
@Validated
({
Default
.
class
})
InformForm
informForm
)
{
return
geTuiService
.
pushSingleCid
(
informForm
);
}
}
src/main/java/com/weface/dao/PushCallBackDao.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
dao
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.weface.entity.PushCallBackEntity
;
import
org.apache.ibatis.annotations.Mapper
;
/**
*
*
* @author admin
* @date 2022-04-20 09:54:09
*/
@Mapper
public
interface
PushCallBackDao
extends
BaseMapper
<
PushCallBackEntity
>
{
}
src/main/java/com/weface/dao/PushLogDao.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
dao
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.weface.entity.PushLogEntity
;
import
org.apache.ibatis.annotations.Mapper
;
/**
*
*
* @author admin
* @date 2022-04-20 09:54:09
*/
@Mapper
public
interface
PushLogDao
extends
BaseMapper
<
PushLogEntity
>
{
}
src/main/java/com/weface/dto/InformForm.java
View file @
62b49ac1
...
...
@@ -16,9 +16,10 @@ public class InformForm {
@NotBlank
private
String
body
;
//跳转url
@NotBlank
private
String
url
;
//推送类型 0:h5 1:原生
private
String
push_t
ype
;
private
Integer
pushT
ype
;
//跳转功能名称
private
String
className
;
//功能标题
...
...
@@ -32,5 +33,11 @@ public class InformForm {
private
Integer
device
;
//定速推送,例如100,个推控制下发速度在100条/秒左右,0表示不限速
private
Integer
speed
;
//推送目标
private
String
[]
cid
;
//推送手机号
private
String
phone
;
//推送模板
private
Integer
messageTemplate
;
}
src/main/java/com/weface/entity/PushCallBackEntity.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
entity
;
import
com.baomidou.mybatisplus.annotation.*
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
*
*
* @author admin
* @date 2022-04-20 09:54:09
*/
@Data
@TableName
(
"tb_push_call_back"
)
public
class
PushCallBackEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
*
*/
@TableId
private
Long
id
;
/**
* 应用 ID
*/
private
String
appid
;
/**
* 接收人CID
*/
private
String
cid
;
/**
* 任务 ID(即 ContentID)
*/
private
String
taskid
;
/**
* 消息 ID
*/
private
String
msgid
;
/**
* 结果码(200 -- 成功,400 -- 推送苹果接口失败, 401 -- 用户不存在,402 -- 非活跃用户,500 -- 系统内部异常)目前只有 200 和 400,后续版本扩展。
*/
private
String
code
;
/**
* 推送结果描述
*/
private
String
desc
;
/**
* 签名
*/
private
String
sign
;
/**
* 回执 ID
*/
private
String
actionid
;
/**
* 回执上传时间
*/
private
Long
recvtime
;
/**
* 根据配置返回
*/
private
String
alias
;
/**
* 状态
*/
private
Integer
status
;
/**
* 是否删除 1:未删除 0 :删除
*/
@TableLogic
(
value
=
"1"
,
delval
=
"0"
)
@TableField
(
fill
=
FieldFill
.
INSERT
)
private
Integer
isValid
;
/**
* 创建时间
*/
@TableField
(
fill
=
FieldFill
.
INSERT
)
private
Date
createTime
;
/**
* 更新时间
*/
private
Date
updateTime
;
}
src/main/java/com/weface/entity/PushLogEntity.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
entity
;
import
com.baomidou.mybatisplus.annotation.*
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
*
*
* @author admin
* @date 2022-04-20 09:54:09
*/
@Data
@TableName
(
"tb_push_log"
)
public
class
PushLogEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
*
*/
@TableId
private
Long
id
;
/**
*
*/
private
String
taskId
;
/**
*
*/
private
String
cid
;
/**
*
*/
private
String
cidStatus
;
/**
*
*/
private
String
phone
;
/**
*
*/
private
Integer
messageTemplate
;
/**
*
*/
private
Integer
isArrive
;
/**
*
*/
@TableLogic
(
value
=
"1"
,
delval
=
"0"
)
@TableField
(
fill
=
FieldFill
.
INSERT
)
private
Integer
isValid
;
/**
*
*/
@TableField
(
fill
=
FieldFill
.
INSERT
)
private
Date
createTime
;
/**
*
*/
private
Date
updateTime
;
}
src/main/java/com/weface/service/PushCallBackService.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.weface.code.PushResultCode
;
import
com.weface.entity.PushCallBackEntity
;
import
javax.servlet.http.HttpServletRequest
;
/**
* @author admin
* @email admin@163.com
* @date 2022-04-20 09:54:09
*/
public
interface
PushCallBackService
extends
IService
<
PushCallBackEntity
>
{
public
PushResultCode
saveCallBackInfo
(
HttpServletRequest
request
);
}
src/main/java/com/weface/service/PushLogService.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
service
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.weface.entity.PushLogEntity
;
/**
* @author admin
* @email admin@163.com
* @date 2022-04-20 09:54:09
*/
public
interface
PushLogService
extends
IService
<
PushLogEntity
>
{
public
void
saveLog
(
JSONObject
data
,
String
phone
,
Integer
messageTemplate
);
}
src/main/java/com/weface/serviceimpl/MenuTagsServiceImpl.java
View file @
62b49ac1
package
com
.
weface
.
serviceimpl
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.lang.Snowflake
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.weface.code.CommonResult
;
import
com.weface.common.utils.BeanUtils
;
import
com.weface.common.utils.SnowIdUtil
;
import
com.weface.dao.MenuTagsDao
;
import
com.weface.dto.MenuTagsForm
;
import
com.weface.entity.MenuTagsEntity
;
...
...
@@ -24,7 +23,7 @@ import java.util.stream.Collectors;
* @author Administrator
*/
@Slf4j
@Transactional
@Transactional
(
rollbackFor
=
{
Exception
.
class
})
@Service
(
"menuTagsService"
)
public
class
MenuTagsServiceImpl
extends
ServiceImpl
<
MenuTagsDao
,
MenuTagsEntity
>
implements
MenuTagsService
{
...
...
@@ -69,9 +68,8 @@ public class MenuTagsServiceImpl extends ServiceImpl<MenuTagsDao, MenuTagsEntity
try
{
MenuTagsEntity
menuTagsEntity
=
new
MenuTagsEntity
();
BeanUtil
.
copyProperties
(
menuTagsForm
,
menuTagsEntity
,
BeanUtils
.
getNullPropertyNames
(
menuTagsForm
));
Snowflake
snowflake
=
IdUtil
.
getSnowflake
(
1
,
1
);
menuTagsEntity
.
setId
(
snowflake
.
nextId
());
menuTagsEntity
.
setId
(
SnowIdUtil
.
nextId
());
String
tagCode
=
""
;
boolean
flag
=
false
;
while
(!
flag
)
{
...
...
src/main/java/com/weface/serviceimpl/PushCallBackServiceImpl.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
serviceimpl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.weface.code.PushResultCode
;
import
com.weface.common.utils.SnowIdUtil
;
import
com.weface.config.GeTuiApp
;
import
com.weface.config.GeTuiConfig
;
import
com.weface.dao.PushCallBackDao
;
import
com.weface.entity.PushCallBackEntity
;
import
com.weface.service.PushCallBackService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.Assert
;
import
javax.annotation.Resource
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.security.MessageDigest
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.Map
;
/**
* @author : Administrator
* @date : 2022/4/19 14:08
*/
@Service
(
"pushCallBackService"
)
@Slf4j
@Transactional
(
rollbackFor
=
{
Exception
.
class
})
public
class
PushCallBackServiceImpl
extends
ServiceImpl
<
PushCallBackDao
,
PushCallBackEntity
>
implements
PushCallBackService
{
@Resource
private
GeTuiApp
geTuiApp
;
/**
* 保存推送回调
*
* @param request 回调请求
* @return 执行结果
*/
@Override
public
PushResultCode
saveCallBackInfo
(
HttpServletRequest
request
)
{
JSONObject
jsonObject
=
new
JSONObject
();
try
{
byte
[]
bytes
=
getRequestInputStream
(
request
);
String
callInfo
=
new
String
(
bytes
);
PushCallBackEntity
callBackInfo
=
JSONObject
.
parseObject
(
callInfo
,
PushCallBackEntity
.
class
);
String
appId
=
callBackInfo
.
getAppid
();
String
str
=
appId
+
callBackInfo
.
getCid
()
+
callBackInfo
.
getTaskid
()
+
callBackInfo
.
getMsgid
()
+
getMasterSecret
(
appId
);
String
sign
=
md5Encode
(
str
);
if
(!
callBackInfo
.
getSign
().
equals
(
sign
))
{
return
PushResultCode
.
error
();
}
String
taskid
=
callBackInfo
.
getTaskid
();
String
cid
=
callBackInfo
.
getCid
();
callBackInfo
.
setId
(
SnowIdUtil
.
nextId
());
callBackInfo
.
setUpdateTime
(
new
Date
());
callBackInfo
.
setStatus
(
1
);
this
.
save
(
callBackInfo
);
return
PushResultCode
.
ok
();
}
catch
(
IOException
e
)
{
log
.
error
(
"处理回调函数异常:{}"
,
e
.
getMessage
());
e
.
printStackTrace
();
}
return
PushResultCode
.
error
();
}
private
String
getMasterSecret
(
String
appId
)
{
String
masterSecret
=
null
;
Map
<
String
,
GeTuiConfig
>
apps
=
geTuiApp
.
getApps
();
for
(
Map
.
Entry
<
String
,
GeTuiConfig
>
entry
:
apps
.
entrySet
())
{
if
(
appId
.
equals
(
entry
.
getValue
().
getAppId
()))
{
masterSecret
=
entry
.
getValue
().
getMastersecret
();
break
;
}
}
Assert
.
notNull
(
masterSecret
,
"密钥不能为空"
);
return
masterSecret
;
}
public
static
String
md5Encode
(
String
str
)
{
MessageDigest
md
=
DigestUtils
.
getMd5Digest
();
return
Arrays
.
toString
(
md
.
digest
(
str
.
getBytes
(
StandardCharsets
.
UTF_8
)));
}
public
static
byte
[]
getRequestInputStream
(
HttpServletRequest
request
)
throws
IOException
{
ServletInputStream
input
=
request
.
getInputStream
();
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
];
int
position
=
0
;
while
(
true
)
{
position
=
input
.
read
(
buffer
);
if
(
position
==
-
1
)
{
break
;
}
output
.
write
(
buffer
,
0
,
position
);
}
return
output
.
toByteArray
();
}
}
src/main/java/com/weface/serviceimpl/PushLogServiceImpl.java
0 → 100644
View file @
62b49ac1
package
com
.
weface
.
serviceimpl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.weface.common.utils.SnowIdUtil
;
import
com.weface.dao.PushLogDao
;
import
com.weface.entity.PushLogEntity
;
import
com.weface.service.PushLogService
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
@Transactional
(
rollbackFor
=
{
Exception
.
class
})
@Service
(
"pushLogService"
)
public
class
PushLogServiceImpl
extends
ServiceImpl
<
PushLogDao
,
PushLogEntity
>
implements
PushLogService
{
@Override
public
void
saveLog
(
JSONObject
data
,
String
phone
,
Integer
messageTemplate
)
{
List
<
PushLogEntity
>
logList
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
Object
>
stringObjectEntry
:
data
.
entrySet
())
{
String
key
=
stringObjectEntry
.
getKey
();
Object
value
=
stringObjectEntry
.
getValue
();
if
(
value
!=
null
)
{
JSONObject
jsonObject1
=
JSONObject
.
parseObject
(
value
.
toString
());
for
(
Map
.
Entry
<
String
,
Object
>
objectEntry
:
jsonObject1
.
entrySet
())
{
String
key1
=
objectEntry
.
getKey
();
Object
value1
=
objectEntry
.
getValue
();
PushLogEntity
pushLogEntity
=
new
PushLogEntity
();
pushLogEntity
.
setId
(
SnowIdUtil
.
nextId
());
pushLogEntity
.
setTaskId
(
key
);
pushLogEntity
.
setCid
(
key1
);
pushLogEntity
.
setCidStatus
(
value1
.
toString
());
pushLogEntity
.
setPhone
(
phone
);
pushLogEntity
.
setMessageTemplate
(
messageTemplate
);
pushLogEntity
.
setIsArrive
(
0
);
pushLogEntity
.
setIsValid
(
1
);
Date
date
=
new
Date
();
pushLogEntity
.
setCreateTime
(
date
);
pushLogEntity
.
setUpdateTime
(
date
);
logList
.
add
(
pushLogEntity
);
}
}
}
if
(!
CollectionUtils
.
isEmpty
(
logList
))
{
this
.
saveBatch
(
logList
);
}
}
}
\ No newline at end of file
src/main/java/com/weface/serviceimpl/UserMenusServiceImpl.java
View file @
62b49ac1
...
...
@@ -2,12 +2,11 @@ package com.weface.serviceimpl;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.lang.Snowflake
;
import
cn.hutool.core.util.IdUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.weface.code.CommonResult
;
import
com.weface.common.utils.SnowIdUtil
;
import
com.weface.dao.UserMenusDao
;
import
com.weface.dto.UserMenuFrom
;
import
com.weface.entity.UserMenusEntity
;
...
...
@@ -24,7 +23,7 @@ import java.util.stream.Collectors;
@Slf4j
@Service
(
"userMenusService"
)
@Transactional
@Transactional
(
rollbackFor
=
{
Exception
.
class
})
public
class
UserMenusServiceImpl
extends
ServiceImpl
<
UserMenusDao
,
UserMenusEntity
>
implements
UserMenusService
{
/**
...
...
@@ -81,10 +80,9 @@ public class UserMenusServiceImpl extends ServiceImpl<UserMenusDao, UserMenusEnt
return
CommonResult
.
failed
(
"用户标签已存在"
);
}
List
<
UserMenusEntity
>
userMenusEntities
=
new
ArrayList
<>(
tagsId
.
length
);
Snowflake
snowflake
=
IdUtil
.
getSnowflake
(
1
,
1
);
for
(
String
aLong
:
saveTags
)
{
UserMenusEntity
userMenusEntity
=
new
UserMenusEntity
();
userMenusEntity
.
setId
(
snowflake
.
nextId
());
userMenusEntity
.
setId
(
SnowIdUtil
.
nextId
());
userMenusEntity
.
setUserId
(
userId
);
userMenusEntity
.
setTagsId
(
Convert
.
toLong
(
aLong
));
userMenusEntity
.
setCreateTime
(
new
Date
());
...
...
src/main/java/com/weface/task/UserTagsTask.java
View file @
62b49ac1
...
...
@@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.stereotype.Component
;
...
...
@@ -53,7 +54,7 @@ public class UserTagsTask {
/**
* 更新用户标签
*/
//
@Scheduled(cron = "0 0 23 * * ?")
@Scheduled
(
cron
=
"0 0 23 * * ?"
)
public
void
updateUserTags
()
{
try
{
//获取每次处理的id起始值
...
...
src/main/resources/mapper/PushCallBackDao.xml
0 → 100644
View file @
62b49ac1
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.weface.dao.PushCallBackDao"
>
<!-- 可根据自己的需求,是否要使用 -->
<resultMap
type=
"com.weface.entity.PushCallBackEntity"
id=
"pushCallBackMap"
>
<result
property=
"id"
column=
"id"
/>
<result
property=
"appid"
column=
"appid"
/>
<result
property=
"cid"
column=
"cid"
/>
<result
property=
"taskid"
column=
"taskid"
/>
<result
property=
"msgid"
column=
"msgid"
/>
<result
property=
"code"
column=
"code"
/>
<result
property=
"desc"
column=
"desc"
/>
<result
property=
"sign"
column=
"sign"
/>
<result
property=
"actionid"
column=
"actionId"
/>
<result
property=
"recvtime"
column=
"recvtime"
/>
<result
property=
"alias"
column=
"alias"
/>
<result
property=
"status"
column=
"status"
/>
<result
property=
"isValid"
column=
"is_valid"
/>
<result
property=
"createTime"
column=
"create_time"
/>
<result
property=
"updateTime"
column=
"update_time"
/>
</resultMap>
</mapper>
\ No newline at end of file
src/main/resources/mapper/PushLogDao.xml
0 → 100644
View file @
62b49ac1
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.weface.dao.PushLogDao"
>
<!-- 可根据自己的需求,是否要使用 -->
<resultMap
type=
"com.weface.entity.PushLogEntity"
id=
"pushLogMap"
>
<result
property=
"id"
column=
"id"
/>
<result
property=
"taskId"
column=
"task_id"
/>
<result
property=
"cid"
column=
"cid"
/>
<result
property=
"cidStatus"
column=
"cid_status"
/>
<result
property=
"phone"
column=
"phone"
/>
<result
property=
"messageTemplate"
column=
"message_template"
/>
<result
property=
"isArrive"
column=
"is_arrive"
/>
<result
property=
"isValid"
column=
"is_valid"
/>
<result
property=
"createTime"
column=
"create_time"
/>
<result
property=
"updateTime"
column=
"update_time"
/>
</resultMap>
</mapper>
\ No newline at end of file
src/test/java/com/weface/PushMessageApplicationTests.java
View file @
62b49ac1
package
com
.
weface
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.http.HttpRequest
;
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.RedisUtil
;
import
com.weface.common.utils.SnowIdUtil
;
import
com.weface.component.GeTuiService
;
import
com.weface.component.MenuService
;
import
com.weface.component.MessageTemplate
;
import
com.weface.config.GeTuiApp
;
import
com.weface.dto.InformForm
;
import
com.weface.entity.MenuTagsEntity
;
import
com.weface.entity.UserMenusEntity
;
...
...
@@ -31,11 +30,9 @@ import org.junit.jupiter.api.Test;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
javax.annotation.Resource
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.*
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutorService
;
...
...
@@ -57,9 +54,6 @@ class PushMessageApplicationTests {
@Autowired
private
GeTuiService
geTuiService
;
@Resource
private
GeTuiApp
geTuiApp
;
@Test
void
contextLoads
()
{
}
...
...
@@ -112,45 +106,11 @@ class PushMessageApplicationTests {
}
}
@Test
void
testConventTemplate
()
throws
UnsupportedEncodingException
{
InformForm
informForm
=
new
InformForm
();
// String[] alias = {"kksh_10131492"};
String
[]
alias
=
{
"kksh_59354"
};
String
token
=
geTuiService
.
getAuthToken
(
"kk_sh_token_ge_tui"
);
// String token = geTuiService.getAuthToken("kk_sb_token_ge_tui");
informForm
.
setTitle
(
"河南一名小学生确诊阳性!"
);
informForm
.
setBody
(
"1月23日新增一例本土确诊病例!为11岁小学生"
);
informForm
.
setUrl
(
"https://kk.weface.com.cn/news/page/?id=c0933d0e2fc85f7333b6202dff0e611c&type=hot&from=101"
);
MessageTemplate
messageTemplate
=
new
MessageTemplate
();
messageTemplate
.
setAudience
(
new
MessageTemplate
.
Audience
(
alias
));
messageTemplate
.
setSettings
(
new
MessageTemplate
.
Settings
(
3600000
,
0
));
MessageTemplate
.
PushMessage
pushMessage
=
new
MessageTemplate
.
PushMessage
();
MessageTemplate
.
PushMessage
.
Transmission
transmission
=
new
MessageTemplate
.
PushMessage
.
Transmission
();
transmission
.
setTitle
(
informForm
.
getTitle
());
transmission
.
setContent
(
informForm
.
getBody
());
transmission
.
setUrl
(
informForm
.
getUrl
());
pushMessage
.
setTransmission
(
transmission
);
messageTemplate
.
setPush_message
(
pushMessage
);
String
s
=
geTuiService
.
singlePushAlias
(
4
,
messageTemplate
,
geTuiService
.
getAppId
(
"kksh"
),
token
);
// String s = geTuiService.singlePushAlias(1, messageTemplate, geTuiService.getAppId("kksb"), 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
(
"request_id"
,
String
.
valueOf
(
SnowIdUtil
.
nextId
()));
map
.
put
(
"audience"
,
"all"
);
Map
<
String
,
Object
>
push_message
=
new
HashMap
<>();
...
...
@@ -166,7 +126,7 @@ class PushMessageApplicationTests {
}
@Test
void
test
Push
()
{
void
test
UserTags
()
{
//获取标签列表
List
<
MenuTagsEntity
>
tags
=
menuTagsService
.
list
();
List
<
String
>
list
=
Collections
.
singletonList
(
"d7e78cfa76e1c61699925ec9bb960d53"
);
...
...
@@ -276,22 +236,6 @@ class PushMessageApplicationTests {
System
.
out
.
println
(
first_map
);
}
@Test
void
testRandom
()
{
String
token
=
"54_qYwZpVbWrJDkflE1ha61B4SPwdhNVoCE6g_YG9zL0PL2ki6pZYsNKK__l2fMfmjRyt3C_EIiTq2Hnnla5MK8bGLckSUXUN14_A2UKMhF9xsVHQswPd6MnmVxV1YkSAyFVLEpF76kuCbBmps7GZOfAFAWPE"
;
// String token = "54_hksRqu53_0Jmw_lopjrJh4Ofzqzb_289qRkfZXxIVhBhk4vjSFH-20sbf6LUg8X1Go4tkVoISnFTSWiyKKUB1Pw8-KKNM8W6GsSpGsj85_fTtm5Uus7ncmkQCS_LxTAybYsUfsU6VaBm6hnHKJSeAAAUTC";
RedisUtil
.
StringOps
.
setEx
(
"kksh_wechat:mini_program_token:10011"
,
token
,
5400
,
TimeUnit
.
SECONDS
);
// String appId = "wx0c0e88fde84cc81c";
// String secret = "45aae2597122419a74297d5987965013";
// String code = "ce863cb4acfa518fc6893686d3e9480a0fd5b4b4ba99dd3d68d5ac4e50775943";
// String userPhone = getUserPhone("10011", code);
// System.out.println(userPhone);
}
private
static
Map
<
String
,
String
>
getAppId
(
String
programType
)
{
String
appId
;
String
secret
;
...
...
@@ -391,4 +335,36 @@ class PushMessageApplicationTests {
}
return
null
;
}
@Test
public
void
testSingleAlias
()
{
InformForm
informForm
=
new
InformForm
();
informForm
.
setTitle
(
"缴电费充值通知"
);
informForm
.
setBody
(
"尊敬的用户您好,您的户"
);
informForm
.
setUrl
(
"mineEarnGold"
);
informForm
.
setPushType
(
1
);
informForm
.
setClassName
(
"mineEarnGold"
);
informForm
.
setClassTitle
(
"我的金币"
);
informForm
.
setNeedLogin
(
"1"
);
informForm
.
setEquipmentType
(
"kksh"
);
String
[]
strings
=
{
"kksh_59354"
};
informForm
.
setCid
(
strings
);
CommonResult
commonResult
=
geTuiService
.
pushSingleAlias
(
informForm
);
System
.
out
.
println
(
commonResult
);
}
@Test
public
void
tesPushApp
()
{
InformForm
informForm
=
new
InformForm
();
informForm
.
setTitle
(
"缴电费充值通知"
);
informForm
.
setBody
(
"尊敬的用户您好,您的户"
);
informForm
.
setUrl
(
"mineEarnGold"
);
informForm
.
setPushType
(
1
);
informForm
.
setClassName
(
"mineEarnGold"
);
informForm
.
setClassTitle
(
"我的金币"
);
informForm
.
setNeedLogin
(
"1"
);
informForm
.
setEquipmentType
(
"kksh"
);
CommonResult
commonResult
=
geTuiService
.
listPush
(
informForm
);
System
.
out
.
println
(
commonResult
);
}
}
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