mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-08 14:42:26 +08:00
feat: improve comment and upgrade golang version 1.16 (#604)
* feat: improve action config and code comment * feat: improve comment and upgrade golang version 1.16 * feat: improve import
This commit is contained in:
@@ -15,21 +15,22 @@ type SignatureOptions struct {
|
||||
}
|
||||
|
||||
// VerifyURL 验证请求参数是否合法并返回解密后的消息内容
|
||||
// //Gin框架的使用示例
|
||||
// r.GET("/v1/event/callback", func(c *gin.Context) {
|
||||
// options := kf.SignatureOptions{}
|
||||
// //获取回调的的校验参数
|
||||
// if = c.ShouldBindQuery(&options); err != nil {
|
||||
// c.String(http.StatusUnauthorized, "参数解析失败")
|
||||
// }
|
||||
// // 调用VerifyURL方法校验当前请求,如果合法则把解密后的内容作为响应返回给微信服务器
|
||||
// echo, err := kfClient.VerifyURL(options)
|
||||
// if err == nil {
|
||||
// c.String(http.StatusOK, echo)
|
||||
// } else {
|
||||
// c.String(http.StatusUnauthorized, "非法请求来源")
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// //Gin框架的使用示例
|
||||
// r.GET("/v1/event/callback", func(c *gin.Context) {
|
||||
// options := kf.SignatureOptions{}
|
||||
// //获取回调的的校验参数
|
||||
// if = c.ShouldBindQuery(&options); err != nil {
|
||||
// c.String(http.StatusUnauthorized, "参数解析失败")
|
||||
// }
|
||||
// // 调用VerifyURL方法校验当前请求,如果合法则把解密后的内容作为响应返回给微信服务器
|
||||
// echo, err := kfClient.VerifyURL(options)
|
||||
// if err == nil {
|
||||
// c.String(http.StatusOK, echo)
|
||||
// } else {
|
||||
// c.String(http.StatusUnauthorized, "非法请求来源")
|
||||
// }
|
||||
// })
|
||||
func (r *Client) VerifyURL(options SignatureOptions) (string, error) {
|
||||
if options.Signature != util.Signature(r.ctx.Token, options.TimeStamp, options.Nonce, options.EchoStr) {
|
||||
return "", NewSDKErr(40015)
|
||||
@@ -59,27 +60,28 @@ type CallbackMessage struct {
|
||||
}
|
||||
|
||||
// GetCallbackMessage 获取回调事件中的消息内容
|
||||
// //Gin框架的使用示例
|
||||
// r.POST("/v1/event/callback", func(c *gin.Context) {
|
||||
// var (
|
||||
// message kf.CallbackMessage
|
||||
// body []byte
|
||||
// )
|
||||
// // 读取原始消息内容
|
||||
// body, err = c.GetRawData()
|
||||
// if err != nil {
|
||||
// c.String(http.StatusInternalServerError, err.Error())
|
||||
// return
|
||||
// }
|
||||
// // 解析原始数据
|
||||
// message, err = kfClient.GetCallbackMessage(body)
|
||||
// if err != nil {
|
||||
// c.String(http.StatusInternalServerError, "消息获取失败")
|
||||
// return
|
||||
// }
|
||||
// fmt.Println(message)
|
||||
// c.String(200, "ok")
|
||||
// })
|
||||
//
|
||||
// //Gin框架的使用示例
|
||||
// r.POST("/v1/event/callback", func(c *gin.Context) {
|
||||
// var (
|
||||
// message kf.CallbackMessage
|
||||
// body []byte
|
||||
// )
|
||||
// // 读取原始消息内容
|
||||
// body, err = c.GetRawData()
|
||||
// if err != nil {
|
||||
// c.String(http.StatusInternalServerError, err.Error())
|
||||
// return
|
||||
// }
|
||||
// // 解析原始数据
|
||||
// message, err = kfClient.GetCallbackMessage(body)
|
||||
// if err != nil {
|
||||
// c.String(http.StatusInternalServerError, "消息获取失败")
|
||||
// return
|
||||
// }
|
||||
// fmt.Println(message)
|
||||
// c.String(200, "ok")
|
||||
// })
|
||||
func (r *Client) GetCallbackMessage(encryptedMsg []byte) (msg CallbackMessage, err error) {
|
||||
var origin callbackOriginMessage
|
||||
if err = xml.Unmarshal(encryptedMsg, &origin); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user