Documentation ¶
Index ¶
- Constants
- Variables
- func Bytes4ToInt(b []byte) int
- func GetSHA1(token, timestamp, nonce, encryptMsg string) (msg string)
- func IntToBytes4(n int) []byte
- func PKCS7EncoderDecode(origData []byte) []byte
- func PKCS7EncoderEncode(cipherText []byte) []byte
- func WXBizMsgErrorMsg(errorCode int) string
- func XmlParseExtract(xmlText []byte) (errCode int, encrypt string, toUserName string)
- func XmlParseGenerate(encrypt, signature, timestamp, nonce string) []byte
- type MsgDecryptFormatEvent
- type MsgEncryptFormat
- type MsgFormat
- type MsgFormatArticlesItem
- type MsgFormatArticlesList
- type MsgFormatImage
- type MsgFormatMusic
- type MsgFormatVideo
- type MsgFormatVoice
- type MsgReplyFormatArticles
- type MsgReplyFormatImage
- type MsgReplyFormatMusic
- type MsgReplyFormatText
- type MsgReplyFormatVideo
- type MsgReplyFormatVoice
- type Prpcrypt
- type WXBizMsgCrypt
Constants ¶
View Source
const ( WXBizMsgCryptOK = 0 WXBizMsgCryptValidateSignatureError = -40001 WXBizMsgCryptParseXmlError = -40002 WXBizMsgCryptComputeSignatureError = -40003 WXBizMsgCryptIllegalAesKey = -40004 WXBizMsgCryptValidateAppidError = -40005 WXBizMsgCryptEncryptAESError = -40006 WXBizMsgCryptDecryptAESError = -40007 WXBizMsgCryptIllegalBuffer = -40008 WXBizMsgCryptEncodeBase64Error = -40009 WXBizMsgCryptDecodeBase64Error = -40010 WXBizMsgCryptGenReturnXmlError = -40011 )
*
- error code 说明.
- <ul>
- <li>-40001: 签名验证错误</li>
- <li>-40002: xml解析失败</li>
- <li>-40003: sha加密生成签名失败</li>
- <li>-40004: encodingAesKey 非法</li>
- <li>-40005: appid 校验错误</li>
- <li>-40006: aes 加密失败</li>
- <li>-40007: aes 解密失败</li>
- <li>-40008: 解密后得到的buffer非法</li>
- <li>-40009: base64加密失败</li>
- <li>-40010: base64解密失败</li>
- <li>-40011: 生成xml失败</li>
- </ul>
Variables ¶
View Source
var PKCS7EncoderBlockSize = 32
Functions ¶
func GetSHA1 ¶
*
- 用SHA1算法生成安全签名
- @param string $token 票据
- @param string $timestamp 时间戳
- @param string $nonce 随机字符串
- @param string $encrypt 密文消息
func PKCS7EncoderEncode ¶
func WXBizMsgErrorMsg ¶
func XmlParseExtract ¶
*
- 提取出xml数据包中的加密消息
- @param string $xmltext 待提取的xml字符串
- @return string 提取出的加密消息字符串
func XmlParseGenerate ¶
*
- 生成xml消息
- @param string $encrypt 加密后的消息密文
- @param string $signature 安全签名
- @param string $timestamp 时间戳
- @param string $nonce 随机字符串
Types ¶
type MsgDecryptFormatEvent ¶ added in v1.3.4
type MsgDecryptFormatEvent struct { ToUserName string `xml:"ToUserName"` FromUserName string `xml:"FromUserName"` CreateTime string `xml:"CreateTime"` MsgType string `xml:"MsgType"` Content string `xml:"Content"` //文本消息 MsgId string `xml:"MsgId"` //文本消息 Event string `xml:"Event"` //非文本时含有 EventKey string `xml:"EventKey"` //扫二维码带此参数 Ticket string `xml:"Ticket"` //扫二维码带此参数 Latitude float64 `xml:"Latitude"` //地理位置 Longitude float64 `xml:"Longitude"` //地理位置 Precision float64 `xml:"Precision"` //地理位置 }
用户向微信发送的事件
type MsgEncryptFormat ¶
type MsgFormatArticlesItem ¶ added in v1.3.3
type MsgFormatArticlesList ¶ added in v1.3.3
type MsgFormatArticlesList struct {
// contains filtered or unexported fields
}
type MsgFormatImage ¶ added in v1.3.3
type MsgFormatImage struct {
MediaId string `xml:"MediaId"`
}
type MsgFormatMusic ¶ added in v1.3.3
type MsgFormatVideo ¶ added in v1.3.3
type MsgFormatVoice ¶ added in v1.3.3
type MsgFormatVoice struct {
MediaId string `xml:"MediaId"`
}
type MsgReplyFormatArticles ¶ added in v1.3.4
type MsgReplyFormatImage ¶ added in v1.3.4
type MsgReplyFormatImage struct { ToUserName string `xml:"ToUserName"` FromUserName string `xml:"FromUserName"` CreateTime string `xml:"CreateTime"` MsgType string `xml:"MsgType"` Image []MsgFormatImage `xml:"Image"` }
type MsgReplyFormatMusic ¶ added in v1.3.4
type MsgReplyFormatMusic struct { ToUserName string `xml:"ToUserName"` FromUserName string `xml:"FromUserName"` CreateTime string `xml:"CreateTime"` MsgType string `xml:"MsgType"` Music []MsgFormatMusic `xml:"Music"` }
type MsgReplyFormatText ¶ added in v1.3.4
type MsgReplyFormatText struct { ToUserName string `xml:"ToUserName"` FromUserName string `xml:"FromUserName"` CreateTime string `xml:"CreateTime"` MsgType string `xml:"MsgType"` Content string `xml:"Content"` }
本地服务器返回给微信服务器的消息格式
type MsgReplyFormatVideo ¶ added in v1.3.4
type MsgReplyFormatVideo struct { ToUserName string `xml:"ToUserName"` FromUserName string `xml:"FromUserName"` CreateTime string `xml:"CreateTime"` MsgType string `xml:"MsgType"` Video []MsgFormatVideo `xml:"Video"` }
type MsgReplyFormatVoice ¶ added in v1.3.4
type MsgReplyFormatVoice struct { ToUserName string `xml:"ToUserName"` FromUserName string `xml:"FromUserName"` CreateTime string `xml:"CreateTime"` MsgType string `xml:"MsgType"` Voice []MsgFormatVoice `xml:"Voice"` }
type Prpcrypt ¶
type Prpcrypt struct {
// contains filtered or unexported fields
}
func PrpcryptDefault ¶
type WXBizMsgCrypt ¶
type WXBizMsgCrypt struct {
// contains filtered or unexported fields
}
*
- 构造函数
- @param $token string 公众平台上,开发者设置的token
- @param $encodingAesKey string 公众平台上,开发者设置的EncodingAESKey
- @param $appId string 公众平台的appId
func Default ¶
func Default(token, encodingAesKey, appId string) *WXBizMsgCrypt
func (*WXBizMsgCrypt) DecryptMsg ¶
func (wx *WXBizMsgCrypt) DecryptMsg(msgSignature, timeStamp, nonce string, postData []byte) (msg []byte, errorCode int)
*
- 检验消息的真实性,并且获取解密后的明文.
- <ol>
- <li>利用收到的密文生成安全签名,进行签名验证</li>
- <li>若验证通过,则提取xml中的加密消息</li>
- <li>对消息进行解密</li>
- </ol> *
- @param $msgSignature string 签名串,对应URL参数的msg_signature
- @param $timestamp string 时间戳 对应URL参数的timestamp
- @param $nonce string 随机串,对应URL参数的nonce
- @param $postData string 密文,对应POST请求的数据
- @param &$msg string 解密后的原文,当return返回0时有效 *
- @return int 成功0,失败返回对应的错误码
func (*WXBizMsgCrypt) EncryptMsg ¶
func (wx *WXBizMsgCrypt) EncryptMsg(replyMsg, timeStamp, nonce string) (encryptMsg []byte, errorCode int)
*
- 将公众平台回复用户的消息加密打包.
- <ol>
- <li>对要发送的消息进行AES-CBC加密</li>
- <li>生成安全签名</li>
- <li>将消息密文和安全签名打包成xml格式</li>
- </ol> *
- @param $replyMsg string 公众平台待回复用户的消息,xml格式的字符串
- @param $timeStamp string 时间戳,可以自己生成,也可以用URL参数的timestamp
- @param $nonce string 随机串,可以自己生成,也可以用URL参数的nonce
- @param &$encryptMsg string 加密后的可以直接回复用户的密文,包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串,
- 当return返回0时有效 *
- @return int 成功0,失败返回对应的错误码
Source Files ¶
Click to show internal directories.
Click to hide internal directories.