feat: analysis user auth and ws
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user