44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package public_platform
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"git.valavala.com/vala/development-kit-sdk/utils"
|
|
access_token "git.valavala.com/vala/development-kit-sdk/wechat-sdk/access-token"
|
|
"git.valavala.com/vala/development-kit-sdk/wechat-sdk/structs"
|
|
)
|
|
|
|
type PublicPlatform struct {
|
|
}
|
|
|
|
func NewWechatPublicPlatform() *PublicPlatform {
|
|
return &PublicPlatform{}
|
|
}
|
|
|
|
// GetFans 获取公众号的关注列表
|
|
// https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=OPENID
|
|
func (p *PublicPlatform) GetFans(wechatConf *structs.WechatConf, nextOpenid string) (*structs.WechatPublicPlatformFansResp, error) {
|
|
mgr := access_token.NewWechatStableAccessTokenMgr()
|
|
accessToken, err := mgr.GetStableAccessToken(wechatConf)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
url := "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + accessToken + "&next_openid=" + nextOpenid
|
|
|
|
header := map[string]string{
|
|
"Content-Type": "application/json",
|
|
}
|
|
resp, err := utils.HttpRequest(http.MethodGet, url, header, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
wechatPublicPlatformFansResp := &structs.WechatPublicPlatformFansResp{}
|
|
_ = json.Unmarshal(resp, wechatPublicPlatformFansResp)
|
|
if wechatPublicPlatformFansResp.Errcode != 0 {
|
|
return nil, errors.New(wechatPublicPlatformFansResp.Errmsg)
|
|
}
|
|
return wechatPublicPlatformFansResp, nil
|
|
}
|