當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.PostJSON方法代碼示例

本文整理匯總了Golang中github.com/chanxuehong/wechat/v2/mp/core.Client.PostJSON方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.PostJSON方法的具體用法?Golang Client.PostJSON怎麽用?Golang Client.PostJSON使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/chanxuehong/wechat/v2/mp/core.Client的用法示例。


在下文中一共展示了Client.PostJSON方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例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: 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

示例4: Get

func Get(clt *core.Client, shopId int64) (homepage *Homepage, err error) {
	request := struct {
		ShopId int64 `json:"shop_id"`
	}{
		ShopId: shopId,
	}

	var result struct {
		core.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 != core.ErrCodeOK {
		err = &result.Error
		return
	}

	homepage = &result.Homepage
	return
}
開發者ID:btbxbob,項目名稱:wechat,代碼行數:25,代碼來源:get.go

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: UploadVideo2

// UploadVideo2 創建視頻素材, 返回的素材一般用於群發消息.
//  mediaId:     通過 UploadVideo 上傳視頻文件得到
//  title:       標題, 可以為空
//  description: 描述, 可以為空
func UploadVideo2(clt *core.Client, mediaId, title, description string) (info *MediaInfo, err error) {
	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token="

	var request = struct {
		MediaId     string `json:"media_id"`
		Title       string `json:"title,omitempty"`
		Description string `json:"description,omitempty"`
	}{
		MediaId:     mediaId,
		Title:       title,
		Description: description,
	}
	var result struct {
		core.Error
		MediaInfo
	}
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result.Error
		return
	}
	info = &result.MediaInfo
	return
}
開發者ID:btbxbob,項目名稱:wechat,代碼行數:30,代碼來源:mpvideo.go

示例11: DeviceList

// 批量查詢設備統計數據接口
func DeviceList(clt *core.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 {
		core.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 != core.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
}
開發者ID:xiaomuqiao,項目名稱:wechat.v2,代碼行數:33,代碼來源:devicelist.go

示例12: Update

// Update 設置客服信息(增量更新, 不更新的可以留空).
//  account:         完整客服賬號,格式為:賬號前綴@公眾號微信號
//  nickname:        客服昵稱,最長6個漢字或12個英文字符
//  password:        客服賬號登錄密碼
//  isPasswordPlain: 標識 password 是否為明文格式, true 表示是明文密碼, false 表示是密文密碼.
func Update(clt *core.Client, account, nickname, password string, isPasswordPlain bool) (err error) {
	const incompleteURL = "https://api.weixin.qq.com/customservice/kfaccount/update?access_token="

	if isPasswordPlain && 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 core.Error
	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
		return
	}
	if result.ErrCode != core.ErrCodeOK {
		err = &result
		return
	}
	return
}
開發者ID:btbxbob,項目名稱:wechat,代碼行數:32,代碼來源:account.go

示例13: ModifyStock

// 庫存修改接口.
// cardId:      卡券ID
// increaseNum: 增加庫存數量, 可以為負數
func ModifyStock(clt *core.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 core.Error

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

	if result.ErrCode != core.ErrCodeOK {
		err = &result
		return
	}
	return
}
開發者ID:btbxbob,項目名稱:wechat,代碼行數:33,代碼來源:card.go

示例14: 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

示例15: 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


注:本文中的github.com/chanxuehong/wechat/v2/mp/core.Client.PostJSON方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。