package external import ( "context" "os" "github.com/rs/zerolog/log" ) type UnreadMessageRequest struct { Type string `json:"type"` // 向谁发的消息:shop(门店), customer(客户) ShopId int32 `json:"shopId"` UserId int32 `json:"userId"` MsgCount int `json:"msgCount"` } // 请求函数 -- 根据请求项目选择请求方式 func RequestToPHP(receiver string, shopId int32, userId int32, count int) error { var project string if receiver == "shop" { project = "huaZhangGui" } else if receiver == "customer" { project = "huaHuiBao" } ctx := context.Background() switch project { case "huaZhangGui": //url := os.Getenv("HUA_ZHANG_GUI_URL") url := os.Getenv("HUA_HUI_BAO_URL") reqData := UnreadMessageRequest{ Type: "shop", ShopId: shopId, UserId: userId, MsgCount: count, } huaZhangGuiClient := NewHuaZhangGuiClient(url) res, err := huaZhangGuiClient.PostUnReadMessage(ctx, reqData) if err != nil { log.Error().Str("receiverType", receiver).Int32("receiverID", shopId).Int("count", count).Err(err).Msg("向 PHP 服务发送未读消息通知失败") return err } 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") // 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 }