-
Notifications
You must be signed in to change notification settings - Fork 164
/
client.go
41 lines (32 loc) · 1013 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package auth
import (
"github.com/ArtisanCloud/PowerLibs/v2/object"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v2/src/miniProgram/auth/response"
)
type Client struct {
*kernel.BaseClient
}
func NewClient(app *kernel.ApplicationInterface) (*Client, error) {
baseClient, err := kernel.NewBaseClient(app, nil)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}
// 登录凭证校验。
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
func (comp *Client) Session(code string) (*response.ResponseCode2Session, error) {
result := &response.ResponseCode2Session{}
config := (*comp.App).GetConfig()
params := &object.StringMap{
"appid": config.GetString("app_id", ""),
"secret": config.GetString("secret", ""),
"js_code": code,
"grant_type": "authorization_code",
}
_, err := comp.HttpGet("sns/jscode2session", params, nil, result)
return result, err
}