feat:get fcm config from url

pull/2341/head
icey-yu 1 year ago
parent ebb9d3dbfb
commit 7bf29e8e5a

@ -24,6 +24,7 @@ geTui:
channelName: ''
fcm:
serviceAccount: "x.json"
verifyUrl: ""
jpns:
appKey: ''
masterSecret: ''

@ -17,6 +17,7 @@ package fcm
import (
"context"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
"github.com/openimsdk/tools/utils/httputil"
"path/filepath"
firebase "firebase.google.com/go"
@ -45,8 +46,24 @@ func NewClient(pushConf *config.Push, cache cache.ThirdCache, fcmConfigPath stri
//if err != nil {
// return nil, err
//}
credentialsFilePath := filepath.Join(fcmConfigPath, "config", pushConf.FCM.ServiceAccount)
opt := option.WithCredentialsFile(credentialsFilePath)
var opt option.ClientOption
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)
if err != nil {
return nil, errs.Wrap(err)

@ -203,6 +203,7 @@ type Push struct {
} `mapstructure:"geTui"`
FCM struct {
ServiceAccount string `mapstructure:"serviceAccount"`
VerifyUrl string `mapstructure:"verifyUrl"`
} `mapstructure:"fcm"`
JPNS struct {
AppKey string `mapstructure:"appKey"`

Loading…
Cancel
Save