mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
feat:get fcm config from url
This commit is contained in:
parent
ebb9d3dbfb
commit
7bf29e8e5a
@ -24,6 +24,7 @@ geTui:
|
|||||||
channelName: ''
|
channelName: ''
|
||||||
fcm:
|
fcm:
|
||||||
serviceAccount: "x.json"
|
serviceAccount: "x.json"
|
||||||
|
verifyUrl: ""
|
||||||
jpns:
|
jpns:
|
||||||
appKey: ''
|
appKey: ''
|
||||||
masterSecret: ''
|
masterSecret: ''
|
||||||
|
|||||||
@ -17,6 +17,7 @@ package fcm
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
|
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
|
||||||
|
"github.com/openimsdk/tools/utils/httputil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
firebase "firebase.google.com/go"
|
firebase "firebase.google.com/go"
|
||||||
@ -45,8 +46,24 @@ func NewClient(pushConf *config.Push, cache cache.ThirdCache, fcmConfigPath stri
|
|||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
//}
|
//}
|
||||||
credentialsFilePath := filepath.Join(fcmConfigPath, "config", pushConf.FCM.ServiceAccount)
|
var opt option.ClientOption
|
||||||
opt := option.WithCredentialsFile(credentialsFilePath)
|
switch {
|
||||||
|
case len(pushConf.FCM.ServiceAccount) != 0:
|
||||||
|
// with file path
|
||||||
|
credentialsFilePath := filepath.Join(fcmConfigPath, pushConf.FCM.ServiceAccount)
|
||||||
|
opt = option.WithCredentialsFile(credentialsFilePath)
|
||||||
|
case len(pushConf.FCM.VerifyUrl) != 0:
|
||||||
|
// with verify url
|
||||||
|
client := httputil.NewHTTPClient(httputil.NewClientConfig())
|
||||||
|
resp, err := client.Get(pushConf.FCM.VerifyUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errs.Wrap(err)
|
||||||
|
}
|
||||||
|
opt = option.WithCredentialsJSON(resp)
|
||||||
|
default:
|
||||||
|
return nil, errs.New("no FCM config")
|
||||||
|
}
|
||||||
|
|
||||||
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
|
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errs.Wrap(err)
|
return nil, errs.Wrap(err)
|
||||||
|
|||||||
@ -203,6 +203,7 @@ type Push struct {
|
|||||||
} `mapstructure:"geTui"`
|
} `mapstructure:"geTui"`
|
||||||
FCM struct {
|
FCM struct {
|
||||||
ServiceAccount string `mapstructure:"serviceAccount"`
|
ServiceAccount string `mapstructure:"serviceAccount"`
|
||||||
|
VerifyUrl string `mapstructure:"verifyUrl"`
|
||||||
} `mapstructure:"fcm"`
|
} `mapstructure:"fcm"`
|
||||||
JPNS struct {
|
JPNS struct {
|
||||||
AppKey string `mapstructure:"appKey"`
|
AppKey string `mapstructure:"appKey"`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user