Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
push-platform-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ec4e69c7
authored
Apr 12, 2021
by
fz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.优化代码
1 parent
39585aea
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
9 deletions
src/main/java/com/glsx/modules/notify/service/CarHomePushService.java
src/main/java/com/glsx/modules/notify/service/PushService.java
src/test/java/com/glsx/modules/notify/controller/DeviceControllerTest.java
src/main/java/com/glsx/modules/notify/service/CarHomePushService.java
View file @
ec4e69c
package
com
.
glsx
.
modules
.
notify
.
service
;
import
com.glsx.modules.notify.factory.PushFactory
;
import
com.glsx.modules.notify.factory.PushStrategy
;
import
com.glsx.modules.notify.model.BaseRequest
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
@Service
@Slf4j
public
class
CarHomePushService
extends
PushService
{
@Autowired
PushFactory
pushFactory
;
/**
* DEV表示开发环境,PRODUCT表示生产环境
*/
...
...
@@ -57,6 +62,11 @@ public class CarHomePushService extends PushService{
private
String
type_ios_aliyun
;
@Override
protected
PushStrategy
getStrategy
(
Integer
code
)
throws
Exception
{
return
pushFactory
.
getStrategy
(
code
);
}
@Override
protected
void
setiOSAliyunValue
(
BaseRequest
pushRequest
)
{
//appkey
pushRequest
.
setAppKey
(
appKey_ios_aliyun
);
...
...
@@ -79,6 +89,7 @@ public class CarHomePushService extends PushService{
pushRequest
.
setAppMasterSecret
(
appMasterSecret_android_youmeng
);
//环境
pushRequest
.
setTestMode
(
testMode
);
log
.
info
(
"setAliasType====="
+
aliasType_android_youmeng
);
//AliasType
pushRequest
.
setAliasType
(
aliasType_android_youmeng
);
//通知跳转
...
...
src/main/java/com/glsx/modules/notify/service/PushService.java
View file @
ec4e69c
package
com
.
glsx
.
modules
.
notify
.
service
;
import
com.glsx.modules.notify.factory.PushFactory
;
import
com.glsx.modules.notify.factory.PushStrategy
;
import
com.glsx.modules.notify.factory.PushType
;
import
com.glsx.modules.notify.model.BaseRequest
;
import
com.glsx.plat.core.web.R
;
import
org.springframework.beans.factory.annotation.Autowired
;
public
abstract
class
PushService
{
@Autowired
private
PushFactory
pushFactory
;
public
abstract
class
PushService
{
public
R
pushNotify
(
BaseRequest
pushRequest
)
{
//如果是阿里云
if
(
pushRequest
.
getPlatformType
()
==
PushType
.
ALIYUN
.
getCode
())
{
...
...
@@ -32,7 +28,7 @@ public abstract class PushService {
//获取对应策略,1:任意触发条件满足 2:全部触发条件满足
PushStrategy
pushStrategy
=
null
;
try
{
pushStrategy
=
pushFactory
.
getStrategy
(
pushRequest
.
getPlatformType
());
pushStrategy
=
getStrategy
(
pushRequest
.
getPlatformType
());
}
catch
(
Exception
e
)
{
R
.
error
(
"创建策略失败:"
+
e
.
getMessage
());
}
...
...
@@ -40,6 +36,8 @@ public abstract class PushService {
return
pushStrategy
.
pushNotify
(
pushRequest
);
}
protected
abstract
PushStrategy
getStrategy
(
Integer
code
)
throws
Exception
;
protected
abstract
void
setiOSAliyunValue
(
BaseRequest
pushRequest
);
protected
abstract
void
setiOSYouMengValue
(
BaseRequest
pushRequest
);
...
...
src/test/java/com/glsx/modules/notify/controller/DeviceControllerTest.java
View file @
ec4e69c
...
...
@@ -30,16 +30,23 @@ public class DeviceControllerTest {
try
{
NotifyReqParam
pushRequest
=
new
NotifyReqParam
();
//推送平台参数
pushRequest
.
setPlatformType
(
PushType
.
YOUMENG
.
getCode
());
//
pushRequest.setPlatformType(PushType.YOUMENG.getCode());
pushRequest
.
setDeviceType
(
"ANDROID"
);
//推送别名参数
pushRequest
.
setAlias
(
"
Auv2Nn2JkqhFypmb1gm8u3gVCv1Y5T7xcsWo1YueLrck
"
);
pushRequest
.
setAlias
(
"
91712432
"
);
//通知参数
pushRequest
.
setTitle
(
"消息推送测试标题"
);
pushRequest
.
setBody
(
"内容test"
);
BaseRequest
baseRequest
=
new
BaseRequest
();
BeanUtils
.
copyProperties
(
pushRequest
,
baseRequest
);
if
(
baseRequest
.
getDeviceType
().
equals
(
"ANDROID"
)){
baseRequest
.
setPlatformType
(
PushType
.
YOUMENG
.
getCode
());
}
if
(
baseRequest
.
getDeviceType
().
equals
(
"iOS"
)){
baseRequest
.
setPlatformType
(
PushType
.
ALIYUN
.
getCode
());
}
R
r
=
pushService
.
pushNotify
(
baseRequest
);
log
.
info
(
"fzpush===android==="
+
r
);
}
catch
(
Exception
ex
)
{
...
...
@@ -52,7 +59,7 @@ public class DeviceControllerTest {
try
{
NotifyReqParam
pushRequest
=
new
NotifyReqParam
();
//推送平台参数
pushRequest
.
setPlatformType
(
PushType
.
ALIYUN
.
getCode
());
//
pushRequest.setPlatformType(PushType.ALIYUN.getCode());
pushRequest
.
setDeviceType
(
"iOS"
);
//推送别名参数
pushRequest
.
setAlias
(
"com.glsx.aicar.push"
);
...
...
@@ -63,6 +70,13 @@ public class DeviceControllerTest {
BaseRequest
baseRequest
=
new
BaseRequest
();
BeanUtils
.
copyProperties
(
pushRequest
,
baseRequest
);
if
(
baseRequest
.
getDeviceType
().
equals
(
"ANDROID"
)){
baseRequest
.
setPlatformType
(
PushType
.
YOUMENG
.
getCode
());
}
if
(
baseRequest
.
getDeviceType
().
equals
(
"iOS"
)){
baseRequest
.
setPlatformType
(
PushType
.
ALIYUN
.
getCode
());
}
R
r
=
pushService
.
pushNotify
(
baseRequest
);
log
.
info
(
"fzpush===ios==="
+
r
);
}
catch
(
Exception
ex
)
{
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment