Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
e822867b
Commit
e822867b
authored
Sep 18, 2021
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成apns推送证书数据库动态配置
parent
b4e1cb20
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
147 additions
and
86 deletions
+147
-86
bootstrap/src/test/java/io/geekidea/springbootplus/test/IosApnsBase64Test.java
+1
-1
bootstrap/src/test/java/io/geekidea/springbootplus/test/SaveApnsTest.java
+49
-0
common/src/main/java/com/wecloud/im/entity/ImIosApns.java
+1
-1
common/src/main/java/com/wecloud/im/param/ImIosApnsQueryVo.java
+1
-1
common/src/main/java/com/wecloud/im/service/ImIosApnsService.java
+3
-0
common/src/main/java/com/wecloud/im/service/impl/ImIosApnsServiceImpl.java
+12
-0
common/src/main/java/com/wecloud/im/ws/sender/IosPush.java
+1
-3
common/src/main/java/com/wecloud/im/ws/sender/PushTask.java
+79
-80
No files found.
bootstrap/src/test/java/io/geekidea/springbootplus/test/IosApnsBase64Test.java
View file @
e822867b
...
@@ -45,7 +45,7 @@ public class IosApnsBase64Test {
...
@@ -45,7 +45,7 @@ public class IosApnsBase64Test {
InputStream
inputStream2
=
new
ByteArrayInputStream
(
decode
);
InputStream
inputStream2
=
new
ByteArrayInputStream
(
decode
);
IosPush
.
push
(
inputStream2
,
Boolean
.
FALSE
,
deviceToken
,
alertTitle
,
alertBody
,
IosPush
.
push
(
"123456"
,
inputStream2
,
Boolean
.
FALSE
,
deviceToken
,
alertTitle
,
alertBody
,
contentAvailable
,
customProperty
,
badge
contentAvailable
,
customProperty
,
badge
,
DeliveryPriority
.
IMMEDIATE
,
PushType
.
ALERT
,
topicBundleId
,
,
DeliveryPriority
.
IMMEDIATE
,
PushType
.
ALERT
,
topicBundleId
,
"default"
);
"default"
);
...
...
bootstrap/src/test/java/io/geekidea/springbootplus/test/SaveApnsTest.java
0 → 100644
View file @
e822867b
package
io
.
geekidea
.
springbootplus
.
test
;
import
cn.hutool.core.codec.Base64
;
import
com.wecloud.im.entity.ImIosApns
;
import
com.wecloud.im.service.ImIosApnsService
;
import
com.wecloud.im.ws.sender.IosPush
;
import
io.geekidea.springbootplus.framework.shiro.util.SnowflakeUtil
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.io.InputStream
;
/**
* 生成apns字符串 并存入数据库
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
SaveApnsTest
{
@Autowired
private
ImIosApnsService
imIosApnsService
;
@Test
public
void
test
()
throws
Exception
{
String
apnsCertificatePath
=
"frogsell_push.p12"
;
String
topicBundleId
=
"com.jdw.frogsell"
;
String
pwd
=
"123456"
;
InputStream
certificate
=
IosPush
.
getApnsCertificate
(
apnsCertificatePath
);
String
encode
=
Base64
.
encode
(
certificate
);
ImIosApns
imIosApns
=
new
ImIosApns
();
imIosApns
.
setId
(
SnowflakeUtil
.
getId
());
imIosApns
.
setFkAppId
(
0L
);
imIosApns
.
setApnsFileValue
(
encode
);
imIosApns
.
setEnv
(
1
);
imIosApns
.
setBundleId
(
topicBundleId
);
imIosApns
.
setPwd
(
pwd
);
imIosApnsService
.
save
(
imIosApns
);
}
}
common/src/main/java/com/wecloud/im/entity/ImIosApns.java
View file @
e822867b
...
@@ -33,7 +33,7 @@ public class ImIosApns extends BaseEntity {
...
@@ -33,7 +33,7 @@ public class ImIosApns extends BaseEntity {
@ApiModelProperty
(
"应用appid"
)
@ApiModelProperty
(
"应用appid"
)
private
Long
fkAppId
;
private
Long
fkAppId
;
@ApiModelProperty
(
"Base6
2
(apns.p12)"
)
@ApiModelProperty
(
"Base6
4
(apns.p12)"
)
private
String
apnsFileValue
;
private
String
apnsFileValue
;
@ApiModelProperty
(
"环境,正式1,测试0"
)
@ApiModelProperty
(
"环境,正式1,测试0"
)
...
...
common/src/main/java/com/wecloud/im/param/ImIosApnsQueryVo.java
View file @
e822867b
...
@@ -27,7 +27,7 @@ public class ImIosApnsQueryVo implements Serializable {
...
@@ -27,7 +27,7 @@ public class ImIosApnsQueryVo implements Serializable {
@ApiModelProperty
(
"应用appid"
)
@ApiModelProperty
(
"应用appid"
)
private
Long
fkAppId
;
private
Long
fkAppId
;
@ApiModelProperty
(
"Base6
2
(apns.p12)"
)
@ApiModelProperty
(
"Base6
4
(apns.p12)"
)
private
String
apnsFileValue
;
private
String
apnsFileValue
;
@ApiModelProperty
(
"环境,正式1,测试0"
)
@ApiModelProperty
(
"环境,正式1,测试0"
)
...
...
common/src/main/java/com/wecloud/im/service/ImIosApnsService.java
View file @
e822867b
...
@@ -48,6 +48,9 @@ public interface ImIosApnsService extends BaseService<ImIosApns> {
...
@@ -48,6 +48,9 @@ public interface ImIosApnsService extends BaseService<ImIosApns> {
*/
*/
ImIosApnsQueryVo
getImIosApnsById
(
Long
id
)
throws
Exception
;
ImIosApnsQueryVo
getImIosApnsById
(
Long
id
)
throws
Exception
;
ImIosApns
getImIosApnsByAppId
(
Long
appId
);
/**
/**
* 获取分页对象
* 获取分页对象
*
*
...
...
common/src/main/java/com/wecloud/im/service/impl/ImIosApnsServiceImpl.java
View file @
e822867b
package
com
.
wecloud
.
im
.
service
.
impl
;
package
com
.
wecloud
.
im
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.wecloud.im.entity.ImIosApns
;
import
com.wecloud.im.entity.ImIosApns
;
import
com.wecloud.im.mapper.ImIosApnsMapper
;
import
com.wecloud.im.mapper.ImIosApnsMapper
;
import
com.wecloud.im.param.ImIosApnsQueryVo
;
import
com.wecloud.im.param.ImIosApnsQueryVo
;
...
@@ -7,6 +8,8 @@ import com.wecloud.im.service.ImIosApnsService;
...
@@ -7,6 +8,8 @@ import com.wecloud.im.service.ImIosApnsService;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -18,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
...
@@ -18,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
*/
*/
@Slf4j
@Slf4j
@Service
@Service
@CacheConfig
(
cacheNames
=
"apns"
)
public
class
ImIosApnsServiceImpl
extends
BaseServiceImpl
<
ImIosApnsMapper
,
ImIosApns
>
implements
ImIosApnsService
{
public
class
ImIosApnsServiceImpl
extends
BaseServiceImpl
<
ImIosApnsMapper
,
ImIosApns
>
implements
ImIosApnsService
{
@Autowired
@Autowired
...
@@ -46,6 +50,14 @@ public class ImIosApnsServiceImpl extends BaseServiceImpl<ImIosApnsMapper, ImIos
...
@@ -46,6 +50,14 @@ public class ImIosApnsServiceImpl extends BaseServiceImpl<ImIosApnsMapper, ImIos
return
imIosApnsMapper
.
getImIosApnsById
(
id
);
return
imIosApnsMapper
.
getImIosApnsById
(
id
);
}
}
@Override
@Cacheable
(
key
=
"#p0"
)
public
ImIosApns
getImIosApnsByAppId
(
Long
appId
)
{
return
this
.
getOne
(
new
QueryWrapper
<
ImIosApns
>().
lambda
().
eq
(
ImIosApns:
:
getFkAppId
,
appId
));
}
// @Override
// @Override
// public Paging<ImIosApnsQueryVo> getImIosApnsPageList(ImIosApnsPageParam imIosApnsPageParam) throws Exception {
// public Paging<ImIosApnsQueryVo> getImIosApnsPageList(ImIosApnsPageParam imIosApnsPageParam) throws Exception {
// Page<ImIosApnsQueryVo> page;
// Page<ImIosApnsQueryVo> page;
...
...
common/src/main/java/com/wecloud/im/ws/sender/IosPush.java
View file @
e822867b
...
@@ -79,13 +79,11 @@ public class IosPush {
...
@@ -79,13 +79,11 @@ public class IosPush {
* @param topicBundleId undleId
* @param topicBundleId undleId
* @param sound rtc= "call.caf"; 否则为default
* @param sound rtc= "call.caf"; 否则为default
*/
*/
public
static
void
push
(
InputStream
inputStream
,
Boolean
productFlag
,
final
String
deviceToken
,
String
alertTitle
,
String
alertBody
,
public
static
void
push
(
String
certificatePassword
,
InputStream
inputStream
,
Boolean
productFlag
,
final
String
deviceToken
,
String
alertTitle
,
String
alertBody
,
boolean
contentAvailable
,
Map
<
String
,
Object
>
customProperty
,
boolean
contentAvailable
,
Map
<
String
,
Object
>
customProperty
,
int
badge
,
DeliveryPriority
priority
,
PushType
pushType
,
String
topicBundleId
,
int
badge
,
DeliveryPriority
priority
,
PushType
pushType
,
String
topicBundleId
,
String
sound
)
{
String
sound
)
{
String
certificatePassword
=
"123456"
;
if
(
deviceToken
==
null
||
""
.
equals
(
deviceToken
))
{
if
(
deviceToken
==
null
||
""
.
equals
(
deviceToken
))
{
logger
.
error
(
"deviceToken=null"
);
logger
.
error
(
"deviceToken=null"
);
return
;
return
;
...
...
common/src/main/java/com/wecloud/im/ws/sender/PushTask.java
View file @
e822867b
package
com
.
wecloud
.
im
.
ws
.
sender
;
package
com
.
wecloud
.
im
.
ws
.
sender
;
import
cn.hutool.core.codec.Base64
;
import
com.turo.pushy.apns.DeliveryPriority
;
import
com.turo.pushy.apns.PushType
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.entity.ImIosApns
;
import
com.wecloud.im.push.PushUtils
;
import
com.wecloud.im.push.PushUtils
;
import
com.wecloud.im.service.ImIosApnsService
;
import
com.wecloud.im.ws.model.request.PushModel
;
import
com.wecloud.im.ws.model.request.PushModel
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.io.OutputStreamWriter
;
import
java.io.OutputStreamWriter
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
/**
* 异步系统推送
* 异步系统推送
...
@@ -24,6 +32,9 @@ import java.util.HashMap;
...
@@ -24,6 +32,9 @@ import java.util.HashMap;
@Slf4j
@Slf4j
public
class
PushTask
{
public
class
PushTask
{
@Autowired
private
ImIosApnsService
imIosApnsService
;
/**
/**
* 谷歌推送地址
* 谷歌推送地址
*/
*/
...
@@ -97,46 +108,9 @@ public class PushTask {
...
@@ -97,46 +108,9 @@ public class PushTask {
}
else
if
(
imApplication
.
getAndroidPushChannel
()
==
2
)
{
}
else
if
(
imApplication
.
getAndroidPushChannel
()
==
2
)
{
//firebase:2
//firebase:2
log
.
info
(
"firebase"
);
log
.
info
(
"
android_
firebase"
);
String
jsonStr
=
null
;
firebase
(
pushModel
,
imClientReceiver
,
imApplication
);
try
{
URL
url
=
new
URL
(
API_URL_FCM
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setUseCaches
(
false
);
conn
.
setDoInput
(
true
);
conn
.
setDoOutput
(
true
);
conn
.
setConnectTimeout
(
10000
);
conn
.
setRequestMethod
(
"POST"
);
//不设置默认发送文本格式。设置就是json
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
conn
.
setRequestProperty
(
"Authorization"
,
"key="
+
imApplication
.
getFirebaseSecret
());
JSONObject
json
=
new
JSONObject
();
//推送到哪台客户端机器
json
.
put
(
"to"
,
imClientReceiver
.
getDeviceToken
());
JSONObject
info
=
new
JSONObject
();
info
.
put
(
"title"
,
pushModel
.
getTitle
());
info
.
put
(
"body"
,
pushModel
.
getSubTitle
());
//数据消息data 通知消息 notification
json
.
put
(
"notification"
,
info
);
OutputStreamWriter
wr
=
new
OutputStreamWriter
(
conn
.
getOutputStream
());
jsonStr
=
json
.
toString
();
wr
.
write
(
jsonStr
);
wr
.
flush
();
InputStream
inputStream
=
conn
.
getInputStream
();
InputStreamReader
in
=
new
InputStreamReader
(
inputStream
);
BufferedReader
reader
=
new
BufferedReader
(
in
);
String
line
=
reader
.
readLine
();
log
.
info
(
line
);
wr
.
close
();
reader
.
close
();
}
catch
(
Exception
e
)
{
log
.
error
(
"FCM push failure: "
+
jsonStr
,
e
);
}
}
else
if
(
imApplication
.
getAndroidPushChannel
()
==
3
)
{
}
else
if
(
imApplication
.
getAndroidPushChannel
()
==
3
)
{
// 信鸽3
// 信鸽3
...
@@ -145,7 +119,6 @@ public class PushTask {
...
@@ -145,7 +119,6 @@ public class PushTask {
}
else
{
}
else
{
log
.
info
(
"没有找到推送类型"
);
log
.
info
(
"没有找到推送类型"
);
return
;
}
}
}
}
...
@@ -173,54 +146,80 @@ public class PushTask {
...
@@ -173,54 +146,80 @@ public class PushTask {
log
.
info
(
"firebase"
);
log
.
info
(
"firebase"
);
String
jsonStr
=
null
;
firebase
(
pushModel
,
imClientReceiver
,
imApplication
);
try
{
URL
url
=
new
URL
(
API_URL_FCM
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setUseCaches
(
false
);
conn
.
setDoInput
(
true
);
conn
.
setDoOutput
(
true
);
conn
.
setConnectTimeout
(
10000
);
conn
.
setRequestMethod
(
"POST"
);
//不设置默认发送文本格式。设置就是json
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
conn
.
setRequestProperty
(
"Authorization"
,
"key="
+
imApplication
.
getFirebaseSecret
());
JSONObject
json
=
new
JSONObject
();
//推送到哪台客户端机器
json
.
put
(
"to"
,
imClientReceiver
.
getDeviceToken
());
JSONObject
info
=
new
JSONObject
();
info
.
put
(
"title"
,
pushModel
.
getTitle
());
info
.
put
(
"body"
,
pushModel
.
getSubTitle
());
//数据消息data 通知消息 notification
json
.
put
(
"notification"
,
info
);
OutputStreamWriter
wr
=
new
OutputStreamWriter
(
conn
.
getOutputStream
());
jsonStr
=
json
.
toString
();
wr
.
write
(
jsonStr
);
wr
.
flush
();
InputStream
inputStream
=
conn
.
getInputStream
();
InputStreamReader
in
=
new
InputStreamReader
(
inputStream
);
BufferedReader
reader
=
new
BufferedReader
(
in
);
String
line
=
reader
.
readLine
();
log
.
info
(
line
);
wr
.
close
();
reader
.
close
();
}
catch
(
Exception
e
)
{
log
.
error
(
"FCM push failure: "
+
jsonStr
,
e
);
}
}
else
if
(
imApplication
.
getIosPushChannel
()
==
3
)
{
}
else
if
(
imApplication
.
getIosPushChannel
()
==
3
)
{
// apns原生:3
// apns原生:3
log
.
info
(
"apns原生"
);
log
.
info
(
"apns原生"
);
apnsPush
(
pushModel
,
imClientReceiver
,
imApplication
);
}
else
{
}
else
{
log
.
info
(
"没有找到推送类型"
);
log
.
info
(
"没有找到推送类型"
);
return
;
}
}
}
}
public
void
firebase
(
PushModel
pushModel
,
ImClient
imClientReceiver
,
ImApplication
imApplication
)
{
String
jsonStr
=
null
;
try
{
URL
url
=
new
URL
(
API_URL_FCM
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setUseCaches
(
false
);
conn
.
setDoInput
(
true
);
conn
.
setDoOutput
(
true
);
conn
.
setConnectTimeout
(
10000
);
conn
.
setRequestMethod
(
"POST"
);
//不设置默认发送文本格式。设置就是json
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
conn
.
setRequestProperty
(
"Authorization"
,
"key="
+
imApplication
.
getFirebaseSecret
());
JSONObject
json
=
new
JSONObject
();
//推送到哪台客户端机器
json
.
put
(
"to"
,
imClientReceiver
.
getDeviceToken
());
JSONObject
info
=
new
JSONObject
();
info
.
put
(
"title"
,
pushModel
.
getTitle
());
info
.
put
(
"body"
,
pushModel
.
getSubTitle
());
//数据消息data 通知消息 notification
json
.
put
(
"notification"
,
info
);
OutputStreamWriter
wr
=
new
OutputStreamWriter
(
conn
.
getOutputStream
());
jsonStr
=
json
.
toString
();
wr
.
write
(
jsonStr
);
wr
.
flush
();
InputStream
inputStream
=
conn
.
getInputStream
();
InputStreamReader
in
=
new
InputStreamReader
(
inputStream
);
BufferedReader
reader
=
new
BufferedReader
(
in
);
String
line
=
reader
.
readLine
();
log
.
info
(
line
);
wr
.
close
();
reader
.
close
();
}
catch
(
Exception
e
)
{
log
.
error
(
"FCM push failure: "
+
jsonStr
,
e
);
}
}
private
void
apnsPush
(
PushModel
pushModel
,
ImClient
imClientReceiver
,
ImApplication
imApplication
)
{
// 查询apns证书
ImIosApns
apns
=
imIosApnsService
.
getImIosApnsByAppId
(
imApplication
.
getId
());
Map
<
String
,
Object
>
customProperty
=
new
HashMap
<
String
,
Object
>(
1
);
String
deviceToken
=
imClientReceiver
.
getDeviceToken
();
String
alertTitle
=
pushModel
.
getTitle
();
String
alertBody
=
pushModel
.
getSubTitle
();
int
badge
=
1
;
String
topicBundleId
=
apns
.
getBundleId
();
String
certificatePassword
=
apns
.
getPwd
();
boolean
contentAvailable
=
false
;
String
sound
=
"default"
;
// 解码
byte
[]
decode
=
Base64
.
decode
(
apns
.
getApnsFileValue
());
InputStream
inputStream2
=
new
ByteArrayInputStream
(
decode
);
IosPush
.
push
(
certificatePassword
,
inputStream2
,
Boolean
.
FALSE
,
deviceToken
,
alertTitle
,
alertBody
,
contentAvailable
,
customProperty
,
badge
,
DeliveryPriority
.
IMMEDIATE
,
PushType
.
ALERT
,
topicBundleId
,
sound
);
}
}
}
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