Exemple #1
0
// 卡券投放, 创建二维码接口.
func Create(clt *mp.Client, para *CreateParameters) (info *QRCodeInfo, err error) {
	request := struct {
		ActionName    string `json:"action_name"`
		ExpireSeconds int    `json:"expire_seconds,omitempty"`
		ActionInfo    struct {
			Card *CreateParameters `json:"card,omitempty"`
		} `json:"action_info"`
	}{
		ActionName:    "QR_CARD",
		ExpireSeconds: para.ExpireSeconds,
	}
	request.ActionInfo.Card = para

	var result struct {
		mp.Error
		QRCodeInfo
	}

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	info = &result.QRCodeInfo
	return
}
Exemple #2
0
// 更改卡券信息接口.
//  sendCheck: 是否提交审核,false为修改后不会重新提审,true为修改字段后重新提审,该卡券的状态变为审核中。
func Update(clt *mp.Client, cardId string, card *Card) (sendCheck bool, err error) {
	request := struct {
		CardId string `json:"card_id"`
		*Card
	}{
		CardId: cardId,
		Card:   card,
	}

	var result struct {
		mp.Error
		SendCheck bool `json:"send_check"`
	}

	incompleteURL := "https://api.weixin.qq.com/card/update?access_token="
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}
	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	sendCheck = result.SendCheck
	return
}
Exemple #3
0
func addFromReader(clt *mp.Client, filename string, reader io.Reader, _type string) (info ImageInfo, err error) {
	var result struct {
		mp.Error
		ImageInfo `json:"data"`
	}

	var incompleteURL string
	if _type != "" {
		incompleteURL = "https://api.weixin.qq.com/shakearound/material/add?type=" + url.QueryEscape(_type) +
			"&access_token="
	} else {
		incompleteURL = "https://api.weixin.qq.com/shakearound/material/add?access_token="
	}
	fields := []mp.MultipartFormField{{
		ContentType: 0,
		FieldName:   "media",
		FileName:    filename,
		Value:       reader,
	}}
	if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	info = result.ImageInfo
	return
}
Exemple #4
0
// 库存修改接口.
// cardId:      卡券ID
// increaseNum: 增加库存数量, 可以为负数
func ModifyStock(clt *mp.Client, cardId string, increaseNum int) (err error) {
	request := struct {
		CardId             string `json:"card_id"`
		IncreaseStockValue int    `json:"increase_stock_value,omitempty"`
		ReduceStockValue   int    `json:"reduce_stock_value,omitempty"`
	}{
		CardId: cardId,
	}
	switch {
	case increaseNum > 0:
		request.IncreaseStockValue = increaseNum
	case increaseNum < 0:
		request.ReduceStockValue = -increaseNum
	default: // increaseNum == 0
		return
	}

	var result mp.Error

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #5
0
// 设置客服信息(增量更新, 不更新的可以留空).
//  account:    完整客服账号, 格式为: 账号前缀@公众号微信号, 账号前缀最多10个字符, 必须是英文或者数字字符.
//  nickname:   客服昵称, 最长6个汉字或12个英文字符
//  password:   客服账号登录密码
//  isPwdPlain: 标识 password 是否为明文格式, true 表示是明文密码, false 表示是密文密码.
func SetKfAccount(clt *mp.Client, account, nickname, password string, isPwdPlain bool) (err error) {
	if isPwdPlain && password != "" {
		md5Sum := md5.Sum([]byte(password))
		password = hex.EncodeToString(md5Sum[:])
	}

	request := struct {
		Account  string `json:"kf_account"`
		Nickname string `json:"nickname,omitempty"`
		Password string `json:"password,omitempty"`
	}{
		Account:  account,
		Nickname: nickname,
		Password: password,
	}

	var result mp.Error

	incompleteURL := "https://api.weixin.qq.com/customservice/kfaccount/update?access_token="
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #6
0
// 批量查询设备统计数据接口
func DeviceList(clt *mp.Client, date int64, pageIndex int) (rslt *DeviceListResult, err error) {
	request := struct {
		Date      int64 `json:"date"`
		PageIndex int   `json:"page_index"`
	}{
		Date:      date,
		PageIndex: pageIndex,
	}

	var result struct {
		mp.Error
		DeviceListResult
	}

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}

	devices := result.DeviceListResult.Data.DeviceStatisticsList
	for i := 0; i < len(devices); i++ {
		devices[i].Ftime = result.DeviceListResult.Date
	}
	result.DeviceListResult.ItemCount = len(devices)
	rslt = &result.DeviceListResult
	return
}
Exemple #7
0
// 数据统计
//  shopId     按门店ID搜索,-1为总统计
//  beginDate: 起始日期时间,格式yyyy-mm-dd,最长时间跨度为30天
//  endDate:   结束日期时间戳,格式yyyy-mm-dd,最长时间跨度为30天
func List(clt *mp.Client, shopId int64, beginDate, endDate string) (data []Statistics, err error) {
	request := struct {
		ShopId    int64  `json:"shop_id"`
		BeginDate string `json:"begin_date"`
		EndDate   string `json:"end_date"`
	}{
		ShopId:    shopId,
		BeginDate: beginDate,
		EndDate:   endDate,
	}

	var result struct {
		mp.Error
		Data []Statistics `json:"data"`
	}

	incompleteURL := "https://api.weixin.qq.com/bizwifi/statistics/list?access_token="
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}

	data = result.Data
	return
}
Exemple #8
0
// 以设备为维度的数据统计接口
func Device(clt *mp.Client, deviceIdentifier *device.DeviceIdentifier, beginDate, endDate int64) (data []StatisticsBase, err error) {
	request := struct {
		DeviceIdentifier *device.DeviceIdentifier `json:"device_identifier,omitempty"`
		BeginDate        int64                    `json:"begin_date"`
		EndDate          int64                    `json:"end_date"`
	}{
		DeviceIdentifier: deviceIdentifier,
		BeginDate:        beginDate,
		EndDate:          endDate,
	}

	var result struct {
		mp.Error
		Data []StatisticsBase `json:"data"`
	}

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	data = result.Data
	return
}
Exemple #9
0
// 获取客服的会话列表
//  开发者可以通过本接口获取某个客服正在接待的会话列表。
func GetSessionList(clt *mp.Client, kfAccount string) (list []Session, err error) {
	var result struct {
		mp.Error
		SessionList []Session `json:"sessionlist"`
	}

	// 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="
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	for i, l := 0, result.SessionList; i < len(l); i++ {
		l[i].KfAccount = kfAccount
	}
	list = result.SessionList
	return
}
Exemple #10
0
// 获取摇周边的设备及用户信息
//  ticket:  摇周边业务的ticket,可在摇到的URL中得到,ticket生效时间为30分钟,每一次摇都会重新生成新的ticket
//  needPoi: 是否需要返回门店poi_id
func GetShakeInfo(clt *mp.Client, ticket string, needPoi bool) (info *Shakeinfo, err error) {
	request := struct {
		Ticket  string `json:"ticket"`
		NeedPoi int    `json:"need_poi,omitempty"`
	}{
		Ticket: ticket,
	}

	if needPoi {
		request.NeedPoi = 1
	}

	var result struct {
		mp.Error
		Shakeinfo `json:"data"`
	}

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	info = &result.Shakeinfo
	return
}
Exemple #11
0
// 以页面为维度的数据统计接口
func Page(clt *mp.Client, pageId, beginDate, endDate int64) (data []StatisticsBase, err error) {
	request := struct {
		PageId    int64 `json:"page_id"`
		BeginDate int64 `json:"begin_date"`
		EndDate   int64 `json:"end_date"`
	}{
		PageId:    pageId,
		BeginDate: beginDate,
		EndDate:   endDate,
	}

	var result struct {
		mp.Error
		Data []StatisticsBase `json:"data"`
	}

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	data = result.Data
	return
}
Exemple #12
0
// 获取用户已领取卡券接口
//  openid: 需要查询的用户openid
//  cardid: 卡券ID。不填写时默认查询当前appid下的卡券。
func GetCardList(clt *mp.Client, openid, cardid string) (list []code.CardItemIdentifier, err error) {
	request := struct {
		OpenId string `json:"openid"`
		CardId string `json:"card_id,omitempty"`
	}{
		OpenId: openid,
		CardId: cardid,
	}

	var result struct {
		mp.Error
		CardList []code.CardItemIdentifier `json:"card_list"`
	}

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	list = result.CardList
	return
}
Exemple #13
0
// 获取物料二维码
//  shopId: 门店ID
//  imgId:  物料样式编号:
//          0-二维码,可用于自由设计宣传材料;
//          1-桌贴(二维码),100mm×100mm(宽×高),可直接张贴
func Get(clt *mp.Client, shopId int64, imgId int) (qrcodeURL string, err error) {
	request := struct {
		ShopId int64 `json:"shop_id"`
		ImgId  int   `json:"img_id"`
	}{
		ShopId: shopId,
		ImgId:  imgId,
	}

	var result struct {
		mp.Error
		Data struct {
			QRCodeURL string `json:"qrcode_url"`
		} `json:"data"`
	}

	incompleteURL := "https://api.weixin.qq.com/bizwifi/qrcode/get?access_token="
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}

	qrcodeURL = result.Data.QRCodeURL
	return
}
Exemple #14
0
func Get(clt *mp.Client, shopId int64) (homepage *Homepage, err error) {
	request := struct {
		ShopId int64 `json:"shop_id"`
	}{
		ShopId: shopId,
	}

	var result struct {
		mp.Error
		Homepage `json:"data"`
	}

	incompleteURL := "https://api.weixin.qq.com/bizwifi/homepage/get?access_token="
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}

	homepage = &result.Homepage
	return
}
Exemple #15
0
// 编辑页面信息
func Update(clt *mp.Client, para *UpdateParameters) (err error) {
	var result mp.Error

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #16
0
// 更新会议门票
func UpdateUser(clt *mp.Client, para *UpdateUserParameters) (err error) {
	var result mp.Error

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #17
0
// 激活/绑定会员卡
func Activate(clt *mp.Client, para *ActivateParameters) (err error) {
	var result mp.Error

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #18
0
// 添加设备
func Add(clt *mp.Client, para *AddParameters) (err error) {
	var result mp.Error

	incompleteURL := "https://api.weixin.qq.com/bizwifi/device/add?access_token="
	if err = clt.PostJSON(incompleteURL, para, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #19
0
// 设置商家主页
//  要求 para 经过 encoding/json 后满足指定的格式要求
func Set(clt *mp.Client, para interface{}) (err error) {
	var result mp.Error

	incompleteURL := "https://api.weixin.qq.com/bizwifi/homepage/set?access_token="
	if err = clt.PostJSON(incompleteURL, para, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #20
0
// 更新飞机票信息接口
func Checkin(clt *mp.Client, para *CheckinParameters) (err error) {
	var result mp.Error

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #21
0
// 申请开通功能
func Register(clt *mp.Client, para *RegisterParameters) (err error) {
	var result mp.Error

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #22
0
// 设置卡券失效接口.
func Unavailable(clt *mp.Client, id *CardItemIdentifier) (err error) {
	var result mp.Error

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #23
0
// 设置测试白名单
func Set(clt *mp.Client, para *SetParameters) (err error) {
	var result mp.Error

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #24
0
// 删除客服账号
func DeleteKfAccount(clt *mp.Client, kfAccount string) (err error) {
	var result mp.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="
	if err = clt.GetJSON(incompleteURL, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result
		return
	}
	return
}
Exemple #25
0
// 查询审核状态
func GetAuditStatus(clt *mp.Client) (status *AuditStatus, err error) {
	var result struct {
		mp.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 != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	status = &result.AuditStatus
	return
}
Exemple #26
0
// 获取卡券最新的颜色列表.
func GetColors(clt *mp.Client) (colors []Color, err error) {
	var result struct {
		mp.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 != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	colors = result.Colors
	return
}
Exemple #27
0
// 拉取会员卡数据接口
func GetMemberCardInfo(clt *mp.Client, req *Request) (list []MemberCardData, err error) {
	var result struct {
		mp.Error
		List []MemberCardData `json:"list"`
	}

	incompleteURL := "https://api.weixin.qq.com/datacube/getcardmembercardinfo?access_token="
	if err = clt.PostJSON(incompleteURL, req, &result); err != nil {
		return
	}

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	list = result.List
	return
}
Exemple #28
0
// 更新会员信息
func UpdateUser(clt *mp.Client, para *UpdateUserParameters) (rslt *UpdateUserResult, err error) {
	var result struct {
		mp.Error
		UpdateUserResult
	}

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	rslt = &result.UpdateUserResult
	return
}
Exemple #29
0
// 获取在线客服接待信息.
func OnlineKfList(clt *mp.Client) (kfList []OnlineKfInfo, err error) {
	var result struct {
		mp.Error
		OnlineKfInfoList []OnlineKfInfo `json:"kf_online_list"`
	}

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	kfList = result.OnlineKfInfoList
	return
}
Exemple #30
0
// 拉取会员信息(积分查询)接口
func Get(clt *mp.Client, id *code.CardItemIdentifier) (info *UserInfo, err error) {
	var result struct {
		mp.Error
		UserInfo
	}

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

	if result.ErrCode != mp.ErrCodeOK {
		err = &result.Error
		return
	}
	info = &result.UserInfo
	return
}