Просмотр исходного кода

调整:1.只向HUA_HUI_BAO_URL发消息(禁HUA_ZHANG_GUI_URL) 2.调整请求参数

shizhongqi 11 месяцев назад
Родитель
Сommit
610a282ae1
3 измененных файлов с 33 добавлено и 29 удалено
  1. 25 21
      external/request.go
  2. 6 6
      wsClient/redis.go
  3. 2 2
      wsClient/room.go

+ 25 - 21
external/request.go

@@ -10,50 +10,54 @@ import (
 
 type UnreadMessageRequest struct {
     Type string `json:"type"`
-    Id int32 `json:"id"`
+    ShopId int32 `json:"id"`
+	UserId int32 `json:"userId"`
     MsgCount int `json:"msgCount"`
 }
 
 // 请求函数 -- 根据请求项目选择请求方式
-func RequestToPHP(receiverType string, receiverID int32, count int) error {
+func RequestToPHP(receiver string, shopId int32, userId int32, count int) error {
 	var project string
-	if receiverType == "shop" {
+	if receiver == "shop" {
 		project = "huaZhangGui"
-	} else if receiverType == "customer" {
+	} else if receiver == "customer" {
 		project = "huaHuiBao"
 	}
 
 	ctx := context.Background()
 	switch project {
 	case "huaZhangGui":
-		url := os.Getenv("HUA_ZHANG_GUI_URL")
+		//url := os.Getenv("HUA_ZHANG_GUI_URL")
+		url := os.Getenv("HUA_HUI_BAO_URL")
 		reqData := UnreadMessageRequest{
 			Type: "shop",
-			Id: receiverID,
+			ShopId: shopId,
+			UserId: userId,
 			MsgCount: count,
 		}
 		huaZhangGuiClient := NewHuaZhangGuiClient(url)
 		res, err := huaZhangGuiClient.PostUnReadMessage(ctx, reqData)
 		if err != nil {
-			log.Error().Str("receiverType", receiverType).Int32("receiverID", receiverID).Int("count", count).Err(err).Msg("向 PHP 服务发送未读消息通知失败")
+			log.Error().Str("receiverType", receiver).Int32("receiverID", shopId).Int("count", count).Err(err).Msg("向 PHP 服务发送未读消息通知失败")
 			return err
 		}
-		log.Info().Str("receiverType", receiverType).Int32("receiverID", receiverID).Int("count", count).Str("res", res).Msg("向 PHP 服务发送未读消息通知成功")
+		log.Info().Str("receiverType", receiver).Int32("receiverID", shopId).Int("count", count).Str("res", res).Msg("向 PHP 服务发送未读消息通知成功")
 		
 	case "huaHuiBao":
-		url := os.Getenv("HUA_HUI_BAO_URL")
-		reqData := UnreadMessageRequest{
-			Type: "customer",
-			Id: receiverID,
-			MsgCount: count,
-		}
-		huaHuiBaoClient := NewHuaHuiBaoClient(url)
-		res, err := huaHuiBaoClient.PostUnReadMessage(ctx, reqData)
-		if err != nil {
-			log.Error().Str("receiverType", receiverType).Int32("receiverID", receiverID).Int("count", count).Err(err).Msg("向 PHP 服务发送未读消息通知失败")
-			return err
-		}
-		log.Info().Str("receiverType", receiverType).Int32("receiverID", receiverID).Int("count", count).Str("res", res).Msg("向 PHP 服务发送未读消息通知成功")
+		////url := os.Getenv("HUA_HUI_BAO_URL")
+		// url := os.Getenv("HUA_ZHANG_GUI_URL")
+		// reqData := UnreadMessageRequest{
+		// 	Type: "customer",
+		// 	Id: receiverID,
+		// 	MsgCount: count,
+		// }
+		// huaHuiBaoClient := NewHuaHuiBaoClient(url)
+		// res, err := huaHuiBaoClient.PostUnReadMessage(ctx, reqData)
+		// if err != nil {
+		// 	log.Error().Str("receiverType", receiverType).Int32("receiverID", receiverID).Int("count", count).Err(err).Msg("向 PHP 服务发送未读消息通知失败")
+		// 	return err
+		// }
+		// log.Info().Str("receiverType", receiverType).Int32("receiverID", receiverID).Int("count", count).Str("res", res).Msg("向 PHP 服务发送未读消息通知成功")
 	}
 
 	return nil

+ 6 - 6
wsClient/redis.go

@@ -377,13 +377,13 @@ func parseScore(score float64) (timestamp int64, unreadCount int) {
 // @param sender 发送者
 // @param count 未读消息数
 // @return 接收者类型, 接收者ID, 未读消息数
-func GeneHaveSendInfo(sender *Client, count int) (string, int32, int) {
-	if sender.userInfo.Type == UserTypeShop {
-		return UserTypeCustomer, sender.userInfo.UserId, count
-	} else if sender.userInfo.Type == UserTypeCustomer {
-		return UserTypeShop, sender.userInfo.ShopId, count
+func GeneHaveSendInfo(sender *Client, count int) (string, int32, int32, int) {
+	if sender.userInfo.Type == UserTypeShop { // 门店发送消息给 客户
+		return UserTypeCustomer, sender.userInfo.ShopId, sender.userInfo.UserId, count
+	} else if sender.userInfo.Type == UserTypeCustomer { // 客户发送消息给 门店
+		return UserTypeShop, sender.userInfo.ShopId, sender.userInfo.UserId, count
 	}
-	return "", 0, 0
+	return "", 0, 0, 0
 }
 
 /**

+ 2 - 2
wsClient/room.go

@@ -159,9 +159,9 @@ func (r *Room) run() {
 			// 本消息转发,目的是让客户与门店互相发消息,当有另一方不在线时,要累计未读消息数
 			if !online {
 				go IncrementUnreadCount(msg.sender, 1)
-				receiverType, receiverID, count := GeneHaveSendInfo(msg.sender, 1)
+				receiver, shopId, userId, count := GeneHaveSendInfo(msg.sender, 1)
 				// 向 PHP 服务发送未读消息通知
-				go external.RequestToPHP(receiverType, receiverID, count)
+				go external.RequestToPHP(receiver, shopId, userId, count)
 			}
 		}
 	}