-
Notifications
You must be signed in to change notification settings - Fork 35
/
acode.go
48 lines (39 loc) · 1.1 KB
/
acode.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
package weixin
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"github.com/arstd/log"
)
const (
urlWxAcode = "https://api.weixin.qq.com/wxa/getwxacode?access_token=%s"
jsWxAcodeReqBody = `{"path":"%s","width":430,"auto_color":true}`
)
const (
urlWxAcodeUnlimit = "http://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s"
jsWxAcodeUnlimitReqBody = `{"scene":"%s","width":430,"auto_color":true}`
)
func Acode(path string) (io.ReadCloser, error) {
atoken := AccessToken()
url := fmt.Sprintf(urlWxAcode, atoken)
in := fmt.Sprintf(jsWxAcodeReqBody, path)
resp, err := http.Post(url, "application/json", bytes.NewBufferString(in))
if err != nil {
return nil, err
}
log.Debug(resp.Header.Get("Content-Type"))
return resp.Body, nil
}
func AcodeUnlimit(scene string) ([]byte, error) {
atoken := AccessToken()
url := fmt.Sprintf(urlWxAcodeUnlimit, atoken)
in := fmt.Sprintf(jsWxAcodeUnlimitReqBody, scene)
resp, err := http.Post(url, "application/json", bytes.NewBufferString(in))
if err != nil {
return nil, err
}
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
}