You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

290 lines
12 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using ProtoCSStruct;
namespace World
{
public static class PaySvc
{
public static void OnGooglePayReq(uint serverId, StructPacket packet)
{
ref SSPayGoogleReq req = ref packet.GetMessage<SSPayGoogleReq>();
long uid = req.Uid;
TraceLog.Debug("PaySvc.OnGooglePayReq uid {0} itemId {1} orderId", req.Uid, req.ItemID, req.OrderId);
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
if(player == null)
{
TraceLog.Error("PaySvc.OnGooglePayReq can not find player uid {0}", uid);
return;
}
//做一下频率限制等的校验,免得外挂太疯狂
int ret = CheckPayCount(player);
if(ret != 0)
{
TraceLog.Error("PaySvc.OnGooglePayReq uid {0} CheckPayCount failed ret {1}", uid, ret);
SSPayGoogleRes res = new SSPayGoogleRes
{
Uid = req.Uid,
Money = req.Money,
Diamond = req.Diamond,
PayType = req.PayType,
GmTestPay = req.GmTestPay,
Ret = ret,
};
res.ItemID = req.ItemID;
res.OrderId.SetString(req.OrderId.GetPtr());
res.PaymentId.SetString(req.PaymentId.GetPtr());
WorldServerUtils.GetPacketSender().SendToServerByID(serverId, (int)SSGameMsgID.PayGoogleRes, ref res, uid);
return;
}
// 转给HttpPay处理, HttpPay需要保存player的worldId
//WorldServerUtils.GetPacketSender().SendToHttpProxyPayServer<SSPayGoogleReq>(packet);
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayGoogleReq>(
AccountServerSelect.SelectFirstAccountServer(), packet, packet.ObjectID);
}
public static void OnGooglePayRes(uint serverId, StructPacket packet)
{
ref SSPayGoogleRes res = ref packet.GetMessage<SSPayGoogleRes>();
TraceLog.Debug("PaySvc.OnGooglePayRes uid {0}, orderid {1} ret {2}", res.Uid, res.OrderId, res.Ret);
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(res.Uid);
if (player == null)
{
TraceLog.Error("PaySvc.OnGooglePayRes no player uid {0}", res.Uid);
return;
}
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayGoogleRes>(player.GameServerID, packet);
}
// worldsvr直接转发给httpPaySvr校验即可
//public static void OnGooglePaySuccessReq(uint serverId, StructPacket packet)
//{
// ref SSPayGoogleSuccessReq req = ref packet.GetMessage<SSPayGoogleSuccessReq>();
// long uid = req.Uid;
// TraceLog.Debug("PaySvc.OnGooglePaySuccessReq uid {0}, Signature {1}", req.Uid, req.Signature);
// PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
// if (player == null)
// {
// TraceLog.Error("PaySvc.OnGooglePaySuccessReq can not find player uid {0}", uid);
// return;
// }
// if (ServerIDUtils.GetServerType(serverId) == (int)ServerType.Game)
// {
// //配置了不校验,或者是gm指令测试支付,直接转给db
// if (WorldServerUtils.GetServerConfig().noCheckGooglePayPublicKey == 1
// || req.GmTestPay == true)
// {
// //转给HttpPay
// WorldServerUtils.GetPacketSender().SendToHttpProxyPayServer<SSPayGoogleSuccessReq>(packet);
// return;
// }
// if (req.PayType == (uint)PayType.IAP)
// {
// //转给HttpPay
// WorldServerUtils.GetPacketSender().SendToHttpProxyPayServer<SSPayGoogleSuccessReq>(packet);
// }
// else if (req.PayType == (uint)PayType.Google)
// {
// //直接在这里校验
// string publicKeyBase64 = WorldServerUtils.GetServerConfig().googlePayPublicKey;
// bool bCheckSuccess = GooglePayCheck.CheckGooglePay(req.PurchaseData.ToString(), req.Signature.ToString(), publicKeyBase64);
// if (bCheckSuccess == false)
// {
// player.PayInfo.PayGoogleSuccessReqFailedCount++;
// TraceLog.Error("PaySvc.OnGooglePaySuccessReq uid {0}, check purchaseData signature {1} failed PayGoogleSuccessReqFailedCount {2}"
// , uid, req.Signature
// , player.PayInfo.PayGoogleSuccessReqFailedCount);
// SSPayGoogleSuccessRes res = new SSPayGoogleSuccessRes();
// res.Uid = req.Uid;
// res.Ret = -1;
// WorldServerUtils.GetPacketSender().SendToServerByID(serverId, (int)SSGameMsgID.PayGoogleSuccessRes, ref res, packet.ObjectID);
// return;
// }
// req.OrderId.SetString(Sog.Crypto.GooglePaySecurity.GetOrderIdFromPurchaseData(req.PurchaseData.ToString()));
// if (req.OrderId.Count == 0)
// {
// TraceLog.Error("PaySvc.OnGooglePaySuccessReq uid {0}, GetOrderIdFromPurchaseData failed", uid);
// return;
// }
// //转给HttpPay
// WorldServerUtils.GetPacketSender().SendToHttpProxyPayServer<SSPayGoogleSuccessReq>(packet);
// }
// }
// else if (ServerIDUtils.GetServerType(serverId) == (int)ServerType.HttpProxyPay)
// {
// //成功是1,其他都是失败
// if (req.CheckSuccess3rd != 1)
// {
// TraceLog.Error("PaySvc.OnGooglePaySuccessReq uid {0}, CheckSuccess3Rd failed orderId {1} orderId3rd {2}"
// , uid, req.OrderId, req.OrderId3rd);
// //失败了,通知game
// SSPayGoogleSuccessRes res = new SSPayGoogleSuccessRes
// {
// Ret = -1,
// ItemID = req.ItemID,
// OrderId = req.OrderId,
// OrderId3rd = req.OrderId3rd,
// PayType = req.PayType,
// Uid = req.Uid,
// PayParam1 = req.PayParam1,
// PayParam2 = req.PayParam2,
// PayTime3rd = req.PayTime3rd,
// Currency = req.Currency,
// Amount = req.Amount,
// };
// WorldServerUtils.GetPacketSender().SendToServerByID(player.GameServerID, (int)SSGameMsgID.PayGoogleSuccessRes, ref res, req.Uid);
// }
// }
//}
public static void OnGooglePaySuccessRes(uint serverId, StructPacket packet)
{
ref SSPayGoogleSuccessRes res = ref packet.GetMessage<SSPayGoogleSuccessRes>();
long uid = res.Uid;
TraceLog.Debug("PaySvc.OnGooglePaySuccessRes uid {0} ret {1}", uid, res.Ret);
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
// 如果player不存在, 后续player上线会发起重试
if (player == null)
{
TraceLog.Trace("PaySvc.OnGooglePaySuccessRes uid {0} no player", uid);
return;
}
// 支付成功
if (res.Ret == 0)
{
}
else
{
if (res.PayType != (int)PayType.Google)
{
player.PayInfo.PayGoogleSuccessReqFailedCount++;
}
TraceLog.Debug("PaySvc.OnGooglePaySuccessRes uid {0} ret {1} PayGoogleSuccessReqFailedCount {2}"
, uid, res.Ret, player.PayInfo.PayGoogleSuccessReqFailedCount);
}
//转给game
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayGoogleSuccessRes>(player.GameServerID, packet);
}
public static void OnPayAddDiamondSuccReq(uint serverId, StructPacket packet)
{
//转给httpProxy
WorldServerUtils.GetPacketSender().SendToHttpProxyPayServer<SSPayDBAddDiamondStatusReq>(packet);
}
public static void OnPayAddDiamondSuccRes(uint serverId, StructPacket packet)
{
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
if (player == null)
{
TraceLog.Trace("PaySvc.OnPayAddDiamondSuccRes uid {0} no player", packet.ObjectID);
return;
}
//转给game
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayDBAddDiamondStatusRes>(player.GameServerID, packet);
}
public static int CheckPayCount(PlayerInfoWorld player)
{
ref PayInfoWorld payInfo = ref player.PayInfo;
long nowSecond = WorldServerUtils.GetTimeSecond();
//初始化
if(payInfo.LastCheckTime == 0)
{
payInfo.LastCheckTime = nowSecond;
payInfo.PayCountToday++;
return 0;
}
//不是同一天了
if(AppTime.IsSameDay(nowSecond, payInfo.LastCheckTime) == false)
{
payInfo.LastCheckTime = nowSecond;
payInfo.PayCountToday = 1;
return 0;
}
//同一天,每次请求至少间隔几秒吧,玩家动作有这么快吗?
if(nowSecond < payInfo.LastCheckTime + 2)
{
TraceLog.Error("PaySvc.CheckPayCount uid {0} req too frequent", player.UserID);
return -1;
}
//一天最多支付500次
if (payInfo.PayCountToday >= 500)
{
TraceLog.Error("PaySvc.CheckPayCount uid {0} PayCountToday {1} >= 500"
, player.UserID, payInfo.PayCountToday);
return -2;
}
//这个按理说应该为0,搞的这么大应该就是外挂了
if(payInfo.PayGoogleSuccessReqFailedCount >= 20)
{
TraceLog.Error("PaySvc.CheckPayCount uid {0} PayGoogleSuccessReqFailedCount {1}"
, player.UserID, payInfo.PayGoogleSuccessReqFailedCount);
//在这里封号处理
return -3;
}
payInfo.PayCountToday++;
return 0;
}
public static void NotifyGameSvrItemStockInfo(int realmId, ItemStockInfoOne stockInfo)
{
var notify = new SSNotifyItemStockInfo{RealmId = realmId};
notify.ItemInfo.ItemID = stockInfo.itemId;
notify.ItemInfo.Count = stockInfo.remainCount;
uint[] serverIDs = WorldServerUtils.GetApp().GetCluster().GetRemoteAppID((int)ServerType.Game);
foreach (uint svrId in serverIDs)
{
WorldServerUtils.GetPacketSender().SendToServerByID(svrId,
(int)SSGameMsgID.NotifyItemStockInfo, ref notify, 0);
}
}
}
}