Example #1
0
// Get 获取用户基本信息.
//  注意:
//  1. 需要判断返回的 UserInfo.IsSubscriber 是等于 1 还是 0
//  2. lang 指定返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语, 默认为 zh_CN
func Get(clt *core.Client, openId string, lang string) (info *UserInfo, err error) {
	switch lang {
	case "":
		lang = LanguageZhCN
	case LanguageZhCN, LanguageZhTW, LanguageEN:
	default:
		lang = LanguageZhCN
	}

	var incompleteURL = "https://api.weixin.qq.com/cgi-bin/user/info?openid=" + url.QueryEscape(openId) +
		"&lang=" + lang + "&access_token="
	var result struct {
		core.Error
		UserInfo
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	info = &result.UserInfo
	return
}
Example #2
0
// 删除自定义菜单.
func Delete(clt *core.Client) (err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token="

	var result core.Error
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result
		return
	}
	return
}
Example #3
0
// Delete 删除客服账号
func Delete(clt *core.Client, kfAccount string) (err error) {
	// TODO
	//	incompleteURL := "https://api.weixin.qq.com/customservice/kfaccount/del?kf_account=" +
	//		url.QueryEscape(kfAccount) + "&access_token="
	incompleteURL := "https://api.weixin.qq.com/customservice/kfaccount/del?kf_account=" +
		kfAccount + "&access_token="

	var result core.Error
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result
		return
	}
	return
}
Example #4
0
// 获取模板列表
func GetAllPrivateTemplate(clt *core.Client) (templateList []Template, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token="

	var result struct {
		core.Error
		TemplateList []Template `json:"template_list"`
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	templateList = result.TemplateList
	return
}
Example #5
0
// List 查询所有分组.
func List(clt *core.Client) (groups []Group, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token="

	var result struct {
		core.Error
		Groups []Group `json:"groups"`
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	groups = result.Groups
	return
}
Example #6
0
// 获取微信服务器IP地址.
//  如果公众号基于安全等考虑,需要获知微信服务器的IP地址列表,以便进行相关限制,可以通过该接口获得微信服务器IP地址列表。
func GetCallbackIP(clt *core.Client) (ipList []string, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token="

	var result struct {
		core.Error
		List []string `json:"ip_list"`
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	ipList = result.List
	return
}
Example #7
0
// 获取素材总数数据.
func GetMaterialCount(clt *core.Client) (info *MaterialCountInfo, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token="

	var result struct {
		core.Error
		MaterialCountInfo
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	info = &result.MaterialCountInfo
	return
}
Example #8
0
// OnlineKfList 获取在线客服接待信息.
func OnlineKfList(clt *core.Client) (list []OnlineKfInfo, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token="

	var result struct {
		core.Error
		OnlineKfInfoList []OnlineKfInfo `json:"kf_online_list"`
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	list = result.OnlineKfInfoList
	return
}
Example #9
0
// CategoryList 获取门店类目表.
func CategoryList(clt *core.Client) (list []string, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/api_getwxcategory?access_token="

	var result struct {
		core.Error
		CategoryList []string `json:"category_list"`
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	list = result.CategoryList
	return
}
Example #10
0
// WaitCaseList 获取未接入会话列表.
func WaitCaseList(clt *core.Client) (rslt *WaitCaseListResult, err error) {
	const incompleteURL = "https://api.weixin.qq.com/customservice/kfsession/getwaitcase?access_token="

	var result struct {
		core.Error
		WaitCaseListResult
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	result.WaitCaseListResult.ItemCount = len(result.WaitCaseListResult.Items)
	rslt = &result.WaitCaseListResult
	return
}
Example #11
0
// 查询审核状态
func GetAuditStatus(clt *core.Client) (status *AuditStatus, err error) {
	var result struct {
		core.Error
		AuditStatus `json:"data"`
	}

	incompleteURL := "https://api.weixin.qq.com/shakearound/account/auditstatus?access_token="
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}

	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	status = &result.AuditStatus
	return
}
Example #12
0
// 获取卡券最新的颜色列表.
func GetColors(clt *core.Client) (colors []Color, err error) {
	var result struct {
		core.Error
		Colors []Color `json:"colors"`
	}

	incompleteURL := "https://api.weixin.qq.com/card/getcolors?access_token="
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}

	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	colors = result.Colors
	return
}
Example #13
0
// 获取设置的行业信息
func GetIndustry(clt *core.Client) (primaryIndustry, secondaryIndustry Industry, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token="

	var result struct {
		core.Error
		PrimaryIndustry   Industry `json:"primary_industry"`
		SecondaryIndustry Industry `json:"secondary_industry"`
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	primaryIndustry = result.PrimaryIndustry
	secondaryIndustry = result.SecondaryIndustry
	return
}
Example #14
0
// Get 获取客户的会话
func Get(clt *core.Client, openId string) (ss *Session, err error) {
	incompleteURL := "https://api.weixin.qq.com/customservice/kfsession/getsession?openid=" +
		url.QueryEscape(openId) + "&access_token="

	var result struct {
		core.Error
		Session
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	result.Session.OpenId = openId
	ss = &result.Session
	return
}
Example #15
0
// 查询自定义菜单.
func Get(clt *core.Client) (menu *Menu, conditionalMenus []Menu, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token="

	var result struct {
		core.Error
		Menu             Menu   `json:"menu"`
		ConditionalMenus []Menu `json:"conditionalmenu"`
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	menu = &result.Menu
	conditionalMenus = result.ConditionalMenus
	return
}
Example #16
0
// 获取自定义菜单配置接口.
func GetMenuInfo(clt *core.Client) (info MenuInfo, isMenuOpen bool, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token="

	var result struct {
		core.Error
		IsMenuOpen int      `json:"is_menu_open"`
		MenuInfo   MenuInfo `json:"selfmenu_info"`
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	info = result.MenuInfo
	if result.IsMenuOpen != 0 {
		isMenuOpen = true
	}
	return
}
Example #17
0
// List 获取用户列表.
//  NOTE: 每次最多能获取 10000 个用户, 可以多次指定 nextOpenId 来获取以满足需求, 如果 nextOpenId == "" 则表示从头获取
func List(clt *core.Client, nextOpenId string) (rslt *ListResult, err error) {
	var incompleteURL string
	if nextOpenId == "" {
		incompleteURL = "https://api.weixin.qq.com/cgi-bin/user/get?access_token="
	} else {
		incompleteURL = "https://api.weixin.qq.com/cgi-bin/user/get?next_openid=" + url.QueryEscape(nextOpenId) + "&access_token="
	}

	var result struct {
		core.Error
		ListResult
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	rslt = &result.ListResult
	return
}
Example #18
0
// List 获取客服的会话列表, 开发者可以通过本接口获取某个客服正在接待的会话列表.
func List(clt *core.Client, kfAccount string) (list []Session, err error) {
	// TODO
	//	incompleteURL := "https://api.weixin.qq.com/customservice/kfsession/getsessionlist?kf_account=" +
	//		url.QueryEscape(kfAccount) + "&access_token="
	incompleteURL := "https://api.weixin.qq.com/customservice/kfsession/getsessionlist?kf_account=" +
		kfAccount + "&access_token="

	var result struct {
		core.Error
		SessionList []Session `json:"sessionlist"`
	}
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	for i := 0; i < len(result.SessionList); i++ {
		result.SessionList[i].KfAccount = kfAccount
	}
	list = result.SessionList
	return
}