1 Star 0 Fork 0

maomao/go-fly-master

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
weixin.go 937 Bytes
Copy Edit Raw Blame History
maocs authored 2025-04-01 20:24 +08:00 . 初始化
package controller
import (
"crypto/sha1"
"encoding/hex"
"github.com/gin-gonic/gin"
"gitee.com/maomaoxiaochao/go-fly-master/tree/master/models"
"log"
"sort"
)
func GetCheckWeixinSign(c *gin.Context) {
token := models.FindConfig("WeixinToken")
signature := c.Query("signature")
timestamp := c.Query("timestamp")
nonce := c.Query("nonce")
echostr := c.Query("echostr")
//将token、timestamp、nonce三个参数进行字典序排序
var tempArray = []string{token, timestamp, nonce}
sort.Strings(tempArray)
//将三个参数字符串拼接成一个字符串进行sha1加密
var sha1String string = ""
for _, v := range tempArray {
sha1String += v
}
h := sha1.New()
h.Write([]byte(sha1String))
sha1String = hex.EncodeToString(h.Sum([]byte("")))
//获得加密后的字符串可与signature对比
if sha1String == signature {
c.Writer.Write([]byte(echostr))
} else {
log.Println("微信API验证失败")
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/maomaoxiaochao/go-fly-master.git
git@gitee.com:maomaoxiaochao/go-fly-master.git
maomaoxiaochao
go-fly-master
go-fly-master
2aceef85fb87

Search