31 lines
1.2 KiB
Go
31 lines
1.2 KiB
Go
package reward
|
|
|
|
import (
|
|
"context"
|
|
"crypto/md5"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/glog"
|
|
"server/api/reward/v1"
|
|
"strings"
|
|
)
|
|
|
|
func (c *ControllerV1) Callback(ctx context.Context, req *v1.CallbackReq) (res *v1.CallbackRes, err error) {
|
|
fromCtx := g.RequestFromCtx(ctx)
|
|
appid := fromCtx.Header.Get("Custom-Data-Appid")
|
|
timestamp := fromCtx.Header.Get("Custom-Data-Timestamp")
|
|
nonce := fromCtx.Header.Get("Custom-Data-Nonce")
|
|
auth := fromCtx.Header.Get("Custom-Data-Auth")
|
|
|
|
data := fmt.Sprintf("%s%s%s%s%d%d%d%s%s%s#%s", req.Uid, req.OrderId, req.PrizeChannelId, req.PrizeId, req.PrizeType, req.PrizeSubType, req.Num, appid, timestamp, nonce, auth)
|
|
stateOri := md5.Sum([]byte(data))
|
|
state := hex.EncodeToString(stateOri[:])
|
|
myAuth := strings.ToUpper(state)
|
|
if myAuth != auth {
|
|
return &v1.CallbackRes{Errcode: 252151000, OrderId: req.OrderId, Datas: []v1.CallbackData{{PrizeCode: req.OrderId}}}, err
|
|
}
|
|
glog.Infof(ctx, fmt.Sprintf("%s,%s,%s,%s,%d,%d,%d,%s,%s,%s,#%s", req.Uid, req.OrderId, req.PrizeChannelId, req.PrizeId, req.PrizeType, req.PrizeSubType, req.Num, appid, timestamp, nonce, auth))
|
|
return &v1.CallbackRes{Errcode: 0, OrderId: req.OrderId, Datas: []v1.CallbackData{{PrizeCode: req.OrderId}}}, err
|
|
}
|