1 Star 0 Fork 0

扒拉扒拉 / wechat-sdk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
open.go 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
夏雨天 提交于 2023-05-12 08:37 . init
package component
import (
"gitee.com/vibly/wechat-sdk/mp/core"
)
func OpenBindGet(clt *core.Client) (openAppId string, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/open/get?access_token="
var result struct {
core.Error
OpenAppId string `json:"open_appid"`
}
var request = struct {
AppId string `json:"appid"`
}{}
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
openAppId = result.OpenAppId
return
}
func CreateOpenAndBind(clt *core.Client, appId string) (openAppId string, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/open/create?access_token="
var result struct {
core.Error
OpenAppId string `json:"open_appid"`
}
var request = struct {
AppId string `json:"appid"`
}{
AppId: appId,
}
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
openAppId = result.OpenAppId
return
}
func OpenBind(clt *core.Client, appId string, openAppId string) (err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/open/bind?access_token="
var result struct {
core.Error
}
var request = struct {
AppId string `json:"appid"`
OpenAppId string `json:"open_appid"`
}{
AppId: appId,
OpenAppId: openAppId,
}
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
return
}
1
https://gitee.com/vibly/wechat-sdk.git
git@gitee.com:vibly/wechat-sdk.git
vibly
wechat-sdk
wechat-sdk
v1.0.0

搜索帮助