Documentation ¶
Overview ¶
Package mp provides accesstoken fetch functions for wechat mp dev
Package mp provides encrpytmsg and decrpytmsg for mp wechat message.
Package mp provides menu create opertations.
Package mp provides functions for handling the received messages.
Index ¶
- Constants
- func CreateMenu(menuLayout []byte, accessToken, agentID string) error
- func DecryptMsg(cipherText, encodingAESKey string) ([]byte, int, string, error)
- func EncryptMsg(msg []byte, appID string, encodingAESKey string) (string, error)
- func FetchAccessToken(appID, appSecret string) (string, float64, error)
- func NewRecvHandler(appID, token, encodingAESKey string) pb.RecvHandler
- func SendMsg(accessToken string, pkg interface{}) error
- func ValidateSignature(signature, token, timestamp, nonce string) bool
- type RecvHTTPEncryptReqBody
- type RecvHTTPEncryptRespBody
- type RecvImageDataPkg
- type RecvLinkDataPkg
- type RecvLocationDataPkg
- type RecvLocationEventDataPkg
- type RecvMenuEventDataPkg
- type RecvScanEventDataPkg
- type RecvShortVideoDataPkg
- type RecvSubscribeEventDataPkg
- type RecvTextDataPkg
- type RecvUnsubscribeScanEventDataPkg
- type RecvVideoDataPkg
- type RecvVoiceDataPkg
- type RecvVoiceRecognitionDataPkg
- type WebAccessTokenResponse
Constants ¶
const ( // Msg type TextMsg = "text" ImageMsg = "image" VoiceMsg = "voice" VideoMsg = "video" ShortVideoMsg = "shortvideo" LocationMsg = "location" LinkMsg = "link" EventMsg = "event" // Event type SubscribeEvent = "subscribe" UnsubscribeEvent = "unsubscribe" LocationEvent = "LOCATION" MenuClickEvent = "CLICK" MenuViewEvent = "VIEW" ScanEvent = "SCAN" )
Variables ¶
This section is empty.
Functions ¶
func CreateMenu ¶
func DecryptMsg ¶
DecryptMsg is used to decrpyt msg_encrypt in wechat mp request. it returns msg, msgLen, corpid, error. msg_encrypt = Base64_Encode( AES_Encrypt[random(16B) + msg_len(4B) + msg + $appID]).
func EncryptMsg ¶
EncryptMsg is used to encrpyt msg in wechat mp response or custom message. it returns msg_encrypt. msg_encrypt = Base64_Encode( AES_Encrypt[random(16B) + msg_len(4B) + msg + $appID]).
func FetchAccessToken ¶
FetchAccessToken could be used to fetch access token for wechat qy dev.
func NewRecvHandler ¶
func NewRecvHandler(appID, token, encodingAESKey string) pb.RecvHandler
NewRecvHandler creates an instance of recvHandler which implements pb.RecvHandler interface.
func ValidateSignature ¶
ValidateSignature is used to validate the signature in request to figure out whether the http request come from wechat mp platform.
Types ¶
type RecvHTTPEncryptReqBody ¶
RecvHTTPEncryptReqBody is a unmarshall result for below xml data: <xml>
<ToUserName><![CDATA[toUser]]</ToUserName> <Encrypt><![CDATA[msg_encrypt]]</Encrypt>
</xml>
type RecvHTTPEncryptRespBody ¶
type RecvHTTPEncryptRespBody struct { XMLName xml.Name `xml:"xml"` Encrypt pb.CDATAText MsgSignature pb.CDATAText TimeStamp int Nonce pb.CDATAText }
RecvHTTPEncryptResqBody is a source for marshalling below xml data: <xml>
<Encrypt><![CDATA[msg_encrypt]]></Encrypt> <MsgSignature><![CDATA[msg_signature]]></MsgSignature> <TimeStamp>timestamp</TimeStamp> <Nonce><![CDATA[nonce]]></Nonce>
</xml>
type RecvImageDataPkg ¶
type RecvImageDataPkg struct { pb.RecvBaseDataPkg PicURL string MediaID string MsgID uint64 `xml:"MsgId"` }
RecvImageDataPkg is a Image Message received from wechat platform.
type RecvLinkDataPkg ¶
type RecvLinkDataPkg struct { pb.RecvBaseDataPkg Title string Description string URL string `xml:"Url"` MsgID uint64 `xml:"MsgId"` }
RecvLinkDataPkg is a Link Message received from wechat platform.
type RecvLocationDataPkg ¶
type RecvLocationDataPkg struct { pb.RecvBaseDataPkg LocX float64 `xml:"Location_X"` LocY float64 `xml:"Location_Y"` Scale int Label string MsgID uint64 `xml:"MsgId"` }
RecvLocationDataPkg is a Location Message received from wechat platform.
type RecvLocationEventDataPkg ¶
type RecvLocationEventDataPkg struct { pb.RecvBaseDataPkg Event string Latitude float64 Longitude float64 Precision float64 }
RecvLocationEventDataPkg is a Location event Message received from wechat platform.
type RecvMenuEventDataPkg ¶
type RecvMenuEventDataPkg struct { pb.RecvBaseDataPkg Event string EventKey string }
RecvMenuEventDataPkg is a Menu Click event Message received from wechat platform.
type RecvScanEventDataPkg ¶
type RecvScanEventDataPkg struct { pb.RecvBaseDataPkg Event string EventKey string Ticket string }
RecvScanDataPkg is a scan event from subscribed user from wechat platform.
type RecvShortVideoDataPkg ¶
type RecvShortVideoDataPkg struct { pb.RecvBaseDataPkg MediaID string ThumbMediaID string MsgID uint64 `xml:"MsgId"` }
RecvShortVideoDataPkg is a short video Message received from wechat platform.
type RecvSubscribeEventDataPkg ¶
type RecvSubscribeEventDataPkg struct { pb.RecvBaseDataPkg Event string }
RecvSubscribeEventDataPkg is a Subscribe/Unsubscribe event Message received from wechat platform.
type RecvTextDataPkg ¶
type RecvTextDataPkg struct { pb.RecvBaseDataPkg Content string MsgID uint64 `xml:"MsgId"` }
RecvTextDataPkg is a Text Message received from wechat platform.
type RecvUnsubscribeScanEventDataPkg ¶
type RecvUnsubscribeScanEventDataPkg struct { pb.RecvBaseDataPkg Event string EventKey string Ticket string }
RecvUnsubscribeScanDataPkg is a scan event from unsubscribe user from wechat platform.
type RecvVideoDataPkg ¶
type RecvVideoDataPkg struct { pb.RecvBaseDataPkg MediaID string ThumbMediaID string MsgID uint64 `xml:"MsgId"` }
RecvVideoDataPkg is a Video Message received from wechat platform.
type RecvVoiceDataPkg ¶
type RecvVoiceDataPkg struct { pb.RecvBaseDataPkg MediaID string Format string MsgID uint64 `xml:"MsgId"` }
RecvVoiceDataPkg is a Voice Message received from wechat platform.
type RecvVoiceRecognitionDataPkg ¶
type RecvVoiceRecognitionDataPkg struct { pb.RecvBaseDataPkg MediaID string `xml:"MediaId"` Format string Recognition string MsgID uint64 `xml:"MsgId"` }
RecvVoiceRecognitionDataPkg is a Voice recognition Message received from wechat platform.
type WebAccessTokenResponse ¶
type WebAccessTokenResponse struct { AccessToken string `json:"access_token"` ExpiresIn float64 `json:"expires_in"` RefreshToken string `json:"refresh_token"` OpenID string `json:"openid"` Scope string `json:"scope"` }
func FetchWebAuthInfo ¶
func FetchWebAuthInfo(appID, appSecret, code string) (*WebAccessTokenResponse, error)