From c458f449176e3ef0e2b6eee527816562b7162eea Mon Sep 17 00:00:00 2001 From: sunyaqiu Date: Tue, 6 Aug 2019 15:14:10 +0800 Subject: [PATCH 01/36] Add member card field --- message/message.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/message/message.go b/message/message.go index dbb23a5..366bfe8 100644 --- a/message/message.go +++ b/message/message.go @@ -133,6 +133,17 @@ type MixMessage struct { AuthorizationCode string `xml:"AuthorizationCode"` AuthorizationCodeExpiredTime int64 `xml:"AuthorizationCodeExpiredTime"` PreAuthCode string `xml:"PreAuthCode"` + + // 卡券相关 + CardID string `xml:"CardId"` + RefuseReason string `xml:"RefuseReason"` + IsGiveByFriend int32 `xml:"IsGiveByFriend"` + FriendUserName string `xml:"FriendUserName"` + UserCardCode string `xml:"UserCardCode"` + OldUserCardCode string `xml:"OldUserCardCode"` + OuterStr string `xml:"OuterStr"` + IsRestoreMemberCard int32 `xml:"IsRestoreMemberCard"` + UnionID string `xml:"UnionId"` } //EventPic 发图事件推送 From f8ab59260693c25d9caeb0a7ea892826fcc2e4a3 Mon Sep 17 00:00:00 2001 From: WhisperRain <2516435583@qq.com> Date: Tue, 1 Oct 2019 20:11:57 +0800 Subject: [PATCH 02/36] add(customer message)Add module to send customer message --- message/customer_message.go | 160 ++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 message/customer_message.go diff --git a/message/customer_message.go b/message/customer_message.go new file mode 100644 index 0000000..e697d13 --- /dev/null +++ b/message/customer_message.go @@ -0,0 +1,160 @@ +package message + +import ( + "encoding/json" + "fmt" + "github.com/silenceper/wechat/util" + "github.com/silenceper/wechat/context" +) + +const ( + customerSendMessage = "https://api.weixin.qq.com/cgi-bin/message/custom/send" +) + +//Manager 消息管理者,可以发送消息 +type Manager struct { + *context.Context +} + +//NewMessageManager 实例化消息管理者 +func NewMessageManager(context *context.Context) *Manager { + return &Manager{ + context, + } +} + +//CustomerMessage 客服消息 +type CustomerMessage struct { + ToUser string `json:"touser"` //接受者OpenID + Msgtype MsgType `json:"msgtype"` //客服消息类型 + Text *MediaText `json:"text,omitempty"` //可选 + Image *MediaResource `json:"image,omitempty"` //可选 + Voice *MediaResource `json:"voice,omitempty"` //可选 + Video *MediaVideo `json:"video,omitempty"` //可选 + Music *MediaMusic `json:"music,omitempty"` //可选 + News *MediaNews `json:"news,omitempty"` //可选 + Mpnews *MediaResource `json:"mpnews,omitempty"` //可选 + Wxcard *MediaWxcard `json:"wxcard,omitempty"` //可选 + Msgmenu *MediaMsgmenu `json:"msgmenu,omitempty"` //可选 + Miniprogrampage *MediaMiniprogrampage `json:"miniprogrampage,omitempty"` //可选 +} + +//NewCustomerTextMessage 文本消息结构体构造方法 +func NewCustomerTextMessage(toUser, text string) *CustomerMessage { + return &CustomerMessage{ + ToUser: toUser, + Msgtype: MsgTypeText, + Text: &MediaText{ + text, + }, + } +} + +//NewCustomerImgMessage 图片消息的构造方法 +func NewCustomerImgMessage(toUser, mediaID string) *CustomerMessage { + return &CustomerMessage{ + ToUser: toUser, + Msgtype: MsgTypeImage, + Image: &MediaResource{ + mediaID, + }, + } +} + +//NewCustomerVoiceMessage 语音消息的构造方法 +func NewCustomerVoiceMessage(toUser, mediaID string) *CustomerMessage { + return &CustomerMessage{ + ToUser: toUser, + Msgtype: MsgTypeVoice, + Voice: &MediaResource{ + mediaID, + }, + } +} + +//MediaText 文本消息的文字 +type MediaText struct { + Content string `json:"content"` +} + +//MediaResource 消息使用的永久素材id +type MediaResource struct { + MediaID string `json:"media_id"` +} + +//MediaVideo 视频消息包含的内容 +type MediaVideo struct { + MediaID string `json:"media_id"` + ThumbMediaID string `json:"thumb_media_id"` + Title string `json:"title"` + Description string `json:"description"` +} + +//MediaMusic 音乐消息包括的内容 +type MediaMusic struct { + Title string `json:"title"` + Description string `json:"description"` + Musicurl string `json:"musicurl"` + Hqmusicurl string `json:"hqmusicurl"` + ThumbMediaID string `json:"thumb_media_id"` +} + +//MediaNews 图文消息的内容 +type MediaNews struct { + Articles []MediaArticles `json:"articles"` +} + +//MediaArticles 图文消息的内容的文章列表中的单独一条 +type MediaArticles struct { + Title string `json:"title"` + Description string `json:"description"` + URL string `json:"url"` + Picurl string `json:"picurl"` +} + +//MediaMsgmenu 菜单消息的内容 +type MediaMsgmenu struct { + HeadContent string `json:"head_content"` + List []MsgmenuItem `json:"list"` + TailContent string `json:"tail_content"` +} + +//MsgmenuItem 菜单消息的菜单按钮 +type MsgmenuItem struct { + ID string `json:"id"` + Content string `json:"content"` +} + +//MediaWxcard 卡券的id +type MediaWxcard struct { + CardID string `json:"card_id"` +} + +//MediaMiniprogrampage 小程序消息 +type MediaMiniprogrampage struct { + Title string `json:"title"` + Appid string `json:"appid"` + Pagepath string `json:"pagepath"` + ThumbMediaID string `json:"thumb_media_id"` +} + +//Send 发送客服消息 +func (manager *Manager) Send(msg *CustomerMessage) error { + accessToken,err:=manager.Context.GetAccessToken() + if err!=nil { + return err + } + uri := fmt.Sprintf("%s?access_token=%s", customerSendMessage, accessToken) + response, err := util.PostJSON(uri, msg) + var result util.CommonError + err = json.Unmarshal(response, &result) + if err != nil { + return err + } + if result.ErrCode != 0 { + err = fmt.Errorf("customer msg send error : errcode=%v , errmsg=%v", result.ErrCode, result.ErrMsg) + return err + } + + return nil +} From 54e2c82fff17fd7dfbd1a5fade54bacaef0caabe Mon Sep 17 00:00:00 2001 From: cielu Date: Sat, 12 Oct 2019 16:03:39 +0800 Subject: [PATCH 03/36] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A7=A3=E5=AF=86=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E8=A7=A3=E5=AF=86=EF=BC=8C=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=9A=84=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=A7=A3=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/decrypt.go | 43 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/miniprogram/decrypt.go b/miniprogram/decrypt.go index 6897368..fce7775 100644 --- a/miniprogram/decrypt.go +++ b/miniprogram/decrypt.go @@ -36,6 +36,17 @@ type UserInfo struct { } `json:"watermark"` } +// 用户手机号 +type PhoneInfo struct { + PhoneNumber string `json:"phoneNumber"` + PurePhoneNumber string `json:"purePhoneNumber"` + CountryCode string `json:"countryCode"` + Watermark struct { + Timestamp int64 `json:"timestamp"` + AppID string `json:"appid"` + } `json:"watermark"` +} + // pkcs7Unpad returns slice of the original data without padding func pkcs7Unpad(data []byte, blockSize int) ([]byte, error) { if blockSize <= 0 { @@ -57,8 +68,8 @@ func pkcs7Unpad(data []byte, blockSize int) ([]byte, error) { return data[:len(data)-n], nil } -// Decrypt 解密数据 -func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo, error) { +// get cipherText +func getCipherText(sessionKey, encryptedData, iv string) ([]byte, error) { aesKey, err := base64.StdEncoding.DecodeString(sessionKey) if err != nil { return nil, err @@ -81,6 +92,16 @@ func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo if err != nil { return nil, err } + return cipherText, err +} + +// Decrypt 解密(用户)数据 +func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo, error) { + // 拿到 cipherText + cipherText,err := getCipherText(sessionKey, encryptedData, iv) + if err != nil { + return nil, err + } var userInfo UserInfo err = json.Unmarshal(cipherText, &userInfo) if err != nil { @@ -91,3 +112,21 @@ func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo } return &userInfo, nil } + +// Decrypt 解密(手机)数据 +func (wxa *MiniProgram) DecryptPhone(sessionKey, encryptedData, iv string) (*PhoneInfo, error) { + // 拿到 cipherText + cipherText,err := getCipherText(sessionKey, encryptedData, iv) + if err != nil { + return nil, err + } + var phoneInfo PhoneInfo + err = json.Unmarshal(cipherText, &phoneInfo) + if err != nil { + return nil, err + } + if phoneInfo.Watermark.AppID != wxa.AppID { + return nil, ErrAppIDNotMatch + } + return &phoneInfo, nil +} From bb97bddc08c0cfd9ca7d28c86e11949bc98225d2 Mon Sep 17 00:00:00 2001 From: ciel yu Date: Sat, 12 Oct 2019 16:27:55 +0800 Subject: [PATCH 04/36] =?UTF-8?q?Revert=20"=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A7=A3=E5=AF=86=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E8=A7=A3=E5=AF=86=EF=BC=8C=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E4=B9=8B=E5=89=8D=E7=9A=84=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E8=A7=A3=E5=AF=86"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 54e2c82f --- miniprogram/decrypt.go | 43 ++---------------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/miniprogram/decrypt.go b/miniprogram/decrypt.go index fce7775..6897368 100644 --- a/miniprogram/decrypt.go +++ b/miniprogram/decrypt.go @@ -36,17 +36,6 @@ type UserInfo struct { } `json:"watermark"` } -// 用户手机号 -type PhoneInfo struct { - PhoneNumber string `json:"phoneNumber"` - PurePhoneNumber string `json:"purePhoneNumber"` - CountryCode string `json:"countryCode"` - Watermark struct { - Timestamp int64 `json:"timestamp"` - AppID string `json:"appid"` - } `json:"watermark"` -} - // pkcs7Unpad returns slice of the original data without padding func pkcs7Unpad(data []byte, blockSize int) ([]byte, error) { if blockSize <= 0 { @@ -68,8 +57,8 @@ func pkcs7Unpad(data []byte, blockSize int) ([]byte, error) { return data[:len(data)-n], nil } -// get cipherText -func getCipherText(sessionKey, encryptedData, iv string) ([]byte, error) { +// Decrypt 解密数据 +func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo, error) { aesKey, err := base64.StdEncoding.DecodeString(sessionKey) if err != nil { return nil, err @@ -92,16 +81,6 @@ func getCipherText(sessionKey, encryptedData, iv string) ([]byte, error) { if err != nil { return nil, err } - return cipherText, err -} - -// Decrypt 解密(用户)数据 -func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo, error) { - // 拿到 cipherText - cipherText,err := getCipherText(sessionKey, encryptedData, iv) - if err != nil { - return nil, err - } var userInfo UserInfo err = json.Unmarshal(cipherText, &userInfo) if err != nil { @@ -112,21 +91,3 @@ func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo } return &userInfo, nil } - -// Decrypt 解密(手机)数据 -func (wxa *MiniProgram) DecryptPhone(sessionKey, encryptedData, iv string) (*PhoneInfo, error) { - // 拿到 cipherText - cipherText,err := getCipherText(sessionKey, encryptedData, iv) - if err != nil { - return nil, err - } - var phoneInfo PhoneInfo - err = json.Unmarshal(cipherText, &phoneInfo) - if err != nil { - return nil, err - } - if phoneInfo.Watermark.AppID != wxa.AppID { - return nil, ErrAppIDNotMatch - } - return &phoneInfo, nil -} From 453089e83e315fcf0943cfcccf68a471e3d19d3b Mon Sep 17 00:00:00 2001 From: ciel yu Date: Sat, 12 Oct 2019 16:41:26 +0800 Subject: [PATCH 05/36] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A7=A3=E5=AF=86=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E8=A7=A3=E5=AF=86=EF=BC=8C=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=9A=84=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=A7=A3=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/decrypt.go | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/miniprogram/decrypt.go b/miniprogram/decrypt.go index 6897368..bcf6a94 100644 --- a/miniprogram/decrypt.go +++ b/miniprogram/decrypt.go @@ -36,6 +36,17 @@ type UserInfo struct { } `json:"watermark"` } +// 用户手机号 +type PhoneInfo struct { + PhoneNumber string `json:"phoneNumber"` + PurePhoneNumber string `json:"purePhoneNumber"` + CountryCode string `json:"countryCode"` + Watermark struct { + Timestamp int64 `json:"timestamp"` + AppID string `json:"appid"` + } `json:"watermark"` +} + // pkcs7Unpad returns slice of the original data without padding func pkcs7Unpad(data []byte, blockSize int) ([]byte, error) { if blockSize <= 0 { @@ -57,8 +68,8 @@ func pkcs7Unpad(data []byte, blockSize int) ([]byte, error) { return data[:len(data)-n], nil } -// Decrypt 解密数据 -func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo, error) { +// get cipherText +func getCipherText(sessionKey, encryptedData, iv string) ([]byte, error) { aesKey, err := base64.StdEncoding.DecodeString(sessionKey) if err != nil { return nil, err @@ -81,6 +92,15 @@ func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo if err != nil { return nil, err } + return cipherText, nil +} + +// Decrypt 解密数据(用户) +func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo, error) { + cipherText, err := getCipherText(sessionKey, encryptedData, iv) + if err != nil { + return nil, err + } var userInfo UserInfo err = json.Unmarshal(cipherText, &userInfo) if err != nil { @@ -91,3 +111,20 @@ func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo } return &userInfo, nil } + +// DecryptPhone 解密数据(手机) +func (wxa *MiniProgram) DecryptPHone(sessionKey, encryptedData, iv string) (*PhoneInfo, error) { + cipherText, err := getCipherText(sessionKey, encryptedData, iv) + if err != nil { + return nil, err + } + var phoneInfo PhoneInfo + err = json.Unmarshal(cipherText, &phoneInfo) + if err != nil { + return nil, err + } + if phoneInfo.Watermark.AppID != wxa.AppID { + return nil, ErrAppIDNotMatch + } + return &phoneInfo, nil +} From 4e6fd625da22495d077a7f77bef8c61c274646ca Mon Sep 17 00:00:00 2001 From: ciel yu Date: Sat, 12 Oct 2019 16:46:59 +0800 Subject: [PATCH 06/36] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A7=A3=E5=AF=86=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E8=A7=A3=E5=AF=86=EF=BC=8C=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=9A=84=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=A7=A3=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/decrypt.go | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/miniprogram/decrypt.go b/miniprogram/decrypt.go index bcf6a94..87a4202 100644 --- a/miniprogram/decrypt.go +++ b/miniprogram/decrypt.go @@ -47,27 +47,6 @@ type PhoneInfo struct { } `json:"watermark"` } -// pkcs7Unpad returns slice of the original data without padding -func pkcs7Unpad(data []byte, blockSize int) ([]byte, error) { - if blockSize <= 0 { - return nil, ErrInvalidBlockSize - } - if len(data)%blockSize != 0 || len(data) == 0 { - return nil, ErrInvalidPKCS7Data - } - c := data[len(data)-1] - n := int(c) - if n == 0 || n > len(data) { - return nil, ErrInvalidPKCS7Padding - } - for i := 0; i < n; i++ { - if data[len(data)-n+i] != c { - return nil, ErrInvalidPKCS7Padding - } - } - return data[:len(data)-n], nil -} - // get cipherText func getCipherText(sessionKey, encryptedData, iv string) ([]byte, error) { aesKey, err := base64.StdEncoding.DecodeString(sessionKey) @@ -95,7 +74,28 @@ func getCipherText(sessionKey, encryptedData, iv string) ([]byte, error) { return cipherText, nil } -// Decrypt 解密数据(用户) +// pkcs7Unpad returns slice of the original data without padding +func pkcs7Unpad(data []byte, blockSize int) ([]byte, error) { + if blockSize <= 0 { + return nil, ErrInvalidBlockSize + } + if len(data)%blockSize != 0 || len(data) == 0 { + return nil, ErrInvalidPKCS7Data + } + c := data[len(data)-1] + n := int(c) + if n == 0 || n > len(data) { + return nil, ErrInvalidPKCS7Padding + } + for i := 0; i < n; i++ { + if data[len(data)-n+i] != c { + return nil, ErrInvalidPKCS7Padding + } + } + return data[:len(data)-n], nil +} + +// Decrypt 解密数据 func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo, error) { cipherText, err := getCipherText(sessionKey, encryptedData, iv) if err != nil { @@ -113,7 +113,7 @@ func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo } // DecryptPhone 解密数据(手机) -func (wxa *MiniProgram) DecryptPHone(sessionKey, encryptedData, iv string) (*PhoneInfo, error) { +func (wxa *MiniProgram) DecryptPhone(sessionKey, encryptedData, iv string) (*PhoneInfo, error) { cipherText, err := getCipherText(sessionKey, encryptedData, iv) if err != nil { return nil, err From 0dffcde4759ec76bb60e7e6e8733a83c08a7f119 Mon Sep 17 00:00:00 2001 From: ciel yu Date: Sat, 12 Oct 2019 17:38:41 +0800 Subject: [PATCH 07/36] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A7=A3=E5=AF=86=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E8=A7=A3=E5=AF=86=EF=BC=8C=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=9A=84=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=A7=A3=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/decrypt.go | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/miniprogram/decrypt.go b/miniprogram/decrypt.go index 87a4202..d904b3c 100644 --- a/miniprogram/decrypt.go +++ b/miniprogram/decrypt.go @@ -36,7 +36,7 @@ type UserInfo struct { } `json:"watermark"` } -// 用户手机号 +// PhoneInfo 用户手机号 type PhoneInfo struct { PhoneNumber string `json:"phoneNumber"` PurePhoneNumber string `json:"purePhoneNumber"` @@ -47,7 +47,28 @@ type PhoneInfo struct { } `json:"watermark"` } -// get cipherText +// pkcs7Unpad returns slice of the original data without padding +func pkcs7Unpad(data []byte, blockSize int) ([]byte, error) { + if blockSize <= 0 { + return nil, ErrInvalidBlockSize + } + if len(data)%blockSize != 0 || len(data) == 0 { + return nil, ErrInvalidPKCS7Data + } + c := data[len(data)-1] + n := int(c) + if n == 0 || n > len(data) { + return nil, ErrInvalidPKCS7Padding + } + for i := 0; i < n; i++ { + if data[len(data)-n+i] != c { + return nil, ErrInvalidPKCS7Padding + } + } + return data[:len(data)-n], nil +} + +// getCipherText returns slice of the cipher text func getCipherText(sessionKey, encryptedData, iv string) ([]byte, error) { aesKey, err := base64.StdEncoding.DecodeString(sessionKey) if err != nil { @@ -74,27 +95,6 @@ func getCipherText(sessionKey, encryptedData, iv string) ([]byte, error) { return cipherText, nil } -// pkcs7Unpad returns slice of the original data without padding -func pkcs7Unpad(data []byte, blockSize int) ([]byte, error) { - if blockSize <= 0 { - return nil, ErrInvalidBlockSize - } - if len(data)%blockSize != 0 || len(data) == 0 { - return nil, ErrInvalidPKCS7Data - } - c := data[len(data)-1] - n := int(c) - if n == 0 || n > len(data) { - return nil, ErrInvalidPKCS7Padding - } - for i := 0; i < n; i++ { - if data[len(data)-n+i] != c { - return nil, ErrInvalidPKCS7Padding - } - } - return data[:len(data)-n], nil -} - // Decrypt 解密数据 func (wxa *MiniProgram) Decrypt(sessionKey, encryptedData, iv string) (*UserInfo, error) { cipherText, err := getCipherText(sessionKey, encryptedData, iv) From abd7f512baa7df6e229d042f65163023157af13e Mon Sep 17 00:00:00 2001 From: ciel yu Date: Mon, 14 Oct 2019 18:33:50 +0800 Subject: [PATCH 08/36] =?UTF-8?q?=E6=94=AF=E4=BB=98=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20BridgeConfig=20=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8F=AF=E8=8E=B7?= =?UTF-8?q?=E5=BE=97=20prepay=20ID=EF=BC=8C=E5=8F=8Ajs=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=97=B6=E6=89=80=E9=9C=80=E8=A6=81=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pay/pay.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/pay/pay.go b/pay/pay.go index 1afa094..1e43514 100644 --- a/pay/pay.go +++ b/pay/pay.go @@ -2,10 +2,17 @@ package pay import ( "bytes" + "crypto/hmac" + "crypto/md5" + "crypto/sha256" + "encoding/hex" "encoding/xml" "errors" + "hash" "sort" "strconv" + "strings" + "time" "github.com/silenceper/wechat/context" "github.com/silenceper/wechat/util" @@ -27,15 +34,17 @@ type Params struct { OutTradeNo string OpenID string TradeType string + SignType string } -// Config 是传出用于 jsdk 用的参数 +// Config 是传出用于 js sdk 用的参数 type Config struct { - Timestamp int64 - NonceStr string - PrePayID string - SignType string - Sign string + Timestamp string `json:"timestamp"` + NonceStr string `json:"nonceStr"` + PrePayID string `json:"prePayId"` + SignType string `json:"signType"` + Package string `json:"package"` + PaySign string `json:"paySign"` } // PreOrder 是 unifie order 接口的返回 @@ -86,6 +95,48 @@ func NewPay(ctx *context.Context) *Pay { return &pay } +// BridgeConfig get js bridge config +func (pcf *Pay) BridgeConfig(p *Params) (cfg Config, err error) { + var ( + buffer strings.Builder + h hash.Hash + timestamp = strconv.FormatInt(time.Now().Unix(), 10) + ) + order, err := pcf.PrePayOrder(p) + if err != nil { + return + } + if p.SignType == "" { + p.SignType = "MD5" + } + buffer.WriteString("appId=") + buffer.WriteString(order.AppID) + buffer.WriteString("&nonceStr=") + buffer.WriteString(order.NonceStr) + buffer.WriteString("&package=") + buffer.WriteString("prepay_id=" + order.PrePayID) + buffer.WriteString("&signType=") + buffer.WriteString(p.SignType) + buffer.WriteString("&timeStamp=") + buffer.WriteString(timestamp) + buffer.WriteString("&key=") + buffer.WriteString(pcf.PayKey) + if p.SignType == "MD5" { + h = md5.New() + } else { + h = hmac.New(sha256.New, []byte(pcf.PayKey)) + } + h.Write([]byte(buffer.String())) + // 签名 + cfg.PaySign = strings.ToUpper(hex.EncodeToString(h.Sum(nil))) + cfg.NonceStr = order.NonceStr + cfg.Timestamp = timestamp + cfg.PrePayID = order.PrePayID + cfg.SignType = p.SignType + cfg.Package = "prepay_id=" + order.PrePayID + return +} + // PrePayOrder return data for invoke wechat payment func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) { nonceStr := util.RandomStr(32) From 546dce2396bcb39857ac5fed51433b4a3524c9dd Mon Sep 17 00:00:00 2001 From: ciel yu Date: Mon, 14 Oct 2019 18:59:42 +0800 Subject: [PATCH 09/36] =?UTF-8?q?=E6=94=AF=E4=BB=98=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20BridgeConfig=20=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8F=AF=E8=8E=B7?= =?UTF-8?q?=E5=BE=97=20prepay=20ID=EF=BC=8C=E5=8F=8Ajs=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=97=B6=E6=89=80=E9=9C=80=E8=A6=81=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一下单 新增非必传参数 --- pay/pay.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pay/pay.go b/pay/pay.go index 1e43514..0795c79 100644 --- a/pay/pay.go +++ b/pay/pay.go @@ -35,6 +35,10 @@ type Params struct { OpenID string TradeType string SignType string + Detail string + Attach string + GoodsTag string + NotifyUrl string } // Config 是传出用于 js sdk 用的参数 @@ -145,12 +149,23 @@ func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) { param["body"] = p.Body param["mch_id"] = pcf.PayMchID param["nonce_str"] = nonceStr - param["notify_url"] = pcf.PayNotifyURL param["out_trade_no"] = p.OutTradeNo param["spbill_create_ip"] = p.CreateIP param["total_fee"] = p.TotalFee param["trade_type"] = p.TradeType param["openid"] = p.OpenID + param["detail"] = p.Detail + param["attach"] = p.Attach + param["goods_tag"] = p.GoodsTag + param["notify_url"] = pcf.PayNotifyURL + // 签名类型 + if p.SignType != "" { + param["sign_type"] = p.SignType + } + // 通知地址 + if p.NotifyUrl != "" { + param["notify_url"] = p.NotifyUrl + } bizKey := "&key=" + pcf.PayKey str := orderParam(param, bizKey) From 3ea624f832c64165f112645a2ed6ef157e069a21 Mon Sep 17 00:00:00 2001 From: ciel yu Date: Mon, 14 Oct 2019 19:08:35 +0800 Subject: [PATCH 10/36] =?UTF-8?q?=E6=94=AF=E4=BB=98=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20BridgeConfig=20=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8F=AF=E8=8E=B7?= =?UTF-8?q?=E5=BE=97=20prepay=20ID=EF=BC=8C=E5=8F=8Ajs=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=97=B6=E6=89=80=E9=9C=80=E8=A6=81=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一下单 新增非必传参数 --- pay/pay.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/pay/pay.go b/pay/pay.go index 0795c79..b5da017 100644 --- a/pay/pay.go +++ b/pay/pay.go @@ -38,7 +38,7 @@ type Params struct { Detail string Attach string GoodsTag string - NotifyUrl string + NotifyURL string } // Config 是传出用于 js sdk 用的参数 @@ -67,7 +67,7 @@ type PreOrder struct { ErrCodeDes string `xml:"err_code_des,omitempty"` } -//payRequest 接口请求参数 +// payRequest 接口请求参数 type payRequest struct { AppID string `xml:"appid"` MchID string `xml:"mch_id"` @@ -77,20 +77,20 @@ type payRequest struct { SignType string `xml:"sign_type,omitempty"` Body string `xml:"body"` Detail string `xml:"detail,omitempty"` - Attach string `xml:"attach,omitempty"` //附加数据 - OutTradeNo string `xml:"out_trade_no"` //商户订单号 - FeeType string `xml:"fee_type,omitempty"` //标价币种 - TotalFee string `xml:"total_fee"` //标价金额 - SpbillCreateIP string `xml:"spbill_create_ip"` //终端IP - TimeStart string `xml:"time_start,omitempty"` //交易起始时间 - TimeExpire string `xml:"time_expire,omitempty"` //交易结束时间 - GoodsTag string `xml:"goods_tag,omitempty"` //订单优惠标记 - NotifyURL string `xml:"notify_url"` //通知地址 - TradeType string `xml:"trade_type"` //交易类型 - ProductID string `xml:"product_id,omitempty"` //商品ID + Attach string `xml:"attach,omitempty"` // 附加数据 + OutTradeNo string `xml:"out_trade_no"` // 商户订单号 + FeeType string `xml:"fee_type,omitempty"` // 标价币种 + TotalFee string `xml:"total_fee"` // 标价金额 + SpbillCreateIP string `xml:"spbill_create_ip"` // 终端IP + TimeStart string `xml:"time_start,omitempty"` // 交易起始时间 + TimeExpire string `xml:"time_expire,omitempty"` // 交易结束时间 + GoodsTag string `xml:"goods_tag,omitempty"` // 订单优惠标记 + NotifyURL string `xml:"notify_url"` // 通知地址 + TradeType string `xml:"trade_type"` // 交易类型 + ProductID string `xml:"product_id,omitempty"` // 商品ID LimitPay string `xml:"limit_pay,omitempty"` // - OpenID string `xml:"openid,omitempty"` //用户标识 - SceneInfo string `xml:"scene_info,omitempty"` //场景信息 + OpenID string `xml:"openid,omitempty"` // 用户标识 + SceneInfo string `xml:"scene_info,omitempty"` // 场景信息 } // NewPay return an instance of Pay package @@ -153,7 +153,7 @@ func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) { param["spbill_create_ip"] = p.CreateIP param["total_fee"] = p.TotalFee param["trade_type"] = p.TradeType - param["openid"] = p.OpenID + param["openid"] = p.OpenIDÒ param["detail"] = p.Detail param["attach"] = p.Attach param["goods_tag"] = p.GoodsTag @@ -192,7 +192,7 @@ func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) { return } if payOrder.ReturnCode == "SUCCESS" { - //pay success + // pay success if payOrder.ResultCode == "SUCCESS" { err = nil return From 09dabb232d5e39277a239582201b409eccb7fbd0 Mon Sep 17 00:00:00 2001 From: ciel yu Date: Mon, 14 Oct 2019 19:14:02 +0800 Subject: [PATCH 11/36] =?UTF-8?q?=E6=94=AF=E4=BB=98=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20BridgeConfig=20=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8F=AF=E8=8E=B7?= =?UTF-8?q?=E5=BE=97=20prepay=20ID=EF=BC=8C=E5=8F=8Ajs=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=97=B6=E6=89=80=E9=9C=80=E8=A6=81=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一下单 新增非必传参数 --- pay/pay.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pay/pay.go b/pay/pay.go index b5da017..1aa8062 100644 --- a/pay/pay.go +++ b/pay/pay.go @@ -163,8 +163,8 @@ func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) { param["sign_type"] = p.SignType } // 通知地址 - if p.NotifyUrl != "" { - param["notify_url"] = p.NotifyUrl + if p.NotifyURL != "" { + param["notify_url"] = p.NotifyURL } bizKey := "&key=" + pcf.PayKey From f68f9d6f5edf086185e6cdddb97f26bf3c5b74e3 Mon Sep 17 00:00:00 2001 From: ciel yu Date: Mon, 14 Oct 2019 19:28:28 +0800 Subject: [PATCH 12/36] =?UTF-8?q?=E6=94=AF=E4=BB=98=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20BridgeConfig=20=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8F=AF=E8=8E=B7?= =?UTF-8?q?=E5=BE=97=20prepay=20ID=EF=BC=8C=E5=8F=8Ajs=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=97=B6=E6=89=80=E9=9C=80=E8=A6=81=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一下单 新增非必传参数 --- pay/pay.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pay/pay.go b/pay/pay.go index 1aa8062..f4655c1 100644 --- a/pay/pay.go +++ b/pay/pay.go @@ -110,9 +110,6 @@ func (pcf *Pay) BridgeConfig(p *Params) (cfg Config, err error) { if err != nil { return } - if p.SignType == "" { - p.SignType = "MD5" - } buffer.WriteString("appId=") buffer.WriteString(order.AppID) buffer.WriteString("&nonceStr=") @@ -144,6 +141,15 @@ func (pcf *Pay) BridgeConfig(p *Params) (cfg Config, err error) { // PrePayOrder return data for invoke wechat payment func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) { nonceStr := util.RandomStr(32) + notifyURL := pcf.PayNotifyURL + // 签名类型 + if p.SignType == "" { + p.SignType = "MD5" + } + // 通知地址 + if p.NotifyURL != "" { + notifyURL = p.NotifyURL + } param := make(map[string]interface{}) param["appid"] = pcf.AppID param["body"] = p.Body @@ -153,19 +159,11 @@ func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) { param["spbill_create_ip"] = p.CreateIP param["total_fee"] = p.TotalFee param["trade_type"] = p.TradeType - param["openid"] = p.OpenIDÒ + param["openid"] = p.OpenID param["detail"] = p.Detail param["attach"] = p.Attach param["goods_tag"] = p.GoodsTag - param["notify_url"] = pcf.PayNotifyURL - // 签名类型 - if p.SignType != "" { - param["sign_type"] = p.SignType - } - // 通知地址 - if p.NotifyURL != "" { - param["notify_url"] = p.NotifyURL - } + param["notify_url"] = notifyURL bizKey := "&key=" + pcf.PayKey str := orderParam(param, bizKey) @@ -179,9 +177,13 @@ func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) { OutTradeNo: p.OutTradeNo, TotalFee: p.TotalFee, SpbillCreateIP: p.CreateIP, - NotifyURL: pcf.PayNotifyURL, + NotifyURL: notifyURL, TradeType: p.TradeType, OpenID: p.OpenID, + SignType: p.SignType, + Detail: p.Detail, + Attach: p.Attach, + GoodsTag: p.GoodsTag, } rawRet, err := util.PostXML(payGateway, request) if err != nil { From 0c9dd16f1fa97c4f5cc5853cf7bc60f81d61dafe Mon Sep 17 00:00:00 2001 From: ciel yu Date: Mon, 14 Oct 2019 19:35:08 +0800 Subject: [PATCH 13/36] =?UTF-8?q?=E6=94=AF=E4=BB=98=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20BridgeConfig=20=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8F=AF=E8=8E=B7?= =?UTF-8?q?=E5=BE=97=20prepay=20ID=EF=BC=8C=E5=8F=8Ajs=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=97=B6=E6=89=80=E9=9C=80=E8=A6=81=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一下单 新增非必传参数 --- pay/pay.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pay/pay.go b/pay/pay.go index f4655c1..1e25d18 100644 --- a/pay/pay.go +++ b/pay/pay.go @@ -160,6 +160,7 @@ func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) { param["total_fee"] = p.TotalFee param["trade_type"] = p.TradeType param["openid"] = p.OpenID + param["sign_type"] = p.SignType param["detail"] = p.Detail param["attach"] = p.Attach param["goods_tag"] = p.GoodsTag From 900a54ee065db952bb22c2ae5686773ebf8b80dd Mon Sep 17 00:00:00 2001 From: Chuanjian Wang Date: Tue, 15 Oct 2019 10:44:54 +0800 Subject: [PATCH 14/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=B0=B8=E4=B9=85=E7=B4=A0=E6=9D=90=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- material/material.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/material/material.go b/material/material.go index f4f1dfb..b7fdc32 100644 --- a/material/material.go +++ b/material/material.go @@ -13,6 +13,7 @@ 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" ) //Material 素材管理 @@ -36,6 +37,33 @@ type Article struct { ShowCoverPic int `json:"show_cover_pic"` Content string `json:"content"` ContentSourceURL string `json:"content_source_url"` + URL string `json:"url"` + DownURL string `json:"down_url"` +} + +// GetNews 获取/下载永久素材 +func (material *Material) GetNews(id string) ([]*Article, error) { + accessToken, err := material.GetAccessToken() + if err != nil { + return nil, err + } + uri := fmt.Sprintf("%s?access_token=%s", getMaterialURL, accessToken) + + var req struct { + MediaID string `json:"media_id"` + } + req.MediaID = id + responseBytes, err := util.PostJSON(uri, req) + + var res struct { + NewsItem []*Article `json:"news_item"` + } + err = json.Unmarshal(responseBytes, &res) + if err != nil { + return nil, err + } + + return res.NewsItem, nil } //reqArticles 永久性图文素材请求信息 From 87470f143d03518f5c467d8b7bc3cb4953077601 Mon Sep 17 00:00:00 2001 From: quxiaolong Date: Tue, 15 Oct 2019 11:54:40 +0800 Subject: [PATCH 15/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E7=9B=B8=E5=85=B3=20message=20=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- message/message.go | 8 ++++++++ server/server.go | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/message/message.go b/message/message.go index 366bfe8..8c7ae2a 100644 --- a/message/message.go +++ b/message/message.go @@ -63,6 +63,8 @@ const ( EventLocationSelect = "location_select" //EventTemplateSendJobFinish 发送模板消息推送通知 EventTemplateSendJobFinish = "TEMPLATESENDJOBFINISH" + //EventWxaMediaCheck 异步校验图片/音频是否含有违法违规内容推送事件 + EventWxaMediaCheck = "wxa_media_check" ) const ( @@ -144,6 +146,12 @@ type MixMessage struct { OuterStr string `xml:"OuterStr"` IsRestoreMemberCard int32 `xml:"IsRestoreMemberCard"` UnionID string `xml:"UnionId"` + + // 内容审核相关 + IsRisky bool `xml:"isrisky"` + ExtraInfoJSON string `xml:"extra_info_json"` + TraceID string `xml:"trace_id"` + StatusCode int `xml:"status_code"` } //EventPic 发图事件推送 diff --git a/server/server.go b/server/server.go index ad3c8ca..e4a4979 100644 --- a/server/server.go +++ b/server/server.go @@ -65,7 +65,9 @@ func (srv *Server) Serve() error { } //debug - //fmt.Println("request msg = ", string(srv.requestRawXMLMsg)) + if srv.debug { + fmt.Println("request msg = ", string(srv.requestRawXMLMsg)) + } return srv.buildResponse(response) } From 7bde39a634031dca306d506bbf8e62e92ca7939b Mon Sep 17 00:00:00 2001 From: kaiiak Date: Mon, 28 Oct 2019 00:53:56 +0800 Subject: [PATCH 16/36] =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=B0=B8=E4=B9=85=E8=A7=86=E9=A2=91=E7=B4=A0=E6=9D=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- material/material.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/material/material.go b/material/material.go index f4f1dfb..cc95d5d 100644 --- a/material/material.go +++ b/material/material.go @@ -138,11 +138,11 @@ func (material *Material) AddVideo(filename, title, introduction string) (mediaI fields := []util.MultipartFormField{ { IsFile: true, - Fieldname: "video", + Fieldname: "media", Filename: filename, }, { - IsFile: true, + IsFile: false, Fieldname: "description", Value: fieldValue, }, From e09031b58cd3693f5e1071b979d8eea37dc4a684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=81=BF=E9=91=AB?= Date: Fri, 1 Nov 2019 23:21:25 +0800 Subject: [PATCH 17/36] =?UTF-8?q?fix:=20=E5=BA=8F=E5=88=97=E5=8C=96=20xml?= =?UTF-8?q?=20=E6=97=B6=E6=B7=BB=E5=8A=A0=20cdata=20=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- message/message.go | 24 ++++++++++++++++-------- message/text.go | 4 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/message/message.go b/message/message.go index 8c7ae2a..4e9b6d2 100644 --- a/message/message.go +++ b/message/message.go @@ -148,10 +148,10 @@ type MixMessage struct { UnionID string `xml:"UnionId"` // 内容审核相关 - IsRisky bool `xml:"isrisky"` - ExtraInfoJSON string `xml:"extra_info_json"` - TraceID string `xml:"trace_id"` - StatusCode int `xml:"status_code"` + IsRisky bool `xml:"isrisky"` + ExtraInfoJSON string `xml:"extra_info_json"` + TraceID string `xml:"trace_id"` + StatusCode int `xml:"status_code"` } //EventPic 发图事件推送 @@ -178,20 +178,28 @@ type ResponseEncryptedXMLMsg struct { // CommonToken 消息中通用的结构 type CommonToken struct { XMLName xml.Name `xml:"xml"` - ToUserName string `xml:"ToUserName"` - FromUserName string `xml:"FromUserName"` + ToUserName CDATA `xml:"ToUserName"` + FromUserName CDATA `xml:"FromUserName"` CreateTime int64 `xml:"CreateTime"` MsgType MsgType `xml:"MsgType"` } +type CDATA string + +func (c CDATA) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + return e.EncodeElement(struct { + string `xml:",cdata"` + }{string(c)}, start) +} + //SetToUserName set ToUserName func (msg *CommonToken) SetToUserName(toUserName string) { - msg.ToUserName = toUserName + msg.ToUserName = CDATA(toUserName) } //SetFromUserName set FromUserName func (msg *CommonToken) SetFromUserName(fromUserName string) { - msg.FromUserName = fromUserName + msg.FromUserName = CDATA(fromUserName) } //SetCreateTime set createTime diff --git a/message/text.go b/message/text.go index d981d96..88ac19a 100644 --- a/message/text.go +++ b/message/text.go @@ -3,12 +3,12 @@ package message //Text 文本消息 type Text struct { CommonToken - Content string `xml:"Content"` + Content CDATA `xml:"Content"` } //NewText 初始化文本消息 func NewText(content string) *Text { text := new(Text) - text.Content = content + text.Content = CDATA(content) return text } From 1fc4cc70ecde3a05c3c059dc83c3795ff9bffd8f Mon Sep 17 00:00:00 2001 From: silenceper Date: Tue, 5 Nov 2019 14:45:22 +0800 Subject: [PATCH 18/36] Create FUNDING.yml --- .github/FUNDING.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..b6a498a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: https://silenceper.com/img/wechat-pay.jpeg From 55615762eb59d6b94dbe9b03ded51094e9165c4c Mon Sep 17 00:00:00 2001 From: silenceper Date: Tue, 5 Nov 2019 14:48:27 +0800 Subject: [PATCH 19/36] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. From 13facb6df82d78a9a590c262aa7598d92fe24fa4 Mon Sep 17 00:00:00 2001 From: silenceper Date: Tue, 5 Nov 2019 14:50:03 +0800 Subject: [PATCH 20/36] Create ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..5d6e38c --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,2 @@ +## 问题及现象 +