Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
8e29972d
提交
8e29972d
authored
9月 21, 2020
作者:
Whispa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commit
上级
b0e45e52
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
85 行增加
和
1 行删除
+85
-1
AuthController.java
...a/com/example/afrishop_v3/controllers/AuthController.java
+5
-1
Controller.java
.../java/com/example/afrishop_v3/controllers/Controller.java
+71
-0
TbCfUserInfo.java
...ain/java/com/example/afrishop_v3/models/TbCfUserInfo.java
+9
-0
没有找到文件。
src/main/java/com/example/afrishop_v3/controllers/AuthController.java
浏览文件 @
8e29972d
...
...
@@ -46,7 +46,7 @@ import java.util.stream.Collectors;
@CrossOrigin
(
origins
=
"*"
,
maxAge
=
3600
)
@RestController
@RequestMapping
(
"/api/auth"
)
public
class
AuthController
{
public
class
AuthController
extends
Controller
{
private
final
AuthenticationManager
authenticationManager
;
private
final
UserRepository
userRepository
;
...
...
@@ -94,6 +94,10 @@ public class AuthController {
userInfo
.
setToken
(
jwt
);
if
(
userInfo
.
hasFcm
()
){
sendNotification
(
userInfo
.
getFcm
(),
"Welcome back"
,
userInfo
.
display
()
+
", Welcome back and enjoy shopping "
);
}
return
new
Result
<>(
userInfo
);
}
...
...
src/main/java/com/example/afrishop_v3/controllers/Controller.java
浏览文件 @
8e29972d
package
com
.
example
.
afrishop_v3
.
controllers
;
import
com.example.afrishop_v3.util.HttpClientUtil
;
import
com.example.afrishop_v3.util.IdUtil
;
import
org.json.JSONObject
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.HashMap
;
class
Controller
{
String
uid
(){
return
IdUtil
.
createIdbyUUID
();
}
static
int
id
=
0
;
final
String
serverToken
=
"AAAAg-FJSfc:APA91bHr7OgmwmcP401YFBJZK_hkeeSO2qbMHXZaJa7Zup9U8dZ8XQqlFnF_z5q5fa9wskRu4PNiK8IMn0lYBjxJgi8srcafC1Mc-p2GU6T8v5kAQKvjwZoDJ_R0PVCvfroX09muIwln"
;
final
String
firebaseUrl
=
"https://fcm.googleapis.com/fcm/send"
;
boolean
sendNotification
(
String
token
,
String
title
,
String
message
){
// Dio().post(
// 'https://fcm.googleapis.com/fcm/send',
// options: Options(headers: <String, String>{
// 'Content-Type': 'application/json',
// 'Authorization': 'key=$serverToken',
// }),
// data: <String, dynamic>{
// 'notification': <String, dynamic>{
// 'body': 'this is a body from app',
// 'title': 'this is a title from app'
// },
// 'priority': 'high',
// 'data': <String, dynamic>{
// 'click_action': 'FLUTTER_NOTIFICATION_CLICK',
// 'id': '1',
// 'status': 'done'
// },
// 'to': token,
// },
// ).then((f){print(f.data.toString());});
JSONObject
request
=
new
JSONObject
();
HashMap
<
String
,
Object
>
notification
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
data
=
new
HashMap
<>();
notification
.
put
(
"body"
,
message
);
notification
.
put
(
"title"
,
title
);
data
.
put
(
"click_action"
,
"FLUTTER_NOTIFICATION_CLICK"
);
data
.
put
(
"id"
,
id
++);
data
.
put
(
"status"
,
"done"
);
request
.
put
(
"notification"
,
notification
);
request
.
put
(
"data"
,
data
);
request
.
put
(
"priority"
,
"high"
);
request
.
put
(
"to"
,
token
);
String
postRequest
=
sendPOSTRequest
(
request
);
return
postRequest
!=
null
;
}
private
String
sendPOSTRequest
(
JSONObject
data
)
{
RestTemplate
restTemplate
=
new
RestTemplate
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
headers
.
setBasicAuth
(
"key="
+
serverToken
);
HttpEntity
entity
=
new
HttpEntity
<>(
data
,
headers
);
String
answer
=
restTemplate
.
postForObject
(
firebaseUrl
,
entity
,
String
.
class
);
System
.
out
.
println
(
answer
);
return
answer
;
}
}
src/main/java/com/example/afrishop_v3/models/TbCfUserInfo.java
浏览文件 @
8e29972d
...
...
@@ -226,6 +226,15 @@ public class TbCfUserInfo {
this
.
slogan
=
slogan
;
}
public
boolean
hasFcm
(){
return
fcm
!=
null
;
}
public
String
getFcm
(){
return
fcm
;
}
public
String
getSlogan
(){
return
slogan
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论