1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package service
-
- import (
- "encoding/json"
- "errors"
-
- "gitee.com/yansen_zh/wechat-oplatform-sdk/api"
- "gitee.com/yansen_zh/wechat-oplatform-sdk/entities"
- "gitee.com/yansen_zh/wechat-oplatform-sdk/utils/request"
- )
-
- // PushTicketParam 启动票据推送服务参数
- type PushTicketParam struct {
- ComponentAppId string `json:"component_appid"`
- ComponentSecret string `json:"component_secret"`
- }
-
- // PushTicketResult 启动票据推送服务参数
- type PushTicketResult struct {
- entities.Error
- }
-
- // StartPushTicket 启动 ticket 推送服务
- func StartPushTicket(param PushTicketParam) (*PushTicketResult, error) {
- if param.ComponentAppId == "" {
- return nil, errors.New("启动 ticket 推送服务 第三方平台的 appid 不能为空")
- }
-
- if param.ComponentSecret == "" {
- return nil, errors.New("启动 ticket 推送服务 第三方平台的 appsecret 不能为空")
- }
-
- data, e1 := json.Marshal(param)
- if e1 != nil {
- return nil, e1
- }
-
- resp, e2 := request.PostJSON(api.StartPushTicket, data)
- if e2 != nil {
- return nil, e2
- }
-
- result := PushTicketResult{}
- if err := json.Unmarshal(resp, &result); err != nil {
- return nil, err
- }
-
- if result.Code != 0 {
- return &result, result.Error
- }
-
- return &result, nil
- }
|