Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] opemim deploy integrated fcm push using docker does not work #227

Closed
youfak opened this issue Feb 27, 2025 · 1 comment
Closed

[BUG] opemim deploy integrated fcm push using docker does not work #227

youfak opened this issue Feb 27, 2025 · 1 comment

Comments

@youfak
Copy link

youfak commented Feb 27, 2025

OpenIM Server Version

3.8.3

Operating System and CPU Architecture

Linux (AMD)

Deployment Method

Docker Deployment

Bug Description and Steps to Reproduce

根据#136 文档规则

##修改配置
修改opemim-push.yaml配置同时把webhooks.yaml中的url清空在docker-compose.yaml文件openim-server节点增加如下配置

IMENV_OPENIM_PUSH_ENABLE=fcm
IMENV_OPENIM_PUSH_FCM_AUTHURL=${FCM_AUTHURL}
IMENV_WEBHOOKS_URL=${WEBHOOKS_URL}

下面是完整配置

 openim-server:
    image: ${OPENIM_SERVER_IMAGE}
    container_name: openim-server
    init: true
    ports:
      - "${OPENIM_MSG_GATEWAY_PORT}:10001"
      - "${OPENIM_API_PORT}:10002"
    healthcheck:
      test: [ "CMD", "sh", "-c", "mage check" ]
      interval: 5s
      timeout: 60s
      retries: 10
    environment:
      - IMENV_MONGODB_ADDRESS=${MONGO_ADDRESS}
      - IMENV_MONGODB_USERNAME=${MONGO_USERNAME}
      - IMENV_MONGODB_PASSWORD=${MONGO_PASSWORD}
      - IMENV_KAFKA_ADDRESS=${KAFKA_ADDRESS}
      - IMENV_DISCOVERY_ETCD_ADDRESS=${ETCD_ADDRESS}
      - IMENV_REDIS_ADDRESS=${REDIS_ADDRESS}
      - IMENV_REDIS_PASSWORD=${REDIS_PASSWORD}
      - IMENV_MINIO_INTERNALADDRESS=${MINIO_INTERNAL_ADDRESS}
      - IMENV_MINIO_EXTERNALADDRESS=${MINIO_EXTERNAL_ADDRESS}
      - IMENV_MINIO_ACCESSKEYID=${MINIO_ACCESS_KEY_ID}
      - IMENV_MINIO_SECRETACCESSKEY=${MINIO_SECRET_ACCESS_KEY}
      - IMENV_SHARE_SECRET=${OPENIM_SECRET}
      - IMENV_LOG_ISSTDOUT=${LOG_IS_STDOUT}
      - IMENV_LOG_REMAINLOGLEVEL=${LOG_LEVEL}
      - IMENV_OPENIM_API_PROMETHEUS_GRAFANAURL=${GRAFANA_URL}
      - IMENV_OPENIM_PUSH_ENABLE=fcm
      - IMENV_OPENIM_PUSH_FCM_AUTHURL=${FCM_AUTHURL}
      - IMENV_WEBHOOKS_URL=${WEBHOOKS_URL}
    restart: always
    networks:
      - openim

##.env文件增加配置

FCM_AUTHURL="https://test.rubicone.club/files/club-rubicone-firebase-adminsdk-fbsvc.json" #地址是可以正常访问  这里做了处理
WEBHOOKS_URL=""

##停止服务

docker compose down

##启动服务

docker compose up -d

进去openim-server容器

docker exec -it openim-server /bin/sh

查看webhooks.yaml和openim-push.yaml文件配置都没有被修改成功

Image

Image
杀掉app后进行发送消息查看openim-server的日志也没有看到推送的日志产生

更新2025年2月27日17:41:09
现在有推送日志但报错

[push/push_handler.go:198]                              offlinePushMsg failed                                   {"platform": "Android", "connID": "af7fe9d15ecf70640badb22011815f3c", "operationID": "bf5a4513-74dc-41c2-904c-49d74f53579c", "opUserID": "f5444053e6b84fa7be0855c06f83dd9c", "needOfflinePushUserID": ["e9b1e674ffa14c6e90fa207f52edf5fa"], "msg": "sendID:\"f5444053e6b84fa7be0855c06f83dd9c\"  recvID:\"e9b1e674ffa14c6e90fa207f52edf5fa\"  clientMsgID:\"6c3958b77ab344a8ea67897a6a2dd11d\"  serverMsgID:\"5228a2ce362fb8f199f63d1be8fef1b6\"  senderPlatformID:2  senderNickname:\"child\"  senderFaceURL:\"/files/V_User/default.png\"  sessionType:1  msgFrom:100  contentType:101  content:\"{\\\"content\\\":\\\"wqi\\\"}\"  seq:409  sendTime:1740648979381  createTime:1740648979467  status:2  offlinePushInfo:{title:\"新消息\"  desc:\"您收到一条新消息\"  iOSPushSound:\"default\"}  attachedInfo:\"null\"", "error": "Error: 1 message send failed;send err:;message err: | -> errs.(*errorString).Wrap() /go/pkg/mod/github.com/openimsdk/[email protected]/errs/error.go:40 -> fcm.(*Fcm).Push() /openim-server/internal/push/offlinepush/fcm/push.go:166 -> push.(*ConsumerHandler).offlinePushMsg() /openim-server/internal/push/push_handler.go:362 -> push.(*ConsumerHandler).Push2User() /openim-server/internal/push/push_handler.go:196 -> push.(*ConsumerHandler).handleMs2PsChat() /openim-server/internal/push/push_handler.go:122 -> push.(*ConsumerHandler).ConsumeClaim() /openim-server/internal/push/push_handler.go:145 -> sarama.(*consumerGroupSession).consume() /go/pkg/mod/github.com/!i!b!m/[email protected]/consumer_group.go:952 -> sarama.newConsumerGroupSession.func2() /go/pkg/mod/github.com/!i!b!m/[email protected]/consumer_group.go:878"}

我使用以下测试代码发送正常

package main

import (
	"context"
	firebase "firebase.google.com/go/v4"
	"firebase.google.com/go/v4/messaging"
	"google.golang.org/api/option"
	"io/ioutil"
	"log"
	"net/http"
)

func main() {
	url := "json地址"
	resp, err := http.Get(url)
	if err != nil {
		log.Fatalf("failed to download credentials: %v\n", err)
	}
	defer resp.Body.Close()

	// 读取JSON数据
	credentialData, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatalf("failed to read credentials: %v\n", err)
	}

	opt := option.WithCredentialsJSON(credentialData)
	fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
	if err != nil {
		log.Fatalf("error initializing app: %v\n", err)
		return
	}

	ctx := context.Background()
	fcmMsgClient, err := fcmApp.Messaging(ctx)
	if err != nil {
		log.Fatalf("error initializing messaging client: %v\n", err)
		return
	}

	// 设置FCM消息,同时包含notification和data字段
	message := &messaging.Message{
		Token: "ewAJgFLFQAiIzoKeDASX3W:APA91bHvaTlOv9mpV8KVPLW4Dnk8s7IXyh_6u9QAmMKg4w4FsJ0DPmzPdPy8647uAff33lYyG4rrjlMRYjMSyKgWXLr21ZF_q14hiJjhiQda8WUoRVhZfZg", // 确认这个token是否有效
		Notification: &messaging.Notification{
			Title: "测试标题",
			Body:  "测试内容",
		},
		Data: map[string]string{
			"title": "测试",
			"body":  "测试",
		},
		Android: &messaging.AndroidConfig{
			Priority: "high",
		},
	}

	// 验证Token是否为空
	if message.Token == "" {
		log.Fatalf("FCM消息发送失败: Token不能为空\n")
		return
	}

	// 发送消息并检查结果
	response, err := fcmMsgClient.Send(ctx, message)
	if err != nil {

		log.Fatalf("发送FCM消息失败: %v\n", err)
		return
	}

	// 打印成功响应
	log.Printf("成功发送消息,消息ID: %s\n", response)
}

Screenshots Link

No response

@OpenIM-Robot
Copy link

Hello! Thank you for filing an issue.

If this is a bug report, please include relevant logs to help us debug the problem.

Join slack 🤖 to connect and communicate with our developers.

@youfak youfak closed this as completed Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants