websocket im在线客服 golang 全双工通讯

该博客介绍了如何使用Golang构建一个WebSocket实现实时的在线客服系统,包括实现一对一私聊功能以及上下线通知机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

多客服系统 实现一对一私聊 上下线通知

package controllers

import (
	"github.com/astaxie/beego/orm"
	"github.com/gorilla/websocket"
	"imservice/models"
	"log"
	"net/http"
)

/*
	客服
*/
type Service struct {
   
	WebsiteName string `json:"website_name,omitempty"` //网站名称
	WebsiteId   int    `json:"website_id,omitempty"`   //网站id
	ServiceId   int    `json:"service_id,omitempty"`   //客服id
	WebsiteLogo string `json:"website_logo,omitempty"` //网站logo
	NiceName    string `json:"nice_name,omitempty"`    //昵称
	Mobile      string `json:"mobile,omitempty"`       //手机号
	FixedMobile string `json:"fixed_mobile,omitempty"` //固定电话
	Token       string `json:"token,omitempty"`        //token
	Ws          *websocket.Conn
}

/*
	游客
*/
type Cust struct {
   
	NiceName string `json:"nick_name,omitempty"`
	CustId   int64  `json:"cust_id,omitempty"`
	Token    string `json:"token,omitempty"`
	Ws       *websocket.Conn
}

/*
	客服集合
*/
var listService = make(map[int]Service)
var listServiceWs = make(map[*websocket.Conn]int)

/*
	游客集合
*/
var listCust = make(map[int64]Cust)
var listCustWs = make(map[*websocket.Conn]int64)

/*
	客服接收消息
*/
type ToService struct {
   
	Type      string      `json:"type,omitempty"`
	ServiceId int         `json:"service_id,omitempty"`
	Messgae   interface{
   } `json:"message,omitempty"`
	NiceName  string      `json:"nick_name,omitempty"`
	CustId    int64       `json:"cust_id,omitempty"`
}



/*
	客服接受消息通道
*/
var ServiceChannal = make(chan ToService)

/*
	游客接收消息
*/
type ToCust struct {
   
	Type        string      `json:"type,omitempty"`
	CustId      int64       `json:"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值