-
Notifications
You must be signed in to change notification settings - Fork 147
/
client.go
100 lines (76 loc) · 2.57 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package wxaCode
import (
"github.com/ArtisanCloud/PowerLibs/v2/http/response"
"github.com/ArtisanCloud/PowerLibs/v2/object"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel/power"
response4 "github.com/ArtisanCloud/PowerWeChat/v2/src/work/media/response"
"net/http"
)
type Client struct {
*kernel.BaseClient
}
// 获取小程序二维码,适用于需要的码数量较少的业务场景
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.createQRCode.html
func (comp *Client) CreateQRCode(path string, width int64) (*http.Response, error) {
var result string
var header = &response4.ResponseHeaderMedia{}
if width <= 0 {
width = 430
}
data := &object.HashMap{
"form_params": &object.HashMap{
"path": path,
"width": width,
},
}
rs, err := comp.RequestRaw("cgi-bin/wxaapp/createwxaqrcode", "POST", data, &header, &result)
httpRS := rs.(*response.HttpResponse).Response
return httpRS, err
}
// 获取小程序码,适用于需要的码数量较少的业务场景
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.get.html
func (comp *Client) Get(path string, width int64,
autoColor bool, lineColor *power.HashMap, isHyaline bool) (*http.Response, error) {
var result string
var header = &response4.ResponseHeaderMedia{}
if width <= 0 {
width = 430
}
data := &object.HashMap{
"form_params": &object.HashMap{
"path": path,
"width": width,
"auto_color": autoColor,
"line_color": lineColor.ToHashMap(),
"is_hyaline": isHyaline,
},
}
rs, err := comp.RequestRaw("wxa/getwxacode", "POST", data, &header, &result)
httpRS := rs.(*response.HttpResponse).Response
return httpRS, err
}
// 获取小程序码,适用于需要的码数量极多的业务场景
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html
func (comp *Client) GetUnlimited(
scene string, page string, width int64,
autoColor bool, lineColor *power.HashMap, isHyaline bool) (*http.Response, error) {
var result string
var header = &response4.ResponseHeaderMedia{}
if width <= 0 {
width = 430
}
data := &object.HashMap{
"form_params": &object.HashMap{
"scene": scene,
"page": page,
"width": width,
"auto_color": autoColor,
"line_color": lineColor.ToHashMap(),
"is_hyaline": isHyaline,
},
}
rs, err := comp.RequestRaw("wxa/getwxacodeunlimit", "POST", data, &header, &result)
httpRS := rs.(*response.HttpResponse).Response
return httpRS, err
}