forked from chanxuehong/wechat
/
set.go
55 lines (47 loc) · 1.27 KB
/
set.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
// @description wechat 是腾讯微信公众平台 api 的 golang 语言封装
// @link https://github.com/chanxuehong/wechat for the canonical source repository
// @license https://github.com/chanxuehong/wechat/blob/master/LICENSE
// @authors chanxuehong(chanxuehong@gmail.com)
package homepage
import (
"github.com/chanxuehong/wechat/mp"
)
// 默认模板
func NewSetParameters1(shopId int64) interface{} {
return &struct {
ShopId int64 `json:"shop_id"`
TemplateId int64 `json:"template_id"`
}{
ShopId: shopId,
TemplateId: 0,
}
}
// 自定义url
func NewSetParameters2(shopId int64, url string) interface{} {
para := struct {
ShopId int64 `json:"shop_id"`
TemplateId int64 `json:"template_id"`
Struct struct {
URL string `json:"url"`
} `json:"struct"`
}{
ShopId: shopId,
TemplateId: 1,
}
para.Struct.URL = url
return ¶
}
// 设置商家主页
// 要求 para 经过 encoding/json 后满足指定的格式要求
func Set(clt *mp.Client, para interface{}) (err error) {
var result mp.Error
incompleteURL := "https://api.weixin.qq.com/bizwifi/homepage/set?access_token="
if err = clt.PostJSON(incompleteURL, para, &result); err != nil {
return
}
if result.ErrCode != mp.ErrCodeOK {
err = &result
return
}
return
}