package qq_obv11 // 本文件实现四个端里的 **ws + client**(裁决 1.4):连接由 Cyrene 发起 // (Cyrene→OneBot),主动拨号 OneBot 实现的「正向 WS」端点(remote_url),建立后 // 收发都走这条长连接。access_token 同时以 Authorization: Bearer 头与 // ?access_token= 查询参数发送,兼容只认其中一种的 OneBot 实现。 import ( "context" "errors" "fmt" "net/url" "strings" ) // connectClient dials the configured OneBot WebSocket endpoint and installs the // resulting connection as the active session. func (a *Adapter) connectClient(ctx context.Context) error { if a.cfg.RemoteURL == "" { return errors.New("qq-obv11: client mode requires remoteURL") } target := appendQueryToken(a.cfg.RemoteURL, a.cfg.AccessToken) conn, err := dialWS(ctx, a.cfg.DialContext, target, a.cfg.AccessToken) if err != nil { return fmt.Errorf("qq-obv11: dial onebot ws %s: %w", a.cfg.RemoteURL, err) } a.setConn(conn) a.log.Info("connected to onebot ws (client mode)", "url", a.cfg.RemoteURL) return nil } // appendQueryToken adds an access_token query parameter to a URL, preserving any // existing query string. func appendQueryToken(rawURL, token string) string { if token == "" { return rawURL } sep := "?" if strings.Contains(rawURL, "?") { sep = "&" } return rawURL + sep + "access_token=" + url.QueryEscape(token) }