69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package reward
|
|
|
|
import (
|
|
"context"
|
|
"crypto/md5"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/glog"
|
|
"server/api/reward/v1"
|
|
"server/internal/model"
|
|
"server/internal/service"
|
|
"server/utility/ecode"
|
|
"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")
|
|
glog.Infof(ctx, fmt.Sprintf("appid:%s,timestamp:%s,nonce:%s,auth:%s", appid, timestamp, nonce, 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)
|
|
|
|
glog.Infof(ctx, fmt.Sprintf("myAuth:%s,auth:%s", myAuth, auth))
|
|
if myAuth != auth {
|
|
glog.Infof(ctx, fmt.Sprintf("myAuth:%s,auth:%s", 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))
|
|
|
|
out, err := service.Reward().CallBack(ctx, &model.RewardCallbackIn{
|
|
Uid: req.Uid,
|
|
CustomInfo: req.CustomInfo,
|
|
OrderId: req.OrderId,
|
|
PrizeChannelId: req.PrizeChannelId,
|
|
PrizeId: req.PrizeId,
|
|
PrizeType: int(req.PrizeType),
|
|
PrizeSubType: int(req.PrizeSubType),
|
|
Num: int(req.Num),
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
//return &v1.CallbackRes{
|
|
// AppId: appid,
|
|
// Datas: out.Datas,
|
|
// Errcode: out.Errcode,
|
|
// Errmsg: out.Errmsg,
|
|
// OrderId: out.OrderId,
|
|
//}, nil
|
|
|
|
marshal, err := json.Marshal(out)
|
|
if err != nil {
|
|
return nil, ecode.Fail.Sub("序列化 json 数据出现异常")
|
|
}
|
|
g.RequestFromCtx(ctx).Response.Write(marshal)
|
|
return nil, nil
|
|
//return &v1.CallbackRes{Errcode: 0, OrderId: req.OrderId, Datas: []v1.CallbackData{{PrizeCode: req.OrderId}}}, err
|
|
}
|