tkcashgame_v4/app/eonline/internal/service/eonline.go

974 lines
24 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
v1 "sandc/api/eonline/v1"
"sandc/app/eonline/internal/biz"
"sandc/app/eonline/internal/conf"
"sandc/app/eonline/internal/config"
"sandc/app/eonline/internal/data"
"sandc/pkg/middleware/xhttp"
"sandc/pkg/utils"
"github.com/go-kratos/kratos/v2/log"
"github.com/paemuri/brdoc"
"github.com/shopspring/decimal"
)
// EonlineService is a eonline service.
type EonlineService struct {
v1.UnimplementedEonlineServer
uc *biz.EonlineUsecase
log *log.Helper
conf *conf.Bootstrap
}
var (
mysqlDB *biz.EonlineUsecase
nowStrSeconds string // 当前时间秒级时间戳字符串
nowStrMilliSeconds string // 当前时间毫秒级时间戳字符串
)
// NewEonlineService new a greeter service.
func NewEonlineService(uc *biz.EonlineUsecase, logger log.Logger, conf *conf.Bootstrap) *EonlineService {
nowStrSeconds = strconv.FormatInt(time.Now().Unix(), 10)
nowStrMilliSeconds = strconv.FormatInt(time.Now().UnixMilli(), 10)
mysqlDB = uc
timeoutTimerPer10Second = int64(conf.Server.TimeoutTimerPer10Second)
return &EonlineService{uc: uc, log: log.NewHelper(logger), conf: conf}
}
func checkStrSeconds(ts string) bool {
if len(ts) == len(nowStrSeconds) {
return true
}
return false
}
func checkStrMilliSeconds(ts string) bool {
if len(ts) == len(nowStrMilliSeconds) {
return true
}
return false
}
// SayHello implements helloworld.EonlineServer
func (s *EonlineService) SayHello(ctx context.Context, in *v1.HelloRequest) (*v1.HelloReply, error) {
s.log.WithContext(ctx).Infof("SayHello Received: %v", in.GetName())
if in.GetName() == "error" {
return nil, v1.ErrorUserNotFound("user not found: %s", in.GetName())
}
return &v1.HelloReply{Message: "Hello " + in.GetName()}, nil
}
// PayInit 初始化支付用户信息
func (s *EonlineService) PayInit(ctx context.Context, req *v1.PayInitReq) (*v1.PayInitReply, error) {
fmt.Printf("PayInit: req[%+v]\n", req)
log.Infof("PayInit: req[%+v]", req)
reply := &v1.PayInitReply{}
for {
// 固定结构体参数
// 验证签名
err := s.validateSignRequest(
v1.PayInitReq{
Platform: req.Platform,
Deviceid: req.Deviceid,
Version: req.Version,
Ip: req.Ip,
Ts: req.Ts,
Sign: req.Sign,
}, biz.SignFixedParameters)
if err != nil {
// return nil, fmt.Errorf("validate request error: %w", err)
reply.Error = 2
break
}
if !checkStrSeconds(req.Ts) {
reply.Error = 4
break
}
if s.conf.Server.Env != "qa" {
req.Ts = strconv.Itoa(int(time.Now().Unix()))
}
// ver := config.Version2int(&req.Version)
// if ver < config.PublicVersionMin {
// // return nil, fmt.Errorf("version [%s] not support", req.Version)
// reply.Error = 3
// break
// }
// 获取真实IP地址和国家code
country, currentIp := s.uc.GetCountryCodeByIp(ctx, req.Ip)
req.Ip = currentIp
x, err := s.uc.PayInit(ctx, &biz.PayoutAddtionalReq{
Platform: req.Platform,
DeviceId: req.Deviceid,
Ip: req.Ip,
Version: req.Version,
Country: country,
Ts: req.Ts,
})
if err != nil {
log.Infof("PayInit error: err[%v]", err)
// return nil, err
reply.Error = 1
break
}
// 生成唯一用户ID
uuid := biz.GenPayoutUuid(req.Deviceid)
x2, err := s.uc.CheckInfo(ctx, &biz.CheckInfoReq{
Uuid: uuid,
Ts: req.Ts,
})
if err != nil {
log.Infof("PayInit error: err[%v]", err)
reply.Error = 1
break
}
reply = &v1.PayInitReply{
Uuid: x.UUID,
CanCheckSubmit: int32(x2.CanCheckSubmit),
CheckSubmit: x2.CheckSubmit,
CheckResult: x2.CheckResult,
CheckPayout: x2.CheckPayout,
CheckCoin: config.PublicCheckCoin,
CanCheckPayOut: x2.CanCheckPayOut,
CheckResultFailedDesc: x2.CheckResultFailedDesc,
ClientData: x.ClientData,
}
items := make([]*v1.PayInitReply_Item, 0)
for _, v := range x.Items {
items = append(items, &v1.PayInitReply_Item{
Id: uint32(v.Id),
Amount: v.Amount,
Status: uint32(v.Status),
})
}
var status uint32 // 状态:1可提现 2:条件未达成 3:已提现, 4:禁止提现, 5:提现中
switch reply.CheckPayout { // 提交身份文件奖励5美元领取的情况0没有提现记录1提现中2提现成功3提现失败
case 0:
status = 2
if reply.CanCheckPayOut != 1 { // 身份文件审核过的提现奖励5美元 能否 提现0能提现1条件不满足不能提现2当天已经提现过不能再次提现
status = 1
}
case 1:
status = 5
case 2:
status = 3
case 3:
status = 1
}
items = append(items, &v1.PayInitReply_Item{
Id: uint32(biz.PayoutItemId4),
Amount: float64(reply.CheckCoin / 100),
Status: status,
})
reply.Items = items
break
}
log.Infof("PayInit: reply[%+v]", reply)
return reply, nil
}
// Name: "WangChuan",
// Phone: "18117858803",
// Email: "w_windysl@foxmail.com",
// Account: "w_windysl@foxmail.com",
// AccountType: "Email",
// Method: "WALLET",
// Channel: "PayPal",
// CustomCode: "custom_chuan9982674851738119",
// FeeBear: "merchant", //beneficiary , merchant
// Amount: "60000",
// SourceCurrency: "USD",
// ArrivalCurrency: "USD",
// NotifyUrl: "https://notify.url",
// AdditionalRemark: "pagsmile payout chuan test",
// Country: "ALB",
// PayOut
func (s *EonlineService) Payout(ctx context.Context, req *v1.PayoutReq) (*v1.PayoutReply, error) {
fmt.Printf("Payout: req[%+v]\n", req)
log.Infof("Payout: req[%+v]", req)
reply := &v1.PayoutReply{}
for {
// 固定结构体参数
uuid := biz.GenPayoutUuid(req.Deviceid)
// account替换左右空格
req.Account = strings.Trim(req.Account, " ")
if req.Uuid != uuid {
// return nil, fmt.Errorf("uuid error")
reply.Error = 4
break
}
// 验证签名
err := s.validateSignRequest(
v1.PayoutReq{
Platform: req.Platform,
Deviceid: req.Deviceid,
Version: req.Version,
Ip: req.Ip,
Ts: req.Ts,
Sign: req.Sign,
Account: req.Account,
Amount: req.Amount,
AdditionalRemark: req.AdditionalRemark,
Uuid: req.Uuid,
}, biz.SignFixedParameters)
if err != nil {
// return nil, fmt.Errorf("validate request error: %w", err)
reply.Error = 2
break
}
if !checkStrSeconds(req.Ts) {
reply.Error = 24
break
}
if s.conf.Server.Env != "qa" {
req.Ts = strconv.Itoa(int(time.Now().Unix()))
}
ver := config.Version2int(&req.Version)
if ver < config.PublicVersionMin {
// return nil, fmt.Errorf("version [%s] not support", req.Version)
reply.Error = 3
break
}
// 处理请求
bq := &biz.PayoutReq{
Account: req.Account,
Amount: decimal.NewFromFloat(req.Amount).String(),
AdditionalRemark: req.AdditionalRemark,
}
// 业务参数
opts := &biz.PayoutAddtionalReq{
Platform: req.Platform,
DeviceId: req.Deviceid,
Version: req.Version,
Ip: req.Ip,
Amount: req.Amount,
ItemId: req.ItemId,
Account: req.Account,
Ts: req.Ts,
Email: req.Email,
}
x, err, errCode := s.uc.Payout(ctx, uuid, opts, bq)
if err != nil {
log.Infof("Payout error: err[%v]", err)
// return nil, err
reply.Error = errCode
break
}
reply = &v1.PayoutReply{
Id: x.Id,
RecordNo: x.CustomCode,
}
break
}
fmt.Printf("Payout: reply[%+v]", reply)
log.Infof("Payout: reply[%+v]", reply)
return reply, nil
}
// PayoutBrazil
func (s *EonlineService) PayoutBrazil(ctx context.Context, req *v1.PayoutReq) (*v1.PayoutReply, error) {
// fmt.Printf("Payout: req[%+v]\n", req)
log.Infof("PayoutBrazil: req[%+v]", req)
if req.DataAdjust == nil {
log.Infof("PayoutBrazil error: req.DataAdjust is nil Deviceid[%s]", req.Deviceid)
}
if req.DataShuShu == nil {
log.Infof("PayoutBrazil error: req.DataShuShu is nil Deviceid[%s]", req.Deviceid)
}
reply := &v1.PayoutReply{}
bSend := false
for {
// 固定结构体参数
uuid := biz.GenPayoutUuid(req.Deviceid)
// account替换左右空格
req.Account = strings.Trim(req.Account, " ")
if req.Uuid != uuid {
// return nil, fmt.Errorf("uuid error")
reply.Error = 4
break
}
if len(req.DocumentType) < 3 {
// return nil, fmt.Errorf("document_type length error")
reply.Error = 13
break
}
if len(req.DocumentId) < 11 {
// return nil, fmt.Errorf("document_id length error")
reply.Error = 14
break
}
if len(req.AccountType) < 3 {
// return nil, fmt.Errorf("account_type length error")
reply.Error = 15
break
}
if len(req.Name) < 5 {
// return nil, fmt.Errorf("name length error")
reply.Error = 16
break
}
if req.AccountType == req.DocumentType && req.Account != req.DocumentId {
// return nil, fmt.Errorf("The values of account_type and document_type are the same, but the values of account and document_id are different")
reply.Error = 17
break
}
// CPF CNPJ PHONE EMAIL EVP
if req.AccountType == "CPF" {
if len(req.Account) != 11 || !brdoc.IsCPF(req.Account) {
// return nil, fmt.Errorf("account not CPF")
reply.Error = 18
break
}
} else if req.AccountType == "CNPJ" {
if len(req.Account) != 14 || !brdoc.IsCNPJ(req.Account) {
// return nil, fmt.Errorf("account not CNPJ")
reply.Error = 19
break
}
} else if req.AccountType == "PHONE" {
} else if req.AccountType == "EMAIL" {
} else if req.AccountType == "EVP" {
} else {
// return nil, fmt.Errorf("account_type error")
reply.Error = 20
break
}
// One of: CPF, CNPJ
if req.DocumentType == "CPF" {
if len(req.DocumentId) != 11 || !brdoc.IsCPF(req.DocumentId) {
// return nil, fmt.Errorf("document_id not CPF")
reply.Error = 22
break
}
} else if req.DocumentType == "CNPJ" {
if len(req.DocumentId) != 14 || !brdoc.IsCNPJ(req.DocumentId) {
// return nil, fmt.Errorf("document_id not CNPJ")
reply.Error = 23
break
}
} else {
// return nil, fmt.Errorf("document_type error")
reply.Error = 21
break
}
// 验证签名
err := s.validateSignRequest(
v1.PayoutReq{
Platform: req.Platform,
Deviceid: req.Deviceid,
Version: req.Version,
Ip: req.Ip,
Ts: req.Ts,
Sign: req.Sign,
Account: req.Account,
Amount: req.Amount,
AdditionalRemark: req.AdditionalRemark,
Uuid: req.Uuid,
}, biz.SignFixedParameters)
if err != nil {
// return nil, fmt.Errorf("validate request error: %w", err)
reply.Error = 2
break
}
if !checkStrSeconds(req.Ts) {
reply.Error = 24
break
}
if s.conf.Server.Env != "qa" {
req.Ts = strconv.Itoa(int(time.Now().Unix()))
}
if len(req.ClientName) > 0 {
// if strings.EqualFold(req.ClientName, "com.capy.cash.earn.money.fast.real.rewards.game") {
} else {
ver := config.Version2int(&req.Version)
if ver < config.PublicVersionMin {
type Cmd_shushu struct {
AdNetwork string `json:"ad_network"`
}
var shushu Cmd_shushu
err = json.Unmarshal([]byte(req.DataShuShu.SsSuperProperties), &shushu)
if err != nil {
reply.Error = 26
break
}
if strings.EqualFold(shushu.AdNetwork, "Organic") {
// return nil, fmt.Errorf("version [%s] not support", req.Version)
reply.Error = 3
break
}
}
}
// 处理请求
bq := &biz.PayoutReq{
Name: req.Name,
AccountType: req.AccountType,
Account: req.Account,
Document_type: req.DocumentType,
Document_id: req.DocumentId,
Amount: decimal.NewFromFloat(req.Amount).String(),
AdditionalRemark: req.AdditionalRemark,
ClientData: req.ClientData,
}
// 业务参数
opts := &biz.PayoutAddtionalReq{
Platform: req.Platform,
DeviceId: req.Deviceid,
Version: req.Version,
Ip: req.Ip,
Amount: req.Amount,
ItemId: req.ItemId,
Account: req.Account,
Ts: req.Ts,
}
x, err, errCode := s.uc.PayoutBrazil(ctx, uuid, opts, bq)
if err != nil {
log.Infof("PayoutBrazil error: err[%v] deviceid[%s]", err, req.Deviceid)
// return nil, err
reply.Error = errCode
errStr := err.Error()
if strings.Contains(errStr, "Payout error:") {
var currentIp string
httpCtx := xhttp.RequestFromContext(ctx)
if httpCtx != nil {
// 获取当前的IP地址
currentIp = utils.GetClientPublicIP(httpCtx.Request())
}
sendStr := fmt.Sprintf("errCode=%d, %s", errCode, errStr)
adjust := biz.GetAdjustData(req, sendStr, currentIp)
shuShu := biz.GetShuShuData(req, sendStr, currentIp)
biz.SendReport(ctx, adjust, shuShu)
bSend = true
}
// { // 测试用例
// var currentIp string
// httpCtx := xhttp.RequestFromContext(ctx)
// if httpCtx != nil {
// // 获取当前的IP地址
// currentIp = utils.GetClientPublicIP(httpCtx.Request())
// }
// adjust := biz.GetAdjustData(req, "", currentIp)
// shuShu := biz.GetShuShuData(req, "", currentIp)
// if adjust != nil && shuShu != nil {
// shuShu.PayoutId = "TS202309260440574XKGb1AxafqWG"
// shuShu.MerchantReference = "PGS_5c2ca21a78a295b4c10a5bfe0027a4e0"
// biz.AddReportData(shuShu.PayoutId, adjust, shuShu)
// biz.GetReportData(shuShu.PayoutId)
// }
// }
break
}
reply = &v1.PayoutReply{
Id: x.Id,
RecordNo: x.CustomCode,
}
{
var currentIp string
httpCtx := xhttp.RequestFromContext(ctx)
if httpCtx != nil {
// 获取当前的IP地址
currentIp = utils.GetClientPublicIP(httpCtx.Request())
}
adjust := biz.GetAdjustData(req, "", currentIp)
shuShu := biz.GetShuShuData(req, "", currentIp)
if adjust != nil && shuShu != nil {
shuShu.PayoutId = x.Id
shuShu.MerchantReference = x.CustomCode
biz.AddReportData(x.Id, adjust, shuShu)
}
}
break
}
log.Infof("PayoutBrazil: reply[%+v]", reply)
if reply.Error != 0 && !bSend {
var currentIp string
httpCtx := xhttp.RequestFromContext(ctx)
if httpCtx != nil {
// 获取当前的IP地址
currentIp = utils.GetClientPublicIP(httpCtx.Request())
}
sendStr := fmt.Sprintf("errCode=%d", reply.Error)
adjust := biz.GetAdjustData(req, sendStr, currentIp)
shuShu := biz.GetShuShuData(req, sendStr, currentIp)
biz.SendReport(ctx, adjust, shuShu)
}
return reply, nil
}
// PayoutCallback
func (s *EonlineService) PayoutCallback(ctx context.Context, req *v1.PayoutCallbackReq) (*v1.PayoutCallbackReply, error) {
// fmt.Printf("PayoutCallback: req[%+v]\n", req)
log.Infof("PayoutCallback: req[%+v]", req)
err := s.uc.PayoutNotify(ctx, &biz.PayoutNotifyReq{
PayoutId: req.PayoutId,
CustomCode: req.CustomCode,
Status: req.Status,
Msg: req.Msg,
Timestamp: req.Timestamp,
})
reply := &v1.PayoutCallbackReply{
Message: "success",
}
log.Infof("PayoutCallback: reply[%+v]", reply)
return reply, err
}
// PayoutCheck 检查支付状态
func (s *EonlineService) PayoutCheck(ctx context.Context, req *v1.PayoutCheckReq) (*v1.PayoutCheckReply, error) {
// fmt.Printf("PayoutCheck: req[%+v]\n", req)
log.Infof("PayoutCheck: req[%+v]", req)
reply := &v1.PayoutCheckReply{}
for {
// 固定结构体参数
// 验证签名
err := s.validateSignRequest(
v1.PayoutCheckReq{
Platform: req.Platform,
Deviceid: req.Deviceid,
Version: req.Version,
Ip: req.Ip,
Ts: req.Ts,
Sign: req.Sign,
}, biz.SignFixedParameters)
if err != nil {
// return nil, fmt.Errorf("validate request error: %w", err)
reply.Error = 2
break
}
if !checkStrSeconds(req.Ts) {
reply.Error = 4
break
}
if s.conf.Server.Env != "qa" {
req.Ts = strconv.Itoa(int(time.Now().Unix()))
}
// ver := config.Version2int(&req.Version)
// if ver < config.PublicVersionMin {
// // return nil, fmt.Errorf("version [%s] not support", req.Version)
// reply.Error = 3
// break
// }
// 处理请求
status, err := s.uc.PayoutCheck(ctx, req.RecordNo)
if err != nil {
log.Infof("PayoutCheck error: err[%v]", err)
reply.Error = 1
break
}
reply = &v1.PayoutCheckReply{
Status: uint32(status),
}
break
}
log.Infof("PayoutCheck: reply[%+v]", reply)
return reply, nil
}
func (s *EonlineService) GetPayoutUserLst(ctx context.Context, req *v1.PayoutUserLstReq) (*v1.PayoutUserLstReply, error) {
log.Infof("GetPayoutUserLst: req[%+v]", req)
reply := &v1.PayoutUserLstReply{}
for {
// 验证签名
err := s.validateSignRequest(
v1.PayInitReq{
Platform: req.Platform,
Deviceid: req.Deviceid,
Version: req.Version,
Ip: "",
Ts: req.Ts,
Sign: req.Sign,
}, biz.SignFixedParameters)
if err != nil {
reply.Error = 2
break
}
if !checkStrSeconds(req.Ts) {
reply.Error = 4
break
}
if req.PageIndex > 0 {
req.PageIndex -= 1
}
if req.PageSize <= 0 {
req.PageSize = 2000
}
records, err := s.uc.GetPayoutRecordByAccount(ctx, "", int(req.Status), int(req.PageIndex), int(req.PageSize))
if err != nil {
log.Infof("GetPayoutRecordByAccount error[%+v]", err)
reply.Error = 3
break
}
for _, record := range records {
reply.Lst = append(reply.Lst, &v1.PayoutUserOne{
Email: record.Email,
RecordNo: record.RecordNo,
Account: record.Account,
Status: uint32(record.Status),
})
}
break
}
log.Infof("GetPayoutUserLst: reply[%+v]", reply)
return reply, nil
}
func (s *EonlineService) SetPayoutStatus(ctx context.Context, req *v1.PayoutStatusReq) (*v1.PayoutStatusReply, error) {
log.Infof("SetPayoutStatus: req[%+v]", req)
reply := &v1.PayoutStatusReply{
RecordNo: req.RecordNo,
Status: req.Status,
}
for {
// 验证签名
err := s.validateSignRequest(
v1.PayInitReq{
Platform: req.Platform,
Deviceid: req.Deviceid,
Version: req.Version,
Ip: "",
Ts: req.Ts,
Sign: req.Sign,
}, biz.SignFixedParameters)
if err != nil {
reply.Error = 2
break
}
if !checkStrSeconds(req.Ts) {
reply.Error = 4
break
}
var status string
if req.Status == 2 {
status = "PAID"
} else if req.Status == 3 {
status = "REJECTED"
} else {
reply.Error = 5
break
}
err = s.uc.PayoutNotify2(ctx, &biz.PayoutNotifyReq{
PayoutId: "Test",
CustomCode: req.RecordNo,
Status: status,
Msg: req.Fail,
Timestamp: time.Now().Unix(),
})
if err != nil {
log.Infof("SetPayoutStatus: PayoutNotify2 err[%v]", err)
reply.Error = 3
break
}
break
}
log.Infof("SetPayoutStatus: reply[%+v]", reply)
return reply, nil
}
func (s *EonlineService) Init(data *data.Data) {
lst := config.GetUserStateData()
log.Infof("EonlineService Init: TbuserState\n%+v", lst)
if len(lst) > 0 {
// 将配置表的审核结果导入redis
var err error
var key, key2, val string
ctx := context.Background()
for _, v := range lst {
key = biz.GetCheckResultRedisKey(v.Paypal)
val, err = data.GetValue(ctx, key)
if err == nil {
if val != biz.StringNull {
log.Infof("EonlineService Init redis has key[%s] value[%s]", v.Paypal, val)
if val == biz.CheckResultSuccess {
continue
}
}
// 没有key值的或者 值为0的写入新值以前的值为1的不写入
if val == biz.StringNull || (val == biz.CheckResultFail && v.State != 0) {
log.Infof("EonlineService Init key[%s] value[%s]=>[%d]", v.Paypal, val, v.State)
err = data.WriteValue(ctx, key, v.State, 0)
if err != nil {
log.Infof("EonlineService Init error: write key[%s] [%d] error[%s]", key, v.State, err.Error())
}
}
if v.State == 0 {
key2 = biz.GetCheckResultFailRedisKey(v.Paypal)
err = data.WriteValue(ctx, key2, v.Couse, 0)
if err != nil {
log.Infof("EonlineService Init error: write key[%s] [%s] error[%s]", key2, v.Couse, err.Error())
}
}
} else {
log.Infof("EonlineService Init error: read key[%s] error[%s]", v.Paypal, err.Error())
}
}
}
// biz.PayoutItemIdAmountes[biz.PayoutItemId4] = float64(config.PublicCheckCoin / 100)
// log.Infof("PayoutItemIdAmountes[%d]=%f", biz.PayoutItemId4, biz.PayoutItemIdAmountes[biz.PayoutItemId4])
log.Infof("EonlineService Init finished")
}
// 提交身份文件验证请求
func (s *EonlineService) SubmitCheck(ctx context.Context, req *v1.SubmitCheckReq) (*v1.SubmitCheckReply, error) {
log.Infof("SubmitCheck: req[%+v]", req)
result, err := s.uc.SubmitCheck(ctx, &biz.SubmitCheckReq{
Account: req.Account,
Uuid: req.Uuid,
})
if err != nil {
return nil, fmt.Errorf("validate request error: %w", err)
}
reply := &v1.SubmitCheckReply{
Result: result.Result,
}
log.Infof("SubmitCheck: reply[%+v]", reply)
return reply, nil
}
func (s *EonlineService) CheckInfo(ctx context.Context, req *v1.CheckInfoReq) (*v1.CheckInfoReply, error) {
log.Infof("CheckInfo: req[%+v]", req)
// 验证签名
err := s.validateSignRequest(
v1.PayInitReq{
Platform: req.Platform,
Deviceid: req.Deviceid,
Version: req.Version,
Ip: req.Ip,
Ts: req.Ts,
Sign: req.Sign,
}, biz.SignFixedParameters)
if err != nil {
return nil, fmt.Errorf("validate request error: %w", err)
}
if !checkStrSeconds(req.Ts) {
reply := &v1.CheckInfoReply{Error: 2}
return reply, nil
}
req.Ts = strconv.Itoa(int(time.Now().Unix()))
// 生成唯一用户ID
uuid := biz.GenPayoutUuid(req.Deviceid)
if uuid != req.Uuid {
return nil, fmt.Errorf("uuid [%s] error", req.Uuid)
}
x, err := s.uc.CheckInfo(ctx, &biz.CheckInfoReq{
Uuid: uuid,
Ts: req.Ts,
})
if err != nil {
return nil, fmt.Errorf("error: %w", err)
}
reply := &v1.CheckInfoReply{
CanCheckSubmit: int32(x.CanCheckSubmit),
CheckSubmit: x.CheckSubmit,
CheckResult: x.CheckResult,
CheckPayout: x.CheckPayout,
CheckCoin: config.PublicCheckCoin,
CanCheckPayOut: x.CanCheckPayOut,
CheckResultFailedDesc: x.CheckResultFailedDesc,
}
log.Infof("CheckInfo: reply[%+v]", reply)
return reply, nil
}
func (s *EonlineService) AddChat(ctx context.Context, req *v1.AddChatReq) (*v1.AddChatReply, error) {
log.Infof("AddChat: req[%+v]", req)
// 验证签名
err := s.validateSignRequest(
v1.PayInitReq{
Platform: req.Platform,
Deviceid: req.Deviceid,
Version: req.Version,
Ip: req.Ip,
Ts: req.Ts,
Sign: req.Sign,
}, biz.SignFixedParameters)
if err != nil {
return nil, fmt.Errorf("validate request error: %w", err)
}
if !checkStrSeconds(req.Ts) {
reply := &v1.AddChatReply{Result: 2}
return reply, nil
}
if s.conf.Server.Env != "qa" {
req.Ts = strconv.Itoa(int(time.Now().Unix()))
}
// ver := config.Version2int(&req.Version)
// if ver < config.PublicVersionMin {
// return nil, fmt.Errorf("version [%s] not support", req.Version)
// }
// 生成唯一用户ID
uuid := biz.GenPayoutUuid(req.Deviceid)
if uuid != req.Uuid {
return nil, fmt.Errorf("uuid [%s] error", req.Uuid)
}
reply := &v1.AddChatReply{
Uuid: uuid,
Result: 0,
}
biz.AddChat(req)
reply.Lst = biz.GetChat(req.TimeStamp)
// log.Infof("AddChat: reply[%+v]", reply)
return reply, nil
}
func (s *EonlineService) GetChat(ctx context.Context, req *v1.GetChatReq) (*v1.GetChatReply, error) {
log.Infof("GetChat: req[%+v]", req)
// 验证签名
err := s.validateSignRequest(
v1.PayInitReq{
Platform: req.Platform,
Deviceid: req.Deviceid,
Version: req.Version,
Ip: req.Ip,
Ts: req.Ts,
Sign: req.Sign,
}, biz.SignFixedParameters)
if err != nil {
return nil, fmt.Errorf("validate request error: %w", err)
}
if s.conf.Server.Env != "qa" {
req.Ts = strconv.Itoa(int(time.Now().Unix()))
}
// ver := config.Version2int(&req.Version)
// if ver < config.PublicVersionMin {
// return nil, fmt.Errorf("version [%s] not support", req.Version)
// }
// 生成唯一用户ID
uuid := biz.GenPayoutUuid(req.Deviceid)
if uuid != req.Uuid {
return nil, fmt.Errorf("uuid [%s] error", req.Uuid)
}
reply := &v1.GetChatReply{
Uuid: uuid,
}
reply.Lst = biz.GetChat(req.TimeStamp)
// log.Infof("AddChat: reply[%+v]", reply)
return reply, nil
}