You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
820 B
24 lines
820 B
package wx
|
|
|
|
import (
|
|
"context"
|
|
"sorbet/pkg/env"
|
|
)
|
|
|
|
type LoginResult struct {
|
|
SessionKey string `json:"session_key"` // 会话密钥
|
|
Unionid string `json:"unionid,omitempty"` // 用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台账号下会返回
|
|
Openid string `json:"openid,omitempty"` // 用户唯一标识
|
|
Result
|
|
}
|
|
|
|
// Login 小程序登录
|
|
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/code2Session.html
|
|
func Login(ctx context.Context, code string) (*LoginResult, error) {
|
|
return httpGet[LoginResult](ctx, "https://api.weixin.qq.com/sns/jscode2session", map[string]string{
|
|
"appid": env.String("WECHAT_APPID"),
|
|
"secret": env.String("WECHAT_SECRET"),
|
|
"grant_type": "authorization_code",
|
|
"js_code": code,
|
|
})
|
|
}
|
|
|