-
Notifications
You must be signed in to change notification settings - Fork 160
/
client.go
58 lines (44 loc) · 1.7 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package account
import (
"fmt"
"github.com/ArtisanCloud/PowerLibs/v2/object"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v2/src/openPlatform/authorizer/aggregate/account"
"github.com/ArtisanCloud/PowerWeChat/v2/src/openPlatform/authorizer/officialAccount/account/response"
)
type Client struct {
*account.Client
// PowerWechat\OpenPlatform\Application
component kernel.ApplicationInterface
}
func NewClient(app kernel.ApplicationInterface, component kernel.ApplicationInterface) (*Client, error) {
client, err := account.NewClient(app)
if err != nil {
return nil, err
}
return &Client{
client,
component,
}, nil
}
// 从第三方平台跳转至微信公众平台授权注册页面, 授权注册小程序.
func (comp *Client) GetFastRegistrationUrl(callbackUrl string, copyWxVerify bool) string {
config := (*comp.App).GetConfig()
componentConfig := comp.component.GetConfig()
queries := &object.StringMap{
"copy_wx_verify": fmt.Sprintf("%t", copyWxVerify),
"component_appid": componentConfig.GetString("app_id", ""),
"appid": config.GetString("app_id", ""),
"redirect_uri": callbackUrl,
}
return "https://mp.weixin.qq.com/cgi-bin/fastregisterauth?" + object.GetJoinedWithKSort(queries)
}
// 复用公众号主体快速注册小程序
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Register_Mini_Programs/fast_registration_of_mini_program.html
func (comp *Client) Register(ticket string) (*response.ResponseRegister, error) {
result := &response.ResponseRegister{}
_, err := comp.HttpPostJson("cgi-bin/account/fastregister", &object.HashMap{
"ticket": ticket,
}, nil, nil, result)
return result, err
}