Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
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
youjj
cloud-platform
Commits
a4b9c0f5
Commit
a4b9c0f5
authored
Sep 10, 2019
by
hezhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
123
parent
e193425d
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
807 additions
and
4 deletions
+807
-4
pom.xml
xx-universal/xx-universal-api/pom.xml
+1
-1
MessagePush.java
.../java/com/xxfc/platform/universal/entity/MessagePush.java
+85
-0
PushExample.java
...n/java/com/xxfc/platform/universal/utils/PushExample.java
+476
-0
JPushBiz.java
...c/main/java/com/xxfc/platform/universal/biz/JPushBiz.java
+192
-3
JPushController.java
...m/xxfc/platform/universal/controller/JPushController.java
+38
-0
MessagePushMapper.java
...com/xxfc/platform/universal/mapper/MessagePushMapper.java
+15
-0
No files found.
xx-universal/xx-universal-api/pom.xml
View file @
a4b9c0f5
...
...
@@ -76,7 +76,7 @@
<dependency>
<groupId>
cn.jpush.api
</groupId>
<artifactId>
jpush-client
</artifactId>
<version>
3.3.
7
</version>
<version>
3.3.
9
</version>
</dependency>
<dependency>
<groupId>
cn.jpush.api
</groupId>
...
...
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/entity/MessagePush.java
0 → 100644
View file @
a4b9c0f5
package
com
.
xxfc
.
platform
.
universal
.
entity
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.io.Serializable
;
/**
* 消息推送表
*
* @author zjw
* @email nishijjo@qq.com
* @date 2019-05-28 16:17:42
*/
@Data
@Table
(
name
=
"message_push"
)
public
class
MessagePush
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
//
@Id
@GeneratedValue
(
generator
=
"JDBC"
)
@ApiModelProperty
(
""
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"1-手动推送;2-系统自动推送"
)
private
Integer
type
;
@Column
(
name
=
"send_type"
)
@ApiModelProperty
(
value
=
"系统发送类型:1-支付完成"
)
private
Integer
sendType
;
@ApiModelProperty
(
value
=
"通知标题"
)
private
String
title
;
@ApiModelProperty
(
value
=
"通知内容"
)
private
String
alert
;
@ApiModelProperty
(
value
=
"通知栏样式类型:1-大文本;2-文本条目;3-大图片"
)
private
Integer
style
;
@Column
(
name
=
"big_text"
)
@ApiModelProperty
(
value
=
"大文本通知栏样式"
)
private
String
bigText
;
@ApiModelProperty
(
value
=
"文本条目通知栏样式"
)
private
String
inbox
;
@Column
(
name
=
"big_pic_path"
)
@ApiModelProperty
(
value
=
"大图片通知栏样式"
)
private
String
bigPicPath
;
@ApiModelProperty
(
value
=
"指定跳转页面"
)
private
String
intent
;
@Column
(
name
=
"crt_time"
)
@ApiModelProperty
(
value
=
"创建时间"
,
hidden
=
true
)
private
Long
crtTime
;
@Column
(
name
=
"upd_time"
)
@ApiModelProperty
(
value
=
"更新时间"
,
hidden
=
true
)
private
Long
updTime
;
@Column
(
name
=
"is_del"
)
@ApiModelProperty
(
value
=
"是否删除"
)
private
Integer
isDel
;
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/utils/PushExample.java
0 → 100644
View file @
a4b9c0f5
This diff is collapsed.
Click to expand it.
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/biz/JPushBiz.java
View file @
a4b9c0f5
...
...
@@ -2,22 +2,35 @@ package com.xxfc.platform.universal.biz;
import
cn.jiguang.common.ClientConfig
;
import
cn.jiguang.common.ServiceHelper
;
import
cn.jiguang.common.resp.APIConnectionException
;
import
cn.jiguang.common.resp.APIRequestException
;
import
cn.jpush.api.JPushClient
;
import
cn.jpush.api.push.PushResult
;
import
cn.jpush.api.push.model.Options
;
import
cn.jpush.api.push.model.Platform
;
import
cn.jpush.api.push.model.PushPayload
;
import
cn.jpush.api.push.model.audience.Audience
;
import
cn.jpush.api.push.model.notification.AndroidNotification
;
import
cn.jpush.api.push.model.notification.Notification
;
import
com.github.wxiaoqi.security.common.biz.BaseBiz
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
com.xxfc.platform.universal.service.SmsService
;
import
com.xxfc.platform.universal.utils.CCPRestSmsUtils
;
import
com.github.wxiaoqi.security.common.vo.PageDataVO
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonPrimitive
;
import
com.xxfc.platform.universal.entity.MessagePush
;
import
com.xxfc.platform.universal.mapper.MessagePushMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
tk.mybatis.mapper.entity.Example
;
@Service
@Slf4j
public
class
JPushBiz
{
public
class
JPushBiz
extends
BaseBiz
<
MessagePushMapper
,
MessagePush
>
{
@Value
(
"${universal.MASTER_SECRET}"
)
...
...
@@ -25,6 +38,8 @@ public class JPushBiz {
@Value
(
"${universal.APP_KEY}"
)
private
String
APP_KEY
;
public
static
final
String
ALERT
=
"Test from API Example - alert"
;
//推送给所有平台设备
public
ObjectRestResponse
jpushToAllPlat
(
String
title
){
ClientConfig
clientConfig
=
ClientConfig
.
getInstance
();
...
...
@@ -48,5 +63,179 @@ public class JPushBiz {
}
}
//推送给所有平台设备
public
ObjectRestResponse
jpushToAllPlat1
(){
ClientConfig
clientConfig
=
ClientConfig
.
getInstance
();
final
JPushClient
jpushClient
=
new
JPushClient
(
MASTER_SECRET
,
APP_KEY
,
null
,
clientConfig
);
PushPayload
payload
=
buildPushObject_android_newly_support
();
try
{
PushResult
result
=
jpushClient
.
sendPush
(
payload
);
log
.
debug
(
"\n推送结果:"
+
result
);
return
ObjectRestResponse
.
succ
();
}
catch
(
APIConnectionException
e
)
{
// Connection error, should retry later
log
.
debug
(
"\nConnection error, should retry later"
+
e
);
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
e
.
getMessage
());
}
catch
(
APIRequestException
e
)
{
// Should review the error, and fix the request
log
.
debug
(
"\nShould review the error, and fix the request"
+
e
);
log
.
debug
(
"\nHTTP Status: "
+
e
.
getStatus
());
log
.
debug
(
"\nError Code: "
+
e
.
getErrorCode
());
log
.
debug
(
"\nError Message: "
+
e
.
getErrorMessage
());
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
e
.
getMessage
());
}
}
public
static
PushPayload
buildPushObject_android_newly_support
()
{
JsonObject
inbox
=
new
JsonObject
();
inbox
.
add
(
"line1"
,
new
JsonPrimitive
(
"line1 string"
));
inbox
.
add
(
"line2"
,
new
JsonPrimitive
(
"line2 string"
));
inbox
.
add
(
"contentTitle"
,
new
JsonPrimitive
(
"title string"
));
inbox
.
add
(
"summaryText"
,
new
JsonPrimitive
(
"+3 more"
));
JsonObject
intent
=
new
JsonObject
();
intent
.
add
(
"url"
,
new
JsonPrimitive
(
"intent:#Intent;component=com.jiguang.push/com.example.jpushdemo.SettingActivity;end"
));
Notification
notification
=
Notification
.
newBuilder
()
.
addPlatformNotification
(
AndroidNotification
.
newBuilder
()
.
setAlert
(
"测试通知内容"
)
.
setBigPicPath
(
"https://xxtest.upyuns.com/image/app/oyI48qqcy3m38iCFffFc3UeZLcm1s3.png"
)
.
setBigText
(
"long text"
)
.
setBuilderId
(
1
)
.
setCategory
(
"CATEGORY_SOCIAL"
)
.
setInbox
(
inbox
)
.
setStyle
(
3
)
.
setTitle
(
"测试通知标题"
)
.
setPriority
(
1
)
.
setLargeIcon
(
"https://xxtest.upyuns.com/image/admin/stock.jpg"
)
.
setIntent
(
intent
)
.
build
())
.
build
();
return
PushPayload
.
newBuilder
()
.
setPlatform
(
Platform
.
all
())
.
setAudience
(
Audience
.
all
())
.
setNotification
(
notification
)
.
setOptions
(
Options
.
newBuilder
()
.
setApnsProduction
(
true
)
.
setSendno
(
ServiceHelper
.
generateSendno
())
.
build
())
.
build
();
}
//推送
public
ObjectRestResponse
jpushToAlias
(
Integer
id
,
String
userIds
){
ClientConfig
clientConfig
=
ClientConfig
.
getInstance
();
final
JPushClient
jpushClient
=
new
JPushClient
(
MASTER_SECRET
,
APP_KEY
,
null
,
clientConfig
);
PushPayload
payload
=
buildPushObject_android_id
(
id
,
userIds
);
if
(
payload
==
null
){
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"参数无效"
);
}
try
{
PushResult
result
=
jpushClient
.
sendPush
(
payload
);
log
.
debug
(
"\n推送结果:"
+
result
);
return
ObjectRestResponse
.
succ
();
}
catch
(
APIConnectionException
e
)
{
// Connection error, should retry later
log
.
debug
(
"\nConnection error, should retry later"
+
e
);
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
e
.
getMessage
());
}
catch
(
APIRequestException
e
)
{
// Should review the error, and fix the request
log
.
debug
(
"\nShould review the error, and fix the request"
+
e
);
log
.
debug
(
"\nHTTP Status: "
+
e
.
getStatus
());
log
.
debug
(
"\nError Code: "
+
e
.
getErrorCode
());
log
.
debug
(
"\nError Message: "
+
e
.
getErrorMessage
());
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
e
.
getMessage
());
}
}
public
PushPayload
buildPushObject_android_id
(
Integer
id
,
String
userIds
)
{
Example
example
=
new
Example
(
MessagePush
.
class
);
example
.
createCriteria
().
andEqualTo
(
"id"
,
id
).
andEqualTo
(
"isDel"
,
0
);
MessagePush
messagePush
=
mapper
.
selectOneByExample
(
example
);
if
(
messagePush
==
null
||
messagePush
.
getType
()==
null
){
log
.
info
(
"无有效数据--id=="
+
id
);
return
null
;
}
Audience
audience
=
Audience
.
all
();
if
(
messagePush
.
getType
()==
2
){
if
(
StringUtils
.
isBlank
(
userIds
)){
log
.
info
(
"无有效数据--type=="
+
messagePush
.
getType
()+
"------userId=="
+
userIds
);
return
null
;
}
audience
=
Audience
.
alias
(
userIds
);
}
JsonObject
intent
=
new
JsonObject
();
if
(
StringUtils
.
isNotBlank
(
messagePush
.
getIntent
())){
intent
=
getJsonObject
(
messagePush
.
getIntent
());
}
Notification
notification
=
Notification
.
newBuilder
()
.
addPlatformNotification
(
AndroidNotification
.
newBuilder
()
.
setAlert
(
messagePush
.
getAlert
())
.
setBigPicPath
(
messagePush
.
getBigPicPath
())
.
setBigText
(
messagePush
.
getBigText
())
.
setBuilderId
(
1
)
.
setCategory
(
"CATEGORY_SOCIAL"
)
.
setInbox
(
messagePush
.
getInbox
())
.
setStyle
(
messagePush
.
getStyle
())
.
setTitle
(
messagePush
.
getTitle
())
.
setPriority
(
1
)
.
setIntent
(
intent
)
.
build
())
.
build
();
return
PushPayload
.
newBuilder
()
.
setPlatform
(
Platform
.
all
())
.
setAudience
(
audience
)
.
setNotification
(
notification
)
.
setOptions
(
Options
.
newBuilder
()
.
setApnsProduction
(
true
)
.
setSendno
(
ServiceHelper
.
generateSendno
())
.
build
())
.
build
();
}
//字符串转JsonObject
public
JsonObject
getJsonObject
(
String
json
){
Gson
g
=
new
Gson
();
return
g
.
fromJson
(
json
,
JsonObject
.
class
);
}
//编辑推送内容
public
ObjectRestResponse
updMessagePush
(
MessagePush
messagePush
){
Integer
id
=
messagePush
.
getId
();
if
(
id
==
null
){
insertSelective
(
messagePush
);
}
else
{
updateSelectiveById
(
messagePush
);
}
return
ObjectRestResponse
.
succ
();
}
//删除推送内容
public
ObjectRestResponse
delMessagePush
(
MessagePush
messagePush
){
messagePush
.
setIsDel
(
1
);
updateSelectiveById
(
messagePush
);
return
ObjectRestResponse
.
succ
();
}
//获取列表
public
ObjectRestResponse
getList
(
Integer
page
,
Integer
limit
,
String
title
,
Integer
type
){
Example
example
=
new
Example
(
MessagePush
.
class
);
Example
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andEqualTo
(
"isDel"
,
0
);
if
(
StringUtils
.
isNotBlank
(
title
)){
criteria
.
andLike
(
"title"
,
"%"
+
title
+
"%"
);
}
if
(
type
!=
null
&&
type
!=
0
){
criteria
.
andEqualTo
(
"type"
,
type
);
}
return
ObjectRestResponse
.
succ
(
PageDataVO
.
pageInfo
(
page
,
limit
,
()->
mapper
.
selectByExample
(
example
)));
}
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/controller/JPushController.java
View file @
a4b9c0f5
...
...
@@ -5,6 +5,7 @@ package com.xxfc.platform.universal.controller;
import
com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.xxfc.platform.universal.biz.JPushBiz
;
import
com.xxfc.platform.universal.entity.MessagePush
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -27,5 +28,42 @@ public class JPushController {
return
jPushBiz
.
jpushToAllPlat
(
title
);
}
@RequestMapping
(
value
=
"/app/unauth/alls"
,
method
=
RequestMethod
.
GET
)
//匹配的是href中的download请求
public
ObjectRestResponse
alls
()
throws
Exception
{
return
jPushBiz
.
jpushToAllPlat1
();
}
@RequestMapping
(
value
=
"/stype"
,
method
=
RequestMethod
.
GET
)
public
ObjectRestResponse
stype
(
@RequestParam
(
value
=
"id"
,
defaultValue
=
"0"
)
Integer
id
,
@RequestParam
(
value
=
"userIds"
,
defaultValue
=
""
)
String
userIds
)
throws
Exception
{
return
jPushBiz
.
jpushToAlias
(
id
,
userIds
);
}
@RequestMapping
(
value
=
"/addMessagePush"
,
method
=
RequestMethod
.
POST
)
public
ObjectRestResponse
addMessagePush
(
@RequestBody
MessagePush
messagePush
){
return
jPushBiz
.
updMessagePush
(
messagePush
);
}
@RequestMapping
(
value
=
"/udpMessagePush"
,
method
=
RequestMethod
.
POST
)
public
ObjectRestResponse
udpMessagePush
(
@RequestBody
MessagePush
messagePush
){
return
jPushBiz
.
updMessagePush
(
messagePush
);
}
@RequestMapping
(
value
=
"/del"
,
method
=
RequestMethod
.
POST
)
public
ObjectRestResponse
delMessagePush
(
@RequestBody
MessagePush
messagePush
){
return
jPushBiz
.
delMessagePush
(
messagePush
);
}
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
public
ObjectRestResponse
getList
(
@RequestParam
(
value
=
"page"
,
defaultValue
=
"1"
)
Integer
page
,
@RequestParam
(
value
=
"limit"
,
defaultValue
=
"10"
)
Integer
limit
,
@RequestParam
(
value
=
"title"
,
defaultValue
=
""
)
String
title
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"0"
)
Integer
type
){
return
jPushBiz
.
getList
(
page
,
limit
,
title
,
type
);
}
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/mapper/MessagePushMapper.java
0 → 100644
View file @
a4b9c0f5
package
com
.
xxfc
.
platform
.
universal
.
mapper
;
import
com.xxfc.platform.universal.entity.MessagePush
;
import
tk.mybatis.mapper.common.Mapper
;
/**
* 消息推送表
*
* @author zjw
* @email nishijjo@qq.com
* @date 2019-05-28 16:17:42
*/
public
interface
MessagePushMapper
extends
Mapper
<
MessagePush
>
{
}
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