Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YeeAmosFireAutoSysRoot
Project
Project
Details
Activity
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
station
YeeAmosFireAutoSysRoot
Commits
3038ab8c
Commit
3038ab8c
authored
May 13, 2020
by
tangwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改推送调用
parent
939574db
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
218 additions
and
79 deletions
+218
-79
MultipartSupportConfig.java
...ejoin/amos/fas/business/feign/MultipartSupportConfig.java
+37
-0
PushFeign.java
...n/java/com/yeejoin/amos/fas/business/feign/PushFeign.java
+40
-0
PushFeignServer.java
.../com/yeejoin/amos/fas/business/feign/PushFeignServer.java
+52
-0
AppMessagePushService.java
...eejoin/amos/fas/business/jpush/AppMessagePushService.java
+89
-79
No files found.
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/feign/MultipartSupportConfig.java
0 → 100644
View file @
3038ab8c
package
com
.
yeejoin
.
amos
.
fas
.
business
.
feign
;
import
feign.codec.Encoder
;
import
feign.form.spring.SpringFormEncoder
;
import
org.springframework.beans.factory.ObjectFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.http.HttpMessageConverters
;
import
org.springframework.cloud.openfeign.support.SpringEncoder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.context.request.RequestContextListener
;
/**
* @Author: xinglei
* @Description:
* @Date: 2020/3/30 16:26
*/
@Configuration
public
class
MultipartSupportConfig
{
@Autowired
private
ObjectFactory
<
HttpMessageConverters
>
messageConverters
;
@Bean
public
Encoder
feignFormEncoder
()
{
return
new
SpringFormEncoder
(
new
SpringEncoder
(
messageConverters
));
}
/**
* 创建Feign请求拦截器,在发送请求前设置认证的token,各个微服务将token设置到环境变量中来达到通用
* @return
*/
@Bean
public
RequestContextListener
requestInterceptor
()
{
return
new
RequestContextListener
();
}
}
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/feign/PushFeign.java
0 → 100644
View file @
3038ab8c
package
com
.
yeejoin
.
amos
.
fas
.
business
.
feign
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
com.yeejoin.amos.fas.business.jpush.PushMsgParam
;
import
com.yeejoin.amos.fas.core.util.CommonResponse
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
java.util.List
;
import
org.springframework.cloud.openfeign.FeignClient
;
//推送
@FeignClient
(
name
=
"${Push.fegin.name}"
,
configuration
={
MultipartSupportConfig
.
class
})
public
interface
PushFeign
{
//
// @RequestMapping(value = "/api/user/sendMessage", method = RequestMethod.POST)
// CommonResponse sendMessage( @RequestBody List<PushMsgParam> responses);
@RequestMapping
(
value
=
"/api/user/sendMessageone"
,
method
=
RequestMethod
.
POST
)
CommonResponse
sendMessageone
(
@RequestBody
PushMsgParam
responses
);
@RequestMapping
(
value
=
"/api/user/pushNoticeMany"
,
method
=
RequestMethod
.
POST
)
CommonResponse
pushNoticeMany
(
@RequestBody
PushMsgParam
responses
);
@RequestMapping
(
value
=
"/api/user/buildPushPayload"
,
method
=
RequestMethod
.
POST
)
CommonResponse
buildPushPayload
(
@RequestBody
PushMsgParam
responses
);
@RequestMapping
(
value
=
"/api/user/pushDevice"
,
method
=
RequestMethod
.
GET
)
CommonResponse
PushDevice
(
@RequestParam
(
"alias"
)
String
alias
);
@RequestMapping
(
value
=
"/api/user/PushDeviceRegistration"
,
method
=
RequestMethod
.
GET
)
CommonResponse
PushDeviceRegistration
(
@RequestParam
(
"registrationId"
)
String
registrationId
,
@RequestParam
(
"alias"
)
String
alias
);
}
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/feign/PushFeignServer.java
0 → 100644
View file @
3038ab8c
package
com
.
yeejoin
.
amos
.
fas
.
business
.
feign
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
com.yeejoin.amos.fas.business.jpush.PushMsgParam
;
import
com.yeejoin.amos.fas.core.util.CommonResponse
;
import
com.yeejoin.amos.fas.core.util.CommonResponseUtil
;
@Service
(
"pushFeignServer"
)
public
class
PushFeignServer
{
private
final
RestTemplate
restTemplate
;
public
PushFeignServer
()
{
this
.
restTemplate
=
new
RestTemplate
();
}
@Value
(
"${Push.fegin.name}"
)
private
String
RPushFeginName
;
private
static
String
sendMessage
=
"/api/user/sendMessage"
;
public
String
geturls
(
String
url
){
return
"http://"
+
RPushFeginName
+
url
;
}
public
HttpHeaders
getHeader
(
String
toke
,
String
product
,
String
appKey
){
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
headers
.
set
(
"Content-Type"
,
"application/json"
);
headers
.
set
(
"token"
,
toke
);
headers
.
set
(
"product"
,
product
);
headers
.
set
(
"appKey"
,
appKey
);
return
headers
;
}
public
CommonResponse
sendMessage
(
String
toke
,
String
product
,
String
appKey
,
List
<
PushMsgParam
>
pushMsgParam
){
try
{
HttpEntity
httpEntity
=
new
HttpEntity
<>(
pushMsgParam
,
getHeader
(
toke
,
product
,
appKey
));
CommonResponse
commonResponse1
=
restTemplate
.
postForObject
(
geturls
(
sendMessage
),
httpEntity
,
CommonResponse
.
class
);
return
commonResponse1
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
CommonResponseUtil
.
failure
(
"发送失败"
);
}
}
}
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/jpush/AppMessagePushService.java
View file @
3038ab8c
package
com
.
yeejoin
.
amos
.
fas
.
business
.
jpush
;
package
com
.
yeejoin
.
amos
.
fas
.
business
.
jpush
;
import
cn.jpush.api.JPushClient
;
import
cn.jpush.api.JPushClient
;
import
cn.jpush.api.push.model.Platform
;
import
cn.jpush.api.push.model.Platform
;
import
cn.jpush.api.push.model.PushPayload
;
import
cn.jpush.api.push.model.PushPayload
;
import
cn.jpush.api.push.model.audience.Audience
;
import
cn.jpush.api.push.model.audience.Audience
;
import
cn.jpush.api.push.model.notification.Notification
;
import
cn.jpush.api.push.model.notification.Notification
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.yeejoin.amos.fas.core.util.CommonResponse
;
import
java.util.List
;
@Service
@Service
public
class
AppMessagePushService
{
public
class
AppMessagePushService
{
protected
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
AppMessagePushService
.
class
);
protected
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
AppMessagePushService
.
class
);
/*
@Value("${params.isPush}")
@Value
(
"${params.isPush}"
)
private String isPush;
private
String
isPush
;
private static final String APP_KEY = "1b3f7b961200f4b236811dfe";
private
static
final
String
APP_KEY
=
"1b3f7b961200f4b236811dfe"
;
private static final String MASTER_SECRET = "8b650e645fb3a43c96be02b2";
private
static
final
String
MASTER_SECRET
=
"8b650e645fb3a43c96be02b2"
;
private static JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY);
private
static
JPushClient
jpushClient
=
new
JPushClient
(
MASTER_SECRET
,
APP_KEY
);
*/
public
void
sendMessage
(
List
<
PushMsgParam
>
responses
)
{
@Autowired
try
{
private
com
.
yeejoin
.
amos
.
fas
.
business
.
feign
.
PushFeign
PushFeign
;
if
(
responses
!=
null
&&
"true"
.
equals
(
isPush
))
{
for
(
PushMsgParam
response
:
responses
)
{
PushPayload
payload
=
buildPushPayload
(
response
);
jpushClient
.
sendPush
(
payload
);
}
}
// public void sendMessage(List<PushMsgParam> responses) {
}
catch
(
Exception
e
)
{
// try {
log
.
error
(
"极光推送异常"
,
e
);
// if (responses != null && "true".equals(isPush)) {
}
// for (PushMsgParam response : responses) {
}
// PushPayload payload = buildPushPayload(response);
// jpushClient.sendPush(payload);
private
PushPayload
buildPushPayload
(
PushMsgParam
response
)
{
// }
if
(
JPushTypeEnum
.
ALL
.
getCode
().
equals
(
response
.
getType
()))
{
// }
return
PushPayload
.
newBuilder
()
// } catch (Exception e) {
.
setPlatform
(
Platform
.
android
())
// log.error("极光推送异常", e);
.
setAudience
(
Audience
.
all
())
// }
.
setNotification
(
Notification
.
android
(
response
.
getContent
(),
response
.
getSubject
(),
response
.
getExtras
()))
// }
.
build
();
}
else
if
(
JPushTypeEnum
.
TAG
.
getCode
().
equals
(
response
.
getType
()))
{
private
PushPayload
buildPushPayload
(
PushMsgParam
response
)
{
return
PushPayload
.
newBuilder
()
CommonResponse
commonResponse
=
PushFeign
.
buildPushPayload
(
response
);
.
setPlatform
(
Platform
.
android
())
return
(
PushPayload
)
commonResponse
.
getDataList
();
.
setAudience
(
Audience
.
tag
(
response
.
getRecivers
()))
// if (JPushTypeEnum.ALL.getCode().equals(response.getType())) {
.
setNotification
(
Notification
.
android
(
response
.
getContent
(),
response
.
getSubject
(),
response
.
getExtras
()))
// return PushPayload.newBuilder()
.
build
();
// .setPlatform(Platform.android())
}
else
{
// .setAudience(Audience.all())
return
PushPayload
.
newBuilder
()
// .setNotification(Notification.android(response.getContent(), response.getSubject(), response.getExtras()))
.
setPlatform
(
Platform
.
android
())
// .build();
.
setAudience
(
Audience
.
alias
(
response
.
getRecivers
()))
// } else if (JPushTypeEnum.TAG.getCode().equals(response.getType())) {
.
setNotification
(
Notification
.
android
(
response
.
getContent
(),
response
.
getSubject
(),
response
.
getExtras
()))
// return PushPayload.newBuilder()
.
build
();
// .setPlatform(Platform.android())
}
// .setAudience(Audience.tag(response.getRecivers()))
}
// .setNotification(Notification.android(response.getContent(), response.getSubject(), response.getExtras()))
// .build();
public
void
sendMessage
(
PushMsgParam
response
)
{
// } else {
try
{
// return PushPayload.newBuilder()
if
(
null
!=
response
&&
"true"
.
equals
(
isPush
))
{
// .setPlatform(Platform.android())
PushPayload
payload
=
PushPayload
.
newBuilder
().
setPlatform
(
Platform
.
android
())
// .setAudience(Audience.alias(response.getRecivers()))
.
setAudience
(
Audience
.
all
())
// .setNotification(Notification.android(response.getContent(), response.getSubject(), response.getExtras()))
.
setNotification
(
Notification
.
android
(
response
.
getContent
(),
response
.
getSubject
(),
response
.
getExtras
()))
// .build();
.
build
();
// }
jpushClient
.
sendPush
(
payload
);
}
}
}
catch
(
Exception
e
)
{
public
void
sendMessage
(
PushMsgParam
response
)
{
log
.
error
(
"极光推送异常"
,
e
);
CommonResponse
commonResponse
=
PushFeign
.
sendMessageone
(
response
);
}
// try {
}
// if (null != response && "true".equals(isPush)) {
// PushPayload payload = PushPayload.newBuilder().setPlatform(Platform.android())
}
// .setAudience(Audience.all())
// .setNotification(Notification.android(response.getContent(), response.getSubject(), response.getExtras()))
// .build();
// jpushClient.sendPush(payload);
// }
// } catch (Exception e) {
// log.error("极光推送异常", e);
// }
}
}
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