生成表结构、
This commit is contained in:
32
internal/controller/wx/wx_v1_we_chat_vertify.go
Normal file
32
internal/controller/wx/wx_v1_we_chat_vertify.go
Normal file
@ -0,0 +1,32 @@
|
||||
package wx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/crypto/gsha1"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"server/utility/ecode"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"server/api/auth/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) WeChatVertify(ctx context.Context, req *v1.WeChatVertifyReq) (res *v1.WeChatVertifyRes, err error) {
|
||||
|
||||
weChatToken := g.Config().MustGet(ctx, "wechat.token").String()
|
||||
// 1. 将 token、timestamp、nonce 组成 slice
|
||||
params := []string{weChatToken, req.Timestamp, req.Nonce}
|
||||
// 2. 字典序排序
|
||||
sort.Strings(params)
|
||||
// 3. 拼接字符串
|
||||
joined := strings.Join(params, "")
|
||||
// 4. SHA1 加密
|
||||
encrypt := gsha1.Encrypt(joined)
|
||||
|
||||
// 5. 与 signature 对比
|
||||
if encrypt != req.Signature {
|
||||
return nil, ecode.InvalidOperation.Sub("微信服务器验证失败")
|
||||
}
|
||||
g.RequestFromCtx(ctx).Response.WriteJson(req.EchoStr)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user