feat: analysis user auth and ws

This commit is contained in:
zzw
2026-10-15 09:23:07 +08:00
parent 6fa185003d
commit a65b6d2803
102 changed files with 4966 additions and 786 deletions
+5 -5
View File
@@ -1,13 +1,13 @@
package qrcode
import "lone-services/pkg/wechat/auth"
type Client struct {
AppID string
Secret string
Auth *auth.Client
}
func NewClient(appID, secret string) *Client {
func NewClient(authCli *auth.Client) *Client {
return &Client{
AppID: appID,
Secret: secret,
Auth: authCli,
}
}
+1 -2
View File
@@ -17,10 +17,9 @@ type UnlimitedRequest struct {
IsHyaline bool `json:"is_hyaline,omitempty"`
}
// WxaCodeRequest 有数量限制的小程序码(getwxacode),path 可带 query。
type WxaCodeRequest struct {
Path string `json:"path"`
EnvVersion string `json:"env_version,omitempty"`
EnvVersion string `json:"env_version,omitempty"` // release / trial / develop
Width int `json:"width,omitempty"`
AutoColor bool `json:"auto_color,omitempty"`
LineColor *LineColor `json:"line_color,omitempty"`
+4 -2
View File
@@ -13,7 +13,6 @@ import (
"time"
"lone-services/pkg/utils"
"lone-services/pkg/wechat/auth"
)
const unlimitedURL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit"
@@ -54,7 +53,10 @@ func (c *Client) GetUnlimited(accessToken string, req *UnlimitedRequest) ([]byte
}
func (c *Client) CreateUnlimited(ctx context.Context, req *UnlimitedRequest) ([]byte, error) {
token, err := auth.NewClient(c.AppID, c.Secret).AccessToken(ctx)
if c == nil || c.Auth == nil {
return nil, fmt.Errorf("wechat qrcode auth client nil")
}
token, err := c.Auth.AccessToken(ctx)
if err != nil {
return nil, err
}
+4 -6
View File
@@ -11,13 +11,10 @@ import (
"time"
"lone-services/pkg/utils"
"lone-services/pkg/wechat/auth"
)
// 小程序码(有数量限制):https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getQRCode.html
const wxaCodeURL = "https://api.weixin.qq.com/wxa/getwxacode"
// BuildPath 拼小程序 path,如 pagesB/userLogin/index?session_id=xxx
func BuildPath(page string, params map[string]string) string {
if len(params) == 0 {
return page
@@ -29,7 +26,6 @@ func BuildPath(page string, params map[string]string) string {
return page + "?" + query.Encode()
}
// GetWxaCode 使用已有 access_token 生成有限小程序码,成功返回图片二进制。
func (c *Client) GetWxaCode(accessToken string, req *WxaCodeRequest) ([]byte, error) {
if accessToken == utils.StringEmpty {
return nil, fmt.Errorf("wechat access_token empty")
@@ -65,9 +61,11 @@ func (c *Client) GetWxaCode(accessToken string, req *WxaCodeRequest) ([]byte, er
return body, nil
}
// CreateWxaCode 通过 auth 拉取 access_token 后生成有限小程序码。
func (c *Client) CreateWxaCode(ctx context.Context, req *WxaCodeRequest) ([]byte, error) {
token, err := auth.NewClient(c.AppID, c.Secret).AccessToken(ctx)
if c == nil || c.Auth == nil {
return nil, fmt.Errorf("wechat qrcode auth client nil")
}
token, err := c.Auth.AccessToken(ctx)
if err != nil {
return nil, err
}