-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 小程序发货信息管理 * fix golang lint * fix miss * fix lint * fix lint * fix lint * 修复查询参数last_index=“”时异常 * 小程序消息推送 * fix lint errors * fix lint * fix lint * fix lint, * 简化写法 * fix 简化写法 * fix name in comments * Update miniprogram.go * add events * change GoodsInfo type * change statements to 50 * 追加xml支持 * fix cl lint * 追加动态消息 * 删除多余空格 * 修复命名 * 修复createActivityId返回值类型
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package message | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/silenceper/wechat/v2/miniprogram/context" | ||
"github.com/silenceper/wechat/v2/util" | ||
) | ||
|
||
const ( | ||
// createActivityURL 创建activity_id | ||
createActivityURL = "https://api.weixin.qq.com/cgi-bin/message/wxopen/activityid/create?access_token=%s" | ||
// SendUpdatableMsgURL 修改动态消息 | ||
setUpdatableMsgURL = "https://api.weixin.qq.com/cgi-bin/message/wxopen/updatablemsg/send?access_token=%s" | ||
) | ||
|
||
// UpdatableTargetState 动态消息状态 | ||
type UpdatableTargetState int | ||
|
||
const ( | ||
// TargetStateNotStarted 未开始 | ||
TargetStateNotStarted UpdatableTargetState = 0 | ||
// TargetStateStarted 已开始 | ||
TargetStateStarted UpdatableTargetState = 1 | ||
// TargetStateFinished 已结束 | ||
TargetStateFinished UpdatableTargetState = 2 | ||
) | ||
|
||
// UpdatableMessage 动态消息 | ||
type UpdatableMessage struct { | ||
*context.Context | ||
} | ||
|
||
// NewUpdatableMessage 实例化 | ||
func NewUpdatableMessage(ctx *context.Context) *UpdatableMessage { | ||
return &UpdatableMessage{ | ||
Context: ctx, | ||
} | ||
} | ||
|
||
// CreateActivityID 创建activity_id | ||
func (updatableMessage *UpdatableMessage) CreateActivityID() (res CreateActivityIDResponse, err error) { | ||
accessToken, err := updatableMessage.GetAccessToken() | ||
if err != nil { | ||
return | ||
} | ||
|
||
uri := fmt.Sprintf(createActivityURL, accessToken) | ||
response, err := util.HTTPGet(uri) | ||
if err != nil { | ||
return | ||
} | ||
err = util.DecodeWithError(response, &res, "CreateActivityID") | ||
return | ||
} | ||
|
||
// SetUpdatableMsg 修改动态消息 | ||
func (updatableMessage *UpdatableMessage) SetUpdatableMsg(activityID string, targetState UpdatableTargetState, template UpdatableMsgTemplate) (err error) { | ||
accessToken, err := updatableMessage.GetAccessToken() | ||
if err != nil { | ||
return | ||
} | ||
|
||
uri := fmt.Sprintf(setUpdatableMsgURL, accessToken) | ||
data := SendUpdatableMsgReq{ | ||
ActivityID: activityID, | ||
TargetState: targetState, | ||
TemplateInfo: template, | ||
} | ||
|
||
response, err := util.PostJSON(uri, data) | ||
if err != nil { | ||
return | ||
} | ||
return util.DecodeWithCommonError(response, "SendUpdatableMsg") | ||
} | ||
|
||
// CreateActivityIDResponse 创建activity_id 返回 | ||
type CreateActivityIDResponse struct { | ||
util.CommonError | ||
|
||
ActivityID string `json:"activity_id"` | ||
ExpirationTime int64 `json:"expiration_time"` | ||
} | ||
|
||
// UpdatableMsgTemplate 动态消息模板 | ||
type UpdatableMsgTemplate struct { | ||
ParameterList []UpdatableMsgParameter `json:"parameter_list"` | ||
} | ||
|
||
// UpdatableMsgParameter 动态消息参数 | ||
type UpdatableMsgParameter struct { | ||
Name string `json:"name"` | ||
Value string `json:"value"` | ||
} | ||
|
||
// SendUpdatableMsgReq 修改动态消息参数 | ||
type SendUpdatableMsgReq struct { | ||
ActivityID string `json:"activity_id"` | ||
TemplateInfo UpdatableMsgTemplate `json:"template_info"` | ||
TargetState UpdatableTargetState `json:"target_state"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters