go-wxhelper/pkg/wxhelper/base.go

45 lines
951 B
Go
Raw Normal View History

package wxhelper
import (
"errors"
robotModel "wechat-robot/model/robot"
"wechat-robot/utils"
)
// CheckLogin
// @description: 检查是否登录
// @receiver wx
// @return flag
func (wx wxHelper) CheckLogin() (flag bool) {
var api string
if api, flag = wx.version.GetApi("CheckLogin"); !flag {
return
}
// 调用接口
var resp robotModel.Response[any]
_ = utils.HttpClientUtils().Post(wx.host+api, nil, &resp, 0)
return resp.Code == 1
}
// UserInfo
// @description: 获取机器人信息
// @receiver wx
// @return data
// @return err
func (wx wxHelper) UserInfo() (data robotModel.UserInfo, err error) {
var api string
var flag bool
if api, flag = wx.version.GetApi("UserInfo"); !flag {
err = errors.New("不支持的接口")
return
}
// 调用接口
var resp robotModel.Response[robotModel.UserInfo]
if err = utils.HttpClientUtils().Post(wx.host+api, nil, &resp, 0); err != nil {
return
}
data = resp.Data
return
}