74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"qiweimanager/logger"
|
|
)
|
|
|
|
// 全局变量
|
|
var (
|
|
globalLogger *logger.Logger
|
|
globalLoaderFuncs *LoaderFunctions
|
|
loaderFuncsMutex sync.Mutex
|
|
|
|
// ResponseMap 用于存储客户端ID和对应的响应通道
|
|
ResponseMap = make(map[int32]chan ClientResponseData)
|
|
responseMapMu sync.Mutex
|
|
|
|
// ResponseMap 用于存储客户端ID和对应的响应通道
|
|
globalClientMap = make(map[uint32]string)
|
|
)
|
|
|
|
// LoaderFunctions 定义了从Loader DLL获取的所有函数指针
|
|
type LoaderFunctions struct {
|
|
GetUserWxWorkVersion uintptr
|
|
UseUtf8 uintptr
|
|
UseRecvJsUnicode uintptr
|
|
InitWxWorkSocket uintptr
|
|
SetDataLocationPath uintptr
|
|
InjectWxWork uintptr
|
|
InjectWxWorkMultiOpen uintptr
|
|
InjectWxWorkPid uintptr
|
|
DestroyWxWork uintptr
|
|
SendWxWorkData uintptr
|
|
}
|
|
|
|
// ClientResponseData 定义客户端响应数据结构
|
|
type ClientResponseData struct {
|
|
ClientId int32 `json:"clientId"`
|
|
Data map[string]interface{} `json:"data"`
|
|
}
|
|
|
|
// SetResponseChannel 为指定的客户端ID设置响应通道
|
|
func SetResponseChannel(clientId int32, ch chan ClientResponseData) {
|
|
responseMapMu.Lock()
|
|
ResponseMap[clientId] = ch
|
|
responseMapMu.Unlock()
|
|
}
|
|
|
|
// GetResponseChannel 获取指定客户端ID的响应通道
|
|
func TrySetResponseChannel(clientId int32, ch chan ClientResponseData) bool {
|
|
responseMapMu.Lock()
|
|
defer responseMapMu.Unlock()
|
|
if _, exists := ResponseMap[clientId]; exists {
|
|
return false
|
|
}
|
|
ResponseMap[clientId] = ch
|
|
return true
|
|
}
|
|
|
|
func GetResponseChannel(clientId int32) (chan ClientResponseData, bool) {
|
|
responseMapMu.Lock()
|
|
ch, exists := ResponseMap[clientId]
|
|
responseMapMu.Unlock()
|
|
return ch, exists
|
|
}
|
|
|
|
// RemoveResponseChannel 移除指定客户端ID的响应通道
|
|
func RemoveResponseChannel(clientId int32) {
|
|
responseMapMu.Lock()
|
|
delete(ResponseMap, clientId)
|
|
responseMapMu.Unlock()
|
|
}
|