-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp.go
67 lines (55 loc) · 1.11 KB
/
mp.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
package wechat
import (
"fmt"
"github.com/sohaha/zlsgo/zhttp"
)
type (
Mp struct {
// 公众号 ID
AppID string
// 公众号密钥
AppSecret string
EncodingAesKey string
Token string
engine *Engine
}
)
var _ Cfg = new(Mp)
func (m *Mp) setEngine(engine *Engine) {
m.engine = engine
}
func (m *Mp) getEngine() *Engine {
return m.engine
}
func (m *Mp) GetAppID() string {
return m.AppID
}
func (m *Mp) GetSecret() string {
return m.AppSecret
}
func (m *Mp) GetToken() string {
return m.Token
}
func (m *Mp) GetEncodingAesKey() string {
return m.EncodingAesKey
}
func (m *Mp) getAccessToken() (data []byte, err error) {
res, err := http.Post(fmt.Sprintf(
"%s/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s",
APIURL, m.AppID, m.AppSecret))
if err != nil {
return
}
data = res.Bytes()
return
}
func (m *Mp) getJsapiTicket() (data *zhttp.Res, err error) {
var token string
token, err = m.engine.GetAccessToken()
if err != nil {
return nil, err
}
return http.Post(fmt.Sprintf(
"%s/cgi-bin/ticket/getticket?&type=jsapi&access_token=%s",
APIURL, token))
}