调整微信扫码登录相关接口,拆分门店奖励:奖励类型、奖励详情
This commit is contained in:
@ -2,31 +2,34 @@ package wx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/crypto/gsha1"
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"server/utility/ecode"
|
||||
"server/utility/wechat"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"server/api/auth/v1"
|
||||
"server/api/wx/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. 字典序排序
|
||||
// 1. 排序
|
||||
params := []string{wechat.GetWeChatClient().GetToken(), req.Timestamp, req.Nonce}
|
||||
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("微信服务器验证失败")
|
||||
// 2. 拼接成字符串
|
||||
str := strings.Join(params, "")
|
||||
|
||||
// 3. SHA1 加密
|
||||
h := sha1.New()
|
||||
h.Write([]byte(str))
|
||||
sha1Str := fmt.Sprintf("%x", h.Sum(nil))
|
||||
|
||||
// 4. 比较签名
|
||||
if sha1Str != req.Signature {
|
||||
return nil, fmt.Errorf("签名错误")
|
||||
}
|
||||
g.RequestFromCtx(ctx).Response.WriteJson(req.EchoStr)
|
||||
return
|
||||
g.RequestFromCtx(ctx).Response.Write(req.EchoStr)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user