微信相关接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.0 KiB

package wechat
import (
"errors"
"fmt"
)
type AppOpenIdData struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
Openid string `json:"openid"`
Scope string `json:"scope"`
Unionid interface{} `json:"unionid"`
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
}
type MiniAppOpenidData struct {
Openid string `json:"openid"`
SessionKey interface{} `json:"session_key"`
Unionid interface{} `json:"unionid"`
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
}
type MpOpenIdData struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
Openid string `json:"openid"`
Scope string `json:"scope"`
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
}
/**
* 从微信api取openid
*/
func GetAppOpenid(appid, secret, code string) (AppOpenIdData, error) {
var data AppOpenIdData
url := fmt.Sprintf(GET_APP_OPENID, appid, secret, code)
data_byte, err := SendHttp("GET", url, nil)
if err != nil {
return data, err
}
err = json.Unmarshal(data_byte, &data)
return data, err
}
/**
* 从微信api取小程序openid
*/
func GetMiniAppOpenid(appid, secret, code string) (MiniAppOpenidData, error) {
url := fmt.Sprintf(GET_MINIAPP_OPENID_API, appid, secret, code)
data_byte, err := SendHttp("GET", url, nil)
var data MiniAppOpenidData
if err != nil {
return data, err
}
err = json.Unmarshal(data_byte, &data)
return data, err
}
/**
* 从微信api取公众号openid
*/
func GetMpOpenid(appid, secret, code string) (MpOpenIdData, error) {
url := fmt.Sprintf(GET_MP_OPENID_API, appid, secret, code)
data_byte, err := SendHttp("GET", url, nil)
var data MpOpenIdData
if err != nil {
return data, err
}
err = json.Unmarshal(data_byte, &data)
if data.Errcode != 0 {
return data, errors.New(data.Errmsg)
}
return data, err
}