mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39dbfd1c13 | ||
|
|
5ad3475cdb | ||
|
|
bcc41989ed | ||
|
|
e189b87e71 |
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
@@ -2,9 +2,9 @@ name: Go
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master,release-* ]
|
branches: [ master,release-*,v2 ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master,release-* ]
|
branches: [ master,release-*,v2 ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
golangci:
|
golangci:
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ const (
|
|||||||
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getTemplateList.html
|
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getTemplateList.html
|
||||||
getTemplateURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
getTemplateURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
||||||
|
|
||||||
|
// 添加订阅模板
|
||||||
|
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.addTemplate.html
|
||||||
|
addTemplateURL = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate"
|
||||||
|
|
||||||
|
// 删除私有模板
|
||||||
|
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.deleteTemplate.html
|
||||||
|
delTemplateURL = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate"
|
||||||
|
|
||||||
// 统一服务消息
|
// 统一服务消息
|
||||||
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/uniform-message/uniformMessage.send.html
|
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/uniform-message/uniformMessage.send.html
|
||||||
uniformMessageSend = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send"
|
uniformMessageSend = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send"
|
||||||
@@ -133,3 +141,55 @@ func (s *Subscribe) UniformSend(msg *UniformMessage) (err error) {
|
|||||||
}
|
}
|
||||||
return util.DecodeWithCommonError(response, "UniformSend")
|
return util.DecodeWithCommonError(response, "UniformSend")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type resSubscribeAdd struct {
|
||||||
|
util.CommonError
|
||||||
|
|
||||||
|
TemplateID string `json:"priTmplId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add 添加订阅消息模板
|
||||||
|
func (s *Subscribe) Add(ShortID string, kidList []int, sceneDesc string) (templateID string, err error) {
|
||||||
|
var accessToken string
|
||||||
|
accessToken, err = s.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var msg = struct {
|
||||||
|
TemplateIDShort string `json:"tid"`
|
||||||
|
SceneDesc string `json:"sceneDesc"`
|
||||||
|
KidList []int `json:"kidList"`
|
||||||
|
}{TemplateIDShort: ShortID, SceneDesc: sceneDesc, KidList: kidList}
|
||||||
|
uri := fmt.Sprintf("%s?access_token=%s", addTemplateURL, accessToken)
|
||||||
|
var response []byte
|
||||||
|
response, err = util.PostJSON(uri, msg)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var result resSubscribeAdd
|
||||||
|
err = util.DecodeWithError(response, &result, "AddSubscribe")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
templateID = result.TemplateID
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete 删除私有模板
|
||||||
|
func (s *Subscribe) Delete(templateID string) (err error) {
|
||||||
|
var accessToken string
|
||||||
|
accessToken, err = s.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var msg = struct {
|
||||||
|
TemplateID string `json:"priTmplId"`
|
||||||
|
}{TemplateID: templateID}
|
||||||
|
uri := fmt.Sprintf("%s?access_token=%s", delTemplateURL, accessToken)
|
||||||
|
var response []byte
|
||||||
|
response, err = util.PostJSON(uri, msg)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return util.DecodeWithCommonError(response, "DeleteSubscribe")
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend"
|
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend"
|
||||||
subscribeTemplateListURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
subscribeTemplateListURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
||||||
|
subscribeTemplateAddURL = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate"
|
||||||
|
subscribeTemplateDelURL = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Subscribe 订阅消息
|
//Subscribe 订阅消息
|
||||||
@@ -84,10 +86,62 @@ func (tpl *Subscribe) List() (templateList []*PrivateSubscribeItem, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var res resPrivateSubscribeList
|
var res resPrivateSubscribeList
|
||||||
err = util.DecodeWithError(response, &res, "ListSubscription")
|
err = util.DecodeWithError(response, &res, "ListSubscribe")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
templateList = res.SubscriptionList
|
templateList = res.SubscriptionList
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type resSubscribeAdd struct {
|
||||||
|
util.CommonError
|
||||||
|
|
||||||
|
TemplateID string `json:"priTmplId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add 添加订阅消息模板
|
||||||
|
func (tpl *Subscribe) Add(ShortID string, kidList []int, sceneDesc string) (templateID string, err error) {
|
||||||
|
var accessToken string
|
||||||
|
accessToken, err = tpl.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var msg = struct {
|
||||||
|
TemplateIDShort string `json:"tid"`
|
||||||
|
SceneDesc string `json:"sceneDesc"`
|
||||||
|
KidList []int `json:"kidList"`
|
||||||
|
}{TemplateIDShort: ShortID, SceneDesc: sceneDesc, KidList: kidList}
|
||||||
|
uri := fmt.Sprintf("%s?access_token=%s", subscribeTemplateAddURL, accessToken)
|
||||||
|
var response []byte
|
||||||
|
response, err = util.PostJSON(uri, msg)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var result resSubscribeAdd
|
||||||
|
err = util.DecodeWithError(response, &result, "AddSubscribe")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
templateID = result.TemplateID
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete 删除私有模板
|
||||||
|
func (tpl *Subscribe) Delete(templateID string) (err error) {
|
||||||
|
var accessToken string
|
||||||
|
accessToken, err = tpl.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var msg = struct {
|
||||||
|
TemplateID string `json:"priTmplId"`
|
||||||
|
}{TemplateID: templateID}
|
||||||
|
uri := fmt.Sprintf("%s?access_token=%s", subscribeTemplateDelURL, accessToken)
|
||||||
|
var response []byte
|
||||||
|
response, err = util.PostJSON(uri, msg)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return util.DecodeWithCommonError(response, "DeleteSubscribe")
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ type RefundedReqInfo struct {
|
|||||||
SettlementRefundFee *int `xml:"settlement_refund_fee"`
|
SettlementRefundFee *int `xml:"settlement_refund_fee"`
|
||||||
RefundStatus *string `xml:"refund_status"`
|
RefundStatus *string `xml:"refund_status"`
|
||||||
SuccessTime *string `xml:"success_time"`
|
SuccessTime *string `xml:"success_time"`
|
||||||
RefundRecvAccount *string `xml:"refund_recv_account"`
|
RefundRecvAccount *string `xml:"refund_recv_accout"`
|
||||||
RefundAccount *string `xml:"refund_account"`
|
RefundAccount *string `xml:"refund_account"`
|
||||||
RefundRequestSource *string `xml:"refund_request_source"`
|
RefundRequestSource *string `xml:"refund_request_source"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,14 @@ const (
|
|||||||
SDKApiFreqOutOfLimit Error = "接口请求次数超频"
|
SDKApiFreqOutOfLimit Error = "接口请求次数超频"
|
||||||
// SDKApiForbidden 错误码:48002
|
// SDKApiForbidden 错误码:48002
|
||||||
SDKApiForbidden Error = "API 禁止调用"
|
SDKApiForbidden Error = "API 禁止调用"
|
||||||
|
// SDKInvalidOpenKFID 错误码:95000
|
||||||
|
SDKInvalidOpenKFID Error = "无效的 open_kfid"
|
||||||
// SDKOpenKFIDNotExist 错误码:95004
|
// SDKOpenKFIDNotExist 错误码:95004
|
||||||
SDKOpenKFIDNotExist Error = "open_kfid 不存在"
|
SDKOpenKFIDNotExist Error = "open_kfid 不存在"
|
||||||
// SDKWeWorkAlready 错误码:95011
|
// SDKWeWorkAlready 错误码:95011
|
||||||
SDKWeWorkAlready Error = "已在企业微信使用微信客服"
|
SDKWeWorkAlready Error = "已在企业微信使用微信客服"
|
||||||
|
// SDKApiNotOpen 错误码:95017
|
||||||
|
SDKApiNotOpen Error = "API 功能没有被开启"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Error 输出错误信息
|
//Error 输出错误信息
|
||||||
@@ -69,10 +73,14 @@ func NewSDKErr(code int64, msgList ...string) Error {
|
|||||||
return SDKApiFreqOutOfLimit
|
return SDKApiFreqOutOfLimit
|
||||||
case 48002:
|
case 48002:
|
||||||
return SDKApiForbidden
|
return SDKApiForbidden
|
||||||
|
case 95000:
|
||||||
|
return SDKInvalidOpenKFID
|
||||||
case 95004:
|
case 95004:
|
||||||
return SDKOpenKFIDNotExist
|
return SDKOpenKFIDNotExist
|
||||||
case 95011:
|
case 95011:
|
||||||
return SDKWeWorkAlready
|
return SDKWeWorkAlready
|
||||||
|
case 95017:
|
||||||
|
return SDKApiNotOpen
|
||||||
default:
|
default:
|
||||||
//返回未知的自定义错误
|
//返回未知的自定义错误
|
||||||
if len(msgList) > 0 {
|
if len(msgList) > 0 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// +build !linux
|
// +build !linux linux,!cgo
|
||||||
|
|
||||||
//Package msgaudit for unsupport platform
|
//Package msgaudit for unsupport platform
|
||||||
package msgaudit
|
package msgaudit
|
||||||
@@ -15,5 +15,5 @@ type Client struct {
|
|||||||
|
|
||||||
// NewClient new
|
// NewClient new
|
||||||
func NewClient(cfg *config.Config) (*Client, error) {
|
func NewClient(cfg *config.Config) (*Client, error) {
|
||||||
return nil, fmt.Errorf("会话存档功能目前只支持Linux平台运行")
|
return nil, fmt.Errorf("会话存档功能目前只支持Linux平台运行,并且打开设置CGO_ENABLED=1")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user