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/gamelife" "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, gamelife.GetGamelifeClient(ctx).GetSecret()) stateOri := md5.Sum([]byte(data)) state := hex.EncodeToString(stateOri[:]) myAuth := strings.ToUpper(state) 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)) 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 } 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), }) marshal, err := json.Marshal(out) if err != nil { glog.Error(ctx, "序列化 json 数据出现异常") g.RequestFromCtx(ctx).Response.Write(marshal) return nil, nil } glog.Infof(ctx, "回调响应:%s", marshal) g.RequestFromCtx(ctx).Response.Write(marshal) return nil, nil }