123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package server
- import (
- "context"
- "log"
- "testing"
- firebase "firebase.google.com/go"
- "firebase.google.com/go/messaging"
- "google.golang.org/api/option"
- )
- func TestFirebaseMessageServer_Send(t *testing.T) {
- ctx := context.Background()
- conf := &firebase.Config{ServiceAccountID: androidFirebaseServiceAccountID}
- app, err := firebase.NewApp(ctx, conf,
- option.WithCredentialsJSON([]byte(androidFirebaseCredentials)))
- if err != nil {
- log.Fatalln(err)
- }
- //token := "fDfRE2raSkSfroIw47qSEV:APA91bF4LORpS8ZWo-i8i1DQ8SZ8C-BEdFWBdGQGDW-PwzQUivoNf75_NpTrFNLFlAqdHd4mdauaI9aZWhFs4Pou2iySmuI6Ct0sHs5Bc9LrnGMK9f5YEBA"
- token := "cl7mDFUw5URmvG9Jio2p7L:APA91bH4GIRM1IJNDn7_tYw7q4ADVdzQKpnaPNqxXw6PZE-H9H82sGkF74-KSz7moydB6ykgHucrXNjsSopmyFCi3M4S-SVWZA_fGJa6Q0WO6V_CY_gtDhi2WHGobM84Pm0aZ0AHb2XB"
- clt, err := app.Messaging(ctx)
- if err != nil {
- panic(err)
- }
- jsonStr := "hello word"
- title := "测试消息"
- body := "测试消息内容,无需关注"
- //title:= "Call Notification"
- //body:= "click to view"
- //videoCallMessage := &NatsPubVideoCallMessage{
- // AccountId: "954d38fc-f4a4-445f-88e3-7be83a51a3c8",
- // Dial: 1,
- // Receiver: "c2686cac-8ec8-4b26-8e87-50b7d63a7d36",
- // Sender: "954d38fc-f4a4-445f-88e3-7be83a51a3c8",
- //}
- //
- //message := NatsPubMessage[NatsPubVideoCallMessage]{
- // RequestId: "41a83fe2-6281-4f72-bb80-067fb5e19b1c",
- // Type: MessageTypeVideoCall,
- // Content: videoCallMessage,
- //}
- //jsonBytes, err := json.Marshal(message)
- //if err != nil {
- // fmt.Println("Error marshaling JSON:", err)
- // return
- //}
- //jsonStr := string(jsonBytes)
- msg := &messaging.Message{
- Token: token,
- Data: map[string]string{
- "message": jsonStr,
- },
- Android: &messaging.AndroidConfig{
- Notification: &messaging.AndroidNotification{
- Sound: "default",
- Priority: messaging.PriorityHigh,
- },
- },
- APNS: &messaging.APNSConfig{
- Payload: &messaging.APNSPayload{
- Aps: &messaging.Aps{
- Sound: "default",
- },
- },
- },
- Notification: &messaging.Notification{
- Title: title,
- Body: body,
- },
- }
- r, err := clt.Send(ctx, msg)
- if err != nil {
- log.Fatalln(err)
- } else {
- log.Println(r)
- }
- }
|