当前位置: 首页>>代码示例>>Golang>>正文


Golang core.Client类代码示例

本文整理汇总了Golang中github.com/chanxuehong/wechat/v2/mp/core.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: uploadFromReader

func uploadFromReader(clt *core.Client, mediaType, filename string, reader io.Reader) (info *MediaInfo, err error) {
	var incompleteURL = "https://api.weixin.qq.com/cgi-bin/media/upload?type=" + mediaType + "&access_token="

	var fields = []core.MultipartFormField{
		{
			IsFile:   true,
			Name:     "media",
			FileName: filename,
			Value:    reader,
		},
	}
	var result struct {
		core.Error
		MediaInfo
	}
	if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	info = &result.MediaInfo
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:25,代码来源:upload.go

示例2: Create

// 卡券投放, 创建二维码接口.
func Create(clt *core.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 {
		core.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 != core.ErrCodeOK {
		err = &result.Error
		return
	}
	info = &result.QrcodeInfo
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:31,代码来源:create.go

示例3: UploadThumbFromReader

// UploadThumbFromReader 上传多媒体缩略图.
//  NOTE: 参数 filename 不是文件路径, 是 multipart/form-data 里面 filename 的值.
func UploadThumbFromReader(clt *core.Client, filename string, reader io.Reader) (info *MediaInfo, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/media/upload?type=thumb&access_token="

	var fields = []core.MultipartFormField{
		{
			IsFile:   true,
			Name:     "media",
			FileName: filename,
			Value:    reader,
		},
	}
	var result struct {
		core.Error
		MediaType string `json:"type"`
		MediaId   string `json:"thumb_media_id"`
		CreatedAt int64  `json:"created_at"`
	}
	if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	info = &MediaInfo{
		MediaType: result.MediaType,
		MediaId:   result.MediaId,
		CreatedAt: result.CreatedAt,
	}
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:33,代码来源:upload.go

示例4: GetCardList

// 获取用户已领取卡券接口
//  openid: 需要查询的用户openid
//  cardid: 卡券ID。不填写时默认查询当前appid下的卡券。
func GetCardList(clt *core.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 {
		core.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 != core.ErrCodeOK {
		err = &result.Error
		return
	}
	list = result.CardList
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:29,代码来源:getcardlist.go

示例5: addFromReader

func addFromReader(clt *core.Client, filename string, reader io.Reader, _type string) (info ImageInfo, err error) {
	var result struct {
		core.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 := []core.MultipartFormField{{
		IsFile:   true,
		Name:     "media",
		FileName: filename,
		Value:    reader,
	}}
	if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
		return
	}

	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	info = result.ImageInfo
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:30,代码来源:add.go

示例6: Create

// Create 创建分组.
func Create(clt *core.Client, name string) (group *Group, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token="

	var request struct {
		Group struct {
			Name string `json:"name"`
		} `json:"group"`
	}
	request.Group.Name = name

	var result struct {
		core.Error
		Group `json:"group"`
	}
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	result.Group.UserCount = 0
	group = &result.Group
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:26,代码来源:group.go

示例7: UploadImageFromReader

// UploadImageFromReader 上传图片到微信服务器, 返回的图片url给其他场景使用, 比如图文消息, 卡卷, POI.
//  NOTE: 参数 filename 不是文件路径, 是 multipart/form-data 里面 filename 的值.
func UploadImageFromReader(clt *core.Client, filename string, reader io.Reader) (url string, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token="

	var fields = []core.MultipartFormField{
		{
			IsFile:   true,
			Name:     "media",
			FileName: filename,
			Value:    reader,
		},
	}
	var result struct {
		core.Error
		URL string `json:"url"`
	}
	if err = clt.PostMultipartForm(incompleteURL, fields, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	url = result.URL
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:27,代码来源:uploadimg.go

示例8: Page

// 以页面为维度的数据统计接口
func Page(clt *core.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 {
		core.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 != core.ErrCodeOK {
		err = &result.Error
		return
	}
	data = result.Data
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:29,代码来源:page.go

示例9: Device

// 以设备为维度的数据统计接口
func Device(clt *core.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 {
		core.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 != core.ErrCodeOK {
		err = &result.Error
		return
	}
	data = result.Data
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:29,代码来源:device.go

示例10: BatchGetNews

// 获取图文素材列表.
//  offset: 从全部素材的该偏移位置开始返回, 0表示从第一个素材
//  count:  返回素材的数量, 取值在1到20之间
func BatchGetNews(clt *core.Client, offset, count int) (rslt *BatchGetNewsResult, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token="

	if offset < 0 {
		err = fmt.Errorf("Incorrect offset: %d", offset)
		return
	}
	if count <= 0 {
		err = fmt.Errorf("Incorrect count: %d", count)
		return
	}

	var request = struct {
		MaterialType string `json:"type"`
		Offset       int    `json:"offset"`
		Count        int    `json:"count"`
	}{
		MaterialType: MaterialTypeNews,
		Offset:       offset,
		Count:        count,
	}
	var result struct {
		core.Error
		BatchGetNewsResult
	}
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	rslt = &result.BatchGetNewsResult
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:38,代码来源:news.go

示例11: List

// 数据统计
//  shopId     按门店ID搜索,-1为总统计
//  beginDate: 起始日期时间,格式yyyy-mm-dd,最长时间跨度为30天
//  endDate:   结束日期时间戳,格式yyyy-mm-dd,最长时间跨度为30天
func List(clt *core.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 {
		core.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 != core.ErrCodeOK {
		err = &result.Error
		return
	}

	data = result.Data
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:33,代码来源:list.go

示例12: GetShakeInfo

// 获取摇周边的设备及用户信息
//  ticket:  摇周边业务的ticket,可在摇到的URL中得到,ticket生效时间为30分钟,每一次摇都会重新生成新的ticket
//  needPoi: 是否需要返回门店poi_id
func GetShakeInfo(clt *core.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 {
		core.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 != core.ErrCodeOK {
		err = &result.Error
		return
	}
	info = &result.Shakeinfo
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:32,代码来源:getshakeinfo.go

示例13: Get

// Get 获取客服聊天记录
func Get(clt *core.Client, request *GetRequest) (list []Record, err error) {
	const incompleteURL = "https://api.weixin.qq.com/customservice/msgrecord/getrecord?access_token="

	if request.PageIndex < 1 {
		err = fmt.Errorf("Incorrect request.PageIndex: %d", request.PageIndex)
		return
	}
	if request.PageSize <= 0 {
		err = fmt.Errorf("Incorrect request.PageSize: %d", request.PageSize)
		return
	}

	var result struct {
		core.Error
		RecordList []Record `json:"recordlist"`
	}
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	list = result.RecordList
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:27,代码来源:record.go

示例14: CreateStrScenePermQrcode

// CreateStrScenePermQrcode 创建永久二维码
//  sceneStr: 场景值ID(字符串形式的ID), 字符串类型, 长度限制为1到64
func CreateStrScenePermQrcode(clt *core.Client, sceneStr string) (qrcode *PermQrcode, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="

	var request struct {
		ActionName string `json:"action_name"`
		ActionInfo struct {
			Scene struct {
				SceneStr string `json:"scene_str"`
			} `json:"scene"`
		} `json:"action_info"`
	}
	request.ActionName = "QR_LIMIT_STR_SCENE"
	request.ActionInfo.Scene.SceneStr = sceneStr

	var result struct {
		core.Error
		PermQrcode
	}
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	qrcode = &result.PermQrcode
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:30,代码来源:create.go

示例15: CreateTempQrcode

// CreateTempQrcode 创建临时二维码.
//  sceneId:       场景值ID, 为32位非0整型
//  expireSeconds: 二维码有效时间, 以秒为单位
func CreateTempQrcode(clt *core.Client, sceneId int32, expireSeconds int) (qrcode *TempQrcode, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="

	var request struct {
		ExpireSeconds int    `json:"expire_seconds"`
		ActionName    string `json:"action_name"`
		ActionInfo    struct {
			Scene struct {
				SceneId int32 `json:"scene_id"`
			} `json:"scene"`
		} `json:"action_info"`
	}
	request.ExpireSeconds = expireSeconds
	request.ActionName = "QR_SCENE"
	request.ActionInfo.Scene.SceneId = sceneId

	var result struct {
		core.Error
		TempQrcode
	}
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	qrcode = &result.TempQrcode
	return
}
开发者ID:btbxbob,项目名称:wechat,代码行数:33,代码来源:create.go


注:本文中的github.com/chanxuehong/wechat/v2/mp/core.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。