mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
53
.golangci.yml
Normal file
53
.golangci.yml
Normal file
@@ -0,0 +1,53 @@
|
||||
linters:
|
||||
# please, do not use `enable-all`: it's deprecated and will be removed soon.
|
||||
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
|
||||
disable-all: true
|
||||
enable:
|
||||
- bodyclose
|
||||
- deadcode
|
||||
- depguard
|
||||
- dogsled
|
||||
- dupl
|
||||
- errcheck
|
||||
- funlen
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
- gofmt
|
||||
- goimports
|
||||
- golint
|
||||
- goprintffuncname
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- interfacer
|
||||
- misspell
|
||||
- nolintlint
|
||||
- rowserrcheck
|
||||
- scopelint
|
||||
- staticcheck
|
||||
- structcheck
|
||||
- stylecheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- varcheck
|
||||
- whitespace
|
||||
|
||||
issues:
|
||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||
exclude-rules:
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- gomnd
|
||||
|
||||
# https://github.com/go-critic/go-critic/issues/926
|
||||
- linters:
|
||||
- gocritic
|
||||
text: "unnecessaryDefer:"
|
||||
|
||||
linters-settings:
|
||||
funlen:
|
||||
lines: 66
|
||||
statements: 40
|
||||
6
cache/memory.go
vendored
6
cache/memory.go
vendored
@@ -62,13 +62,13 @@ func (mem *Memory) Set(key string, val interface{}, timeout time.Duration) (err
|
||||
|
||||
//Delete delete value in memcache.
|
||||
func (mem *Memory) Delete(key string) error {
|
||||
return mem.deleteKey(key)
|
||||
mem.deleteKey(key)
|
||||
return nil
|
||||
}
|
||||
|
||||
// deleteKey
|
||||
func (mem *Memory) deleteKey(key string) error {
|
||||
func (mem *Memory) deleteKey(key string) {
|
||||
mem.Lock()
|
||||
defer mem.Unlock()
|
||||
delete(mem.data, key)
|
||||
return nil
|
||||
}
|
||||
|
||||
5
cache/redis.go
vendored
5
cache/redis.go
vendored
@@ -95,10 +95,7 @@ func (r *Redis) IsExist(key string) bool {
|
||||
|
||||
a, _ := conn.Do("EXISTS", key)
|
||||
i := a.(int64)
|
||||
if i > 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return i > 0
|
||||
}
|
||||
|
||||
//Delete 删除
|
||||
|
||||
@@ -68,6 +68,9 @@ func GetTicketFromServer(accessToken string) (ticket ResTicket, err error) {
|
||||
var response []byte
|
||||
url := fmt.Sprintf(getTicketURL, accessToken)
|
||||
response, err = util.HTTPGet(url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(response, &ticket)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -22,7 +22,6 @@ func NewEncryptor(context *context.Context) *Encryptor {
|
||||
return basic
|
||||
}
|
||||
|
||||
|
||||
var (
|
||||
// ErrAppIDNotMatch appid不匹配
|
||||
ErrAppIDNotMatch = errors.New("app id not match")
|
||||
@@ -36,19 +35,19 @@ var (
|
||||
|
||||
// PlainData 用户信息/手机号信息
|
||||
type PlainData struct {
|
||||
OpenID string `json:"openId"`
|
||||
UnionID string `json:"unionId"`
|
||||
NickName string `json:"nickName"`
|
||||
Gender int `json:"gender"`
|
||||
City string `json:"city"`
|
||||
Province string `json:"province"`
|
||||
Country string `json:"country"`
|
||||
AvatarURL string `json:"avatarUrl"`
|
||||
Language string `json:"language"`
|
||||
OpenID string `json:"openId"`
|
||||
UnionID string `json:"unionId"`
|
||||
NickName string `json:"nickName"`
|
||||
Gender int `json:"gender"`
|
||||
City string `json:"city"`
|
||||
Province string `json:"province"`
|
||||
Country string `json:"country"`
|
||||
AvatarURL string `json:"avatarUrl"`
|
||||
Language string `json:"language"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
PurePhoneNumber string `json:"purePhoneNumber"`
|
||||
CountryCode string `json:"countryCode"`
|
||||
Watermark struct {
|
||||
Watermark struct {
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
AppID string `json:"appid"`
|
||||
} `json:"watermark"`
|
||||
|
||||
@@ -74,15 +74,13 @@ func (qrCode *QRCode) fetchCode(urlStr string, body interface{}) (response []byt
|
||||
err = fmt.Errorf("fetchCode error : errcode=%v , errmsg=%v", result.ErrCode, result.ErrMsg)
|
||||
return nil, err
|
||||
}
|
||||
} else if contentType == "image/jpeg" {
|
||||
}
|
||||
if contentType == "image/jpeg" {
|
||||
// 返回文件
|
||||
return response, nil
|
||||
} else {
|
||||
err = fmt.Errorf("fetchCode error : unknown response content type - %v", contentType)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
err = fmt.Errorf("fetchCode error : unknown response content type - %v", contentType)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// CreateWXAQRCode 获取小程序二维码,适用于需要的码数量较少的业务场景
|
||||
|
||||
@@ -47,6 +47,8 @@ func (s *Subscribe) Send(msg *Message) (err error) {
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", subscribeSendURL, accessToken)
|
||||
response, err := util.PostJSON(uri, msg)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "Send")
|
||||
}
|
||||
|
||||
@@ -130,5 +130,5 @@ func (tcb *Tcb) BatchDeleteFile(env string, fileIDList []string) (*BatchDeleteFi
|
||||
}
|
||||
batchDeleteFileRes := &BatchDeleteFileRes{}
|
||||
err = util.DecodeWithError(response, batchDeleteFileRes, "BatchDeleteFile")
|
||||
return batchDeleteFileRes, nil
|
||||
return batchDeleteFileRes, err
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
sendURLByTag = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall"
|
||||
sendURLByTag = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall"
|
||||
sendURLByOpenID = "https://api.weixin.qq.com/cgi-bin/message/mass/send"
|
||||
deleteSendURL ="https://api.weixin.qq.com/cgi-bin/message/mass/delete"
|
||||
deleteSendURL = "https://api.weixin.qq.com/cgi-bin/message/mass/delete"
|
||||
)
|
||||
|
||||
//MsgType 发送消息类型
|
||||
@@ -69,17 +69,17 @@ type sendRequest struct {
|
||||
//发送图片
|
||||
Images *Image `json:"images,omitempty"`
|
||||
//发送卡券
|
||||
WxCard map[string]interface{} `json:"wxcard,omitempty"`
|
||||
MsgType MsgType `json:"msgtype"`
|
||||
SendIgnoreReprint int32 `json:"send_ignore_reprint,omitempty"`
|
||||
WxCard map[string]interface{} `json:"wxcard,omitempty"`
|
||||
MsgType MsgType `json:"msgtype"`
|
||||
SendIgnoreReprint int32 `json:"send_ignore_reprint,omitempty"`
|
||||
}
|
||||
|
||||
//Image 发送图片
|
||||
type Image struct{
|
||||
MediaIDs []string `json:"media_ids"`
|
||||
Recommend string `json:"recommend"`
|
||||
NeedOpenComment int32 `json:"need_open_comment"`
|
||||
OnlyFansCanComment int32 `json:"only_fans_can_comment"`
|
||||
type Image struct {
|
||||
MediaIDs []string `json:"media_ids"`
|
||||
Recommend string `json:"recommend"`
|
||||
NeedOpenComment int32 `json:"need_open_comment"`
|
||||
OnlyFansCanComment int32 `json:"only_fans_can_comment"`
|
||||
}
|
||||
|
||||
//SendText 群发文本
|
||||
@@ -92,13 +92,13 @@ func (broadcast *Broadcast) SendText(user *User, content string) (*Result, error
|
||||
return nil, err
|
||||
}
|
||||
req := &sendRequest{
|
||||
ToUser: nil,
|
||||
ToUser: nil,
|
||||
MsgType: MsgTypeText,
|
||||
}
|
||||
req.Text=map[string]interface{}{
|
||||
"content":content,
|
||||
req.Text = map[string]interface{}{
|
||||
"content": content,
|
||||
}
|
||||
req,sendURL:=broadcast.chooseTagOrOpenID(user,req)
|
||||
req, sendURL := broadcast.chooseTagOrOpenID(user, req)
|
||||
url := fmt.Sprintf("%s?access_token=%s", sendURL, ak)
|
||||
data, err := util.PostJSON(url, req)
|
||||
if err != nil {
|
||||
@@ -110,22 +110,22 @@ func (broadcast *Broadcast) SendText(user *User, content string) (*Result, error
|
||||
}
|
||||
|
||||
//SendNews 发送图文
|
||||
func (broadcast *Broadcast) SendNews(user *User, mediaID string,ignoreReprint bool) (*Result, error) {
|
||||
func (broadcast *Broadcast) SendNews(user *User, mediaID string, ignoreReprint bool) (*Result, error) {
|
||||
ak, err := broadcast.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := &sendRequest{
|
||||
ToUser: nil,
|
||||
ToUser: nil,
|
||||
MsgType: MsgTypeNews,
|
||||
}
|
||||
if ignoreReprint{
|
||||
req.SendIgnoreReprint=1
|
||||
if ignoreReprint {
|
||||
req.SendIgnoreReprint = 1
|
||||
}
|
||||
req.Mpnews=map[string]interface{}{
|
||||
"media_id":mediaID,
|
||||
req.Mpnews = map[string]interface{}{
|
||||
"media_id": mediaID,
|
||||
}
|
||||
req,sendURL:=broadcast.chooseTagOrOpenID(user,req)
|
||||
req, sendURL := broadcast.chooseTagOrOpenID(user, req)
|
||||
url := fmt.Sprintf("%s?access_token=%s", sendURL, ak)
|
||||
data, err := util.PostJSON(url, req)
|
||||
if err != nil {
|
||||
@@ -136,7 +136,6 @@ func (broadcast *Broadcast) SendNews(user *User, mediaID string,ignoreReprint bo
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
//SendVoice 发送语音
|
||||
func (broadcast *Broadcast) SendVoice(user *User, mediaID string) (*Result, error) {
|
||||
ak, err := broadcast.GetAccessToken()
|
||||
@@ -144,13 +143,13 @@ func (broadcast *Broadcast) SendVoice(user *User, mediaID string) (*Result, erro
|
||||
return nil, err
|
||||
}
|
||||
req := &sendRequest{
|
||||
ToUser: nil,
|
||||
ToUser: nil,
|
||||
MsgType: MsgTypeVoice,
|
||||
}
|
||||
req.Voice=map[string]interface{}{
|
||||
"media_id":mediaID,
|
||||
req.Voice = map[string]interface{}{
|
||||
"media_id": mediaID,
|
||||
}
|
||||
req,sendURL:=broadcast.chooseTagOrOpenID(user,req)
|
||||
req, sendURL := broadcast.chooseTagOrOpenID(user, req)
|
||||
url := fmt.Sprintf("%s?access_token=%s", sendURL, ak)
|
||||
data, err := util.PostJSON(url, req)
|
||||
if err != nil {
|
||||
@@ -168,11 +167,11 @@ func (broadcast *Broadcast) SendImage(user *User, images *Image) (*Result, error
|
||||
return nil, err
|
||||
}
|
||||
req := &sendRequest{
|
||||
ToUser: nil,
|
||||
ToUser: nil,
|
||||
MsgType: MsgTypeImage,
|
||||
}
|
||||
req.Images=images
|
||||
req,sendURL:=broadcast.chooseTagOrOpenID(user,req)
|
||||
req.Images = images
|
||||
req, sendURL := broadcast.chooseTagOrOpenID(user, req)
|
||||
url := fmt.Sprintf("%s?access_token=%s", sendURL, ak)
|
||||
data, err := util.PostJSON(url, req)
|
||||
if err != nil {
|
||||
@@ -183,23 +182,22 @@ func (broadcast *Broadcast) SendImage(user *User, images *Image) (*Result, error
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
//SendVideo 发送视频
|
||||
func (broadcast *Broadcast) SendVideo(user *User, mediaID string,title,description string) (*Result, error) {
|
||||
func (broadcast *Broadcast) SendVideo(user *User, mediaID string, title, description string) (*Result, error) {
|
||||
ak, err := broadcast.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := &sendRequest{
|
||||
ToUser: nil,
|
||||
ToUser: nil,
|
||||
MsgType: MsgTypeVideo,
|
||||
}
|
||||
req.Voice=map[string]interface{}{
|
||||
"media_id":mediaID,
|
||||
"title":title,
|
||||
"description":description,
|
||||
req.Voice = map[string]interface{}{
|
||||
"media_id": mediaID,
|
||||
"title": title,
|
||||
"description": description,
|
||||
}
|
||||
req,sendURL:=broadcast.chooseTagOrOpenID(user,req)
|
||||
req, sendURL := broadcast.chooseTagOrOpenID(user, req)
|
||||
url := fmt.Sprintf("%s?access_token=%s", sendURL, ak)
|
||||
data, err := util.PostJSON(url, req)
|
||||
if err != nil {
|
||||
@@ -210,7 +208,6 @@ func (broadcast *Broadcast) SendVideo(user *User, mediaID string,title,descripti
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
//SendWxCard 发送卡券
|
||||
func (broadcast *Broadcast) SendWxCard(user *User, cardID string) (*Result, error) {
|
||||
ak, err := broadcast.GetAccessToken()
|
||||
@@ -218,13 +215,13 @@ func (broadcast *Broadcast) SendWxCard(user *User, cardID string) (*Result, erro
|
||||
return nil, err
|
||||
}
|
||||
req := &sendRequest{
|
||||
ToUser: nil,
|
||||
ToUser: nil,
|
||||
MsgType: MsgTypeWxCard,
|
||||
}
|
||||
req.WxCard=map[string]interface{}{
|
||||
"card_id":cardID,
|
||||
req.WxCard = map[string]interface{}{
|
||||
"card_id": cardID,
|
||||
}
|
||||
req,sendURL:=broadcast.chooseTagOrOpenID(user,req)
|
||||
req, sendURL := broadcast.chooseTagOrOpenID(user, req)
|
||||
url := fmt.Sprintf("%s?access_token=%s", sendURL, ak)
|
||||
data, err := util.PostJSON(url, req)
|
||||
if err != nil {
|
||||
@@ -234,11 +231,12 @@ func (broadcast *Broadcast) SendWxCard(user *User, cardID string) (*Result, erro
|
||||
err = util.DecodeWithError(data, res, "SendWxCard")
|
||||
return res, err
|
||||
}
|
||||
|
||||
//Delete 删除群发消息
|
||||
func (broadcast *Broadcast) Delete(msgID int64 ,articleIDx int64) error {
|
||||
func (broadcast *Broadcast) Delete(msgID int64, articleIDx int64) error {
|
||||
ak, err := broadcast.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
return err
|
||||
}
|
||||
req := map[string]interface{}{
|
||||
"msg_id": msgID,
|
||||
@@ -247,33 +245,32 @@ func (broadcast *Broadcast) Delete(msgID int64 ,articleIDx int64) error {
|
||||
url := fmt.Sprintf("%s?access_token=%s", deleteSendURL, ak)
|
||||
data, err := util.PostJSON(url, req)
|
||||
if err != nil {
|
||||
return err
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(data, "Delete")
|
||||
}
|
||||
|
||||
|
||||
//TODO 发送预览,群发消息状态,发送速度
|
||||
|
||||
func (broadcast *Broadcast) chooseTagOrOpenID(user *User,req *sendRequest)(ret *sendRequest,url string){
|
||||
sendURL:=""
|
||||
func (broadcast *Broadcast) chooseTagOrOpenID(user *User, req *sendRequest) (ret *sendRequest, url string) {
|
||||
sendURL := ""
|
||||
if user == nil {
|
||||
req.Filter=map[string]interface{}{
|
||||
"is_to_all":true,
|
||||
req.Filter = map[string]interface{}{
|
||||
"is_to_all": true,
|
||||
}
|
||||
sendURL=sendURLByTag
|
||||
sendURL = sendURLByTag
|
||||
} else {
|
||||
if user.TagID != 0 {
|
||||
req.Filter=map[string]interface{}{
|
||||
"is_to_all":false,
|
||||
"tag_id":user.TagID,
|
||||
req.Filter = map[string]interface{}{
|
||||
"is_to_all": false,
|
||||
"tag_id": user.TagID,
|
||||
}
|
||||
sendURL=sendURLByTag
|
||||
sendURL = sendURLByTag
|
||||
}
|
||||
if len(user.OpenID) != 0 {
|
||||
req.ToUser = user.OpenID
|
||||
sendURL=sendURLByOpenID
|
||||
sendURL = sendURLByOpenID
|
||||
}
|
||||
}
|
||||
return req,sendURL
|
||||
}
|
||||
return req, sendURL
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package datacube
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package datacube
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package datacube
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package datacube
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
//AdSlot 广告位类型
|
||||
@@ -55,9 +55,8 @@ type BaseResp struct {
|
||||
//ResPublisherAdPos 公众号分广告位数据响应
|
||||
type ResPublisherAdPos struct {
|
||||
util.CommonError
|
||||
BaseResp
|
||||
|
||||
Base BaseResp `json:"base_resp"`
|
||||
BaseResp BaseResp `json:"base_resp"`
|
||||
List []ResAdPosList `json:"list"`
|
||||
Summary ResAdPosSummary `json:"summary"`
|
||||
TotalNum int `json:"total_num"`
|
||||
@@ -91,9 +90,8 @@ type ResAdPosSummary struct {
|
||||
//ResPublisherCps 公众号返佣商品数据响应
|
||||
type ResPublisherCps struct {
|
||||
util.CommonError
|
||||
BaseResp
|
||||
|
||||
Base BaseResp `json:"base_resp"`
|
||||
BaseResp BaseResp `json:"base_resp"`
|
||||
List []ResCpsList `json:"list"`
|
||||
Summary ResCpsSummary `json:"summary"`
|
||||
TotalNum int `json:"total_num"`
|
||||
@@ -125,9 +123,8 @@ type ResCpsSummary struct {
|
||||
//ResPublisherSettlement 公众号结算收入数据及结算主体信息响应
|
||||
type ResPublisherSettlement struct {
|
||||
util.CommonError
|
||||
BaseResp
|
||||
|
||||
Base BaseResp `json:"base_resp"`
|
||||
BaseResp BaseResp `json:"base_resp"`
|
||||
Body string `json:"body"`
|
||||
PenaltyAll int `json:"penalty_all"`
|
||||
RevenueAll int64 `json:"revenue_all"`
|
||||
@@ -208,25 +205,15 @@ func (cube *DataCube) GetPublisherAdPosGeneral(startDate, endDate string, page,
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(response, &resPublisherAdPos)
|
||||
err = util.DecodeWithError(response, &resPublisherAdPos, "GetPublisherAdPosGeneral")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if resPublisherAdPos.CommonError.ErrCode != 0 {
|
||||
err = fmt.Errorf("GetPublisherAdPosGeneral Error , errcode=%d , errmsg=%s", resPublisherAdPos.CommonError.ErrCode, resPublisherAdPos.CommonError.ErrMsg)
|
||||
return
|
||||
}
|
||||
|
||||
if resPublisherAdPos.BaseResp.Ret != 0 {
|
||||
err = fmt.Errorf("GetPublisherAdPosGeneral Error , errcode=%d , errmsg=%s", resPublisherAdPos.BaseResp.Ret, resPublisherAdPos.BaseResp.ErrMsg)
|
||||
return
|
||||
}
|
||||
|
||||
if resPublisherAdPos.Base.Ret != 0 {
|
||||
err = fmt.Errorf("GetPublisherAdPosGeneral Error , errcode=%d , errmsg=%s", resPublisherAdPos.Base.Ret, resPublisherAdPos.Base.ErrMsg)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -245,26 +232,15 @@ func (cube *DataCube) GetPublisherCpsGeneral(startDate, endDate string, page, pa
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(response, &resPublisherCps)
|
||||
err = util.DecodeWithError(response, &resPublisherCps, "GetPublisherCpsGeneral")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if resPublisherCps.CommonError.ErrCode != 0 {
|
||||
err = fmt.Errorf("GetPublisherCpsGeneral Error , errcode=%d , errmsg=%s", resPublisherCps.CommonError.ErrCode, resPublisherCps.CommonError.ErrMsg)
|
||||
return
|
||||
}
|
||||
|
||||
if resPublisherCps.BaseResp.Ret != 0 {
|
||||
err = fmt.Errorf("GetPublisherCpsGeneral Error , errcode=%d , errmsg=%s", resPublisherCps.BaseResp.Ret, resPublisherCps.BaseResp.ErrMsg)
|
||||
return
|
||||
}
|
||||
|
||||
if resPublisherCps.Base.Ret != 0 {
|
||||
err = fmt.Errorf("GetPublisherCpsGeneral Error , errcode=%d , errmsg=%s", resPublisherCps.Base.Ret, resPublisherCps.Base.ErrMsg)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -283,24 +259,14 @@ func (cube *DataCube) GetPublisherSettlement(startDate, endDate string, page, pa
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(response, &resPublisherSettlement)
|
||||
err = util.DecodeWithError(response, &resPublisherSettlement, "GetPublisherSettlement")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if resPublisherSettlement.CommonError.ErrCode != 0 {
|
||||
err = fmt.Errorf("GetPublisherSettlement Error , errcode=%d , errmsg=%s", resPublisherSettlement.CommonError.ErrCode, resPublisherSettlement.CommonError.ErrMsg)
|
||||
return
|
||||
}
|
||||
|
||||
if resPublisherSettlement.BaseResp.Ret != 0 {
|
||||
err = fmt.Errorf("GetPublisherSettlement Error , errcode=%d , errmsg=%s", resPublisherSettlement.BaseResp.Ret, resPublisherSettlement.BaseResp.ErrMsg)
|
||||
return
|
||||
}
|
||||
|
||||
if resPublisherSettlement.Base.Ret != 0 {
|
||||
err = fmt.Errorf("GetPublisherSettlement Error , errcode=%d , errmsg=%s", resPublisherSettlement.Base.Ret, resPublisherSettlement.Base.ErrMsg)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package datacube
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ type ReqDevice struct {
|
||||
// ble – 3
|
||||
// wifi -- 4
|
||||
// 一个设备可以支持多种连接类型,用符号"|"做分割,客户端优先选择靠前的连接方式(优先级按|关系的排序依次降低),举例:
|
||||
// 1:表示设备仅支持andiod classic bluetooth 1|2:表示设备支持andiod 和ios 两种classic bluetooth,但是客户端优先选择andriod classic bluetooth 协议,如果andriod classic bluetooth协议连接失败,再选择ios classic bluetooth协议进行连接
|
||||
// 1:表示设备仅支持andiod classic bluetooth 1|2:表示设备支持android 和ios 两种classic bluetooth,但是客户端优先选择android classic bluetooth 协议,如果android classic bluetooth协议连接失败,再选择ios classic bluetooth协议进行连接
|
||||
// (注:安卓平台不同时支持BLE和classic类型)
|
||||
ConnectProtocol string `json:"connect_protocol"`
|
||||
//auth及通信的加密key,第三方需要将key烧制在设备上(128bit),格式采用16进制串的方式(长度为32字节),不需要0X前缀,如: 1234567890ABCDEF1234567890ABCDEF
|
||||
@@ -56,7 +56,7 @@ type ReqDevice struct {
|
||||
// 0:不加密的version
|
||||
// 1:version 1
|
||||
AuthVer string `json:"auth_ver"`
|
||||
// 表示mac地址在厂商广播manufature data里含有mac地址的偏移,取值如下:
|
||||
// 表示mac地址在厂商广播manufacture data里含有mac地址的偏移,取值如下:
|
||||
// -1:在尾部、
|
||||
// -2:表示不包含mac地址 其他:非法偏移
|
||||
ManuMacPos string `json:"manu_mac_pos"`
|
||||
|
||||
@@ -52,7 +52,7 @@ func (js *Js) GetConfig(uri string) (config *Config, err error) {
|
||||
}
|
||||
|
||||
nonceStr := util.RandomStr(16)
|
||||
timestamp := util.GetCurrTs()
|
||||
timestamp := util.GetCurrTS()
|
||||
str := fmt.Sprintf("jsapi_ticket=%s&noncestr=%s×tamp=%d&url=%s", ticketStr, nonceStr, timestamp, uri)
|
||||
sigStr := util.Signature(str)
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
addNewsURL = "https://api.weixin.qq.com/cgi-bin/material/add_news"
|
||||
addMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/add_material"
|
||||
delMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/del_material"
|
||||
getMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/get_material"
|
||||
addNewsURL = "https://api.weixin.qq.com/cgi-bin/material/add_news"
|
||||
addMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/add_material"
|
||||
delMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/del_material"
|
||||
getMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/get_material"
|
||||
batchGetMaterialURL = "https://api.weixin.qq.com/cgi-bin/material/batchget_material"
|
||||
)
|
||||
|
||||
@@ -30,6 +30,7 @@ const (
|
||||
//PermanentMaterialTypeNews 永久素材图文类型(news)
|
||||
PermanentMaterialTypeNews PermanentMaterialType = "news"
|
||||
)
|
||||
|
||||
//Material 素材管理
|
||||
type Material struct {
|
||||
*context.Context
|
||||
|
||||
@@ -106,5 +106,4 @@ func (material *Material) ImageUpload(filename string) (url string, err error) {
|
||||
}
|
||||
url = image.URL
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
@@ -102,12 +102,12 @@ type ButtonNew struct {
|
||||
|
||||
//MatchRule 个性化菜单规则
|
||||
type MatchRule struct {
|
||||
GroupID string `json:"group_id,omitempty"`
|
||||
Sex string `json:"sex,omitempty"`
|
||||
GroupID string `json:"group_id,omitempty"`
|
||||
Sex string `json:"sex,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
Province string `json:"province,omitempty"`
|
||||
City string `json:"city,omitempty"`
|
||||
ClientPlatformType string `json:"client_platform_type,omitempty"`
|
||||
ClientPlatformType string `json:"client_platform_type,omitempty"`
|
||||
Language string `json:"language,omitempty"`
|
||||
}
|
||||
|
||||
@@ -138,7 +138,6 @@ func (menu *Menu) SetMenu(buttons []*Button) error {
|
||||
return util.DecodeWithCommonError(response, "SetMenu")
|
||||
}
|
||||
|
||||
|
||||
//SetMenuByJSON 设置按钮
|
||||
func (menu *Menu) SetMenuByJSON(jsonInfo string) error {
|
||||
accessToken, err := menu.GetAccessToken()
|
||||
@@ -216,7 +215,6 @@ func (menu *Menu) AddConditional(buttons []*Button, matchRule *MatchRule) error
|
||||
return util.DecodeWithCommonError(response, "AddConditional")
|
||||
}
|
||||
|
||||
|
||||
//AddConditionalByJSON 添加个性化菜单
|
||||
func (menu *Menu) AddConditionalByJSON(jsonInfo string) error {
|
||||
accessToken, err := menu.GetAccessToken()
|
||||
|
||||
@@ -147,6 +147,9 @@ func (manager *Manager) Send(msg *CustomerMessage) error {
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", customerSendMessage, accessToken)
|
||||
response, err := util.PostJSON(uri, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var result util.CommonError
|
||||
err = json.Unmarshal(response, &result)
|
||||
if err != nil {
|
||||
|
||||
@@ -59,7 +59,9 @@ func (tpl *Template) Send(msg *TemplateMessage) (msgID int64, err error) {
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", templateSendURL, accessToken)
|
||||
response, err := util.PostJSON(uri, msg)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var result resTemplateSend
|
||||
err = json.Unmarshal(response, &result)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,11 +13,11 @@ type TransInfo struct {
|
||||
}
|
||||
|
||||
//NewTransferCustomer 实例化
|
||||
func NewTransferCustomer(KfAccount string) *TransferCustomer {
|
||||
func NewTransferCustomer(kfAccount string) *TransferCustomer {
|
||||
tc := new(TransferCustomer)
|
||||
if KfAccount != "" {
|
||||
if kfAccount != "" {
|
||||
transInfo := new(TransInfo)
|
||||
transInfo.KfAccount = KfAccount
|
||||
transInfo.KfAccount = kfAccount
|
||||
tc.TransInfo = transInfo
|
||||
}
|
||||
return tc
|
||||
|
||||
@@ -50,7 +50,7 @@ func (oauth *Oauth) Redirect(writer http.ResponseWriter, req *http.Request, redi
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
http.Redirect(writer, req, location, 302)
|
||||
http.Redirect(writer, req, location, http.StatusFound)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package officialaccount
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/v2/officialaccount/datacube"
|
||||
"net/http"
|
||||
|
||||
"github.com/silenceper/wechat/v2/officialaccount/datacube"
|
||||
|
||||
"github.com/silenceper/wechat/v2/credential"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/basic"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/broadcast"
|
||||
|
||||
@@ -199,7 +199,7 @@ func (srv *Server) buildResponse(reply *message.Reply) (err error) {
|
||||
value := reflect.ValueOf(msgData)
|
||||
//msgData must be a ptr
|
||||
kind := value.Kind().String()
|
||||
if "ptr" != kind {
|
||||
if kind != "ptr" {
|
||||
return message.ErrUnsupportReply
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ func (srv *Server) buildResponse(reply *message.Reply) (err error) {
|
||||
params[0] = reflect.ValueOf(msgType)
|
||||
value.MethodByName("SetMsgType").Call(params)
|
||||
|
||||
params[0] = reflect.ValueOf(util.GetCurrTs())
|
||||
params[0] = reflect.ValueOf(util.GetCurrTS())
|
||||
value.MethodByName("SetCreateTime").Call(params)
|
||||
|
||||
srv.ResponseMsg = msgData
|
||||
|
||||
@@ -15,9 +15,9 @@ const (
|
||||
refreshTokenURL = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%s"
|
||||
getComponentInfoURL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%s"
|
||||
//TODO 获取授权方选项信息
|
||||
getComponentConfigURL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option?component_access_token=%s"
|
||||
//getComponentConfigURL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option?component_access_token=%s"
|
||||
//TODO 获取已授权的账号信息
|
||||
getuthorizerListURL = "POST https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list?component_access_token=%s"
|
||||
//getuthorizerListURL = "POST https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list?component_access_token=%s"
|
||||
)
|
||||
|
||||
// ComponentAccessToken 第三方平台
|
||||
|
||||
@@ -12,7 +12,6 @@ type OfficialAccount struct {
|
||||
//授权的公众号的appID
|
||||
appID string
|
||||
*officialaccount.OfficialAccount
|
||||
opContext *opContext.Context
|
||||
}
|
||||
|
||||
//NewOfficialAccount 实例化
|
||||
|
||||
@@ -65,7 +65,7 @@ func AESEncryptMsg(random, rawXMLMsg []byte, appID string, aesKey []byte) (ciphe
|
||||
}
|
||||
|
||||
// 加密
|
||||
block, err := aes.NewCipher(aesKey[:])
|
||||
block, err := aes.NewCipher(aesKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ func Signature(params ...string) string {
|
||||
sort.Strings(params)
|
||||
h := sha1.New()
|
||||
for _, s := range params {
|
||||
io.WriteString(h, s)
|
||||
_, _ = io.WriteString(h, s)
|
||||
}
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package util
|
||||
import "time"
|
||||
|
||||
//GetCurrTs return current timestamps
|
||||
func GetCurrTs() int64 {
|
||||
func GetCurrTS() int64 {
|
||||
return time.Now().Unix()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user