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.
 
 
 
 
 
 

169 lines
6.4 KiB

using LitJson;
using Sog;
using ProtoCSStruct;
namespace Game
{
public static class HuaweiPaySvc
{
public static void OnCltPaySuccessReq(PlayerOnGame player, ref CSPayGoogleSuccessReq req, bool gmTestPay)
{
int ret = OnPaySuccessReq(player, ref req, gmTestPay);
if (ret != 0)
{
var res = new CSPayGoogleSuccessRes { Ret = -1, Uid = player.UserID };
res.OrderId.SetString(req.OrderId.GetPtr());
player.SendToClient((int)CSGameMsgID.PayGoogleSuccessRes, ref res);
}
}
private static int OnPaySuccessReq(PlayerOnGame player, ref CSPayGoogleSuccessReq payReq, bool gmTestPay)
{
// 英雄支付不能由客户端发起支付成功的消息
PayType payType = PlayerPayUtil.GetPlayerPayType(player);
if (payType != PayType.Huawei)
{
TraceLog.Error("HuaweiPaySvc.OnPaySuccessReq uid {0} invalid payType {1}", player.UserID, payType);
return -1;
}
string purchaseData = payReq.PurchaseData.GetString();
string signature = payReq.Signature.GetString();
TraceLog.Debug("HuaweiPaySvc.OnPaySuccessReq uid {0} PurchaseData {1} Signature {2}"
, payReq.Uid, purchaseData, signature);
// 获取游戏内部自己的订单号
JsonData jsonData = JsonMapper.ToObject(purchaseData);
if (jsonData == null)
{
TraceLog.Error("HuaweiPaySvc.OnPaySuccessReq uid {0} invalid payType {1}", player.UserID, payType);
return -1;
}
JsonData payload = jsonData["developerPayload"];
if (payload == null)
{
TraceLog.Error("HuaweiPaySvc.OnPaySuccessReq uid {0} no orderId in PurchaseData", player.UserID);
return -1;
}
JsonData order3rd = jsonData["orderId"];
if (order3rd == null)
{
TraceLog.Error("HuaweiPaySvc.OnPaySuccessReq uid {0} no orderId3rd in PurchaseData", player.UserID);
return -1;
}
string orderId = payload.ToString();
string orderId3rd = order3rd.ToString();
// uid-time-orderIdSeq-serverId-payitemId-payParam1-payParam2-paymentId-payUrlId
string[] split = orderId.Split('-');
if (split.Length < 9)
{
TraceLog.Error("HuaweiPaySvc.OnPaySuccessReq invalid orderId {0}, need >= 9 params", orderId);
return -1;
}
int itemId = int.Parse(split[4]);
string goodsId = split[7];
JsonData productIdJson = jsonData["productId"];
if (productIdJson == null)
{
TraceLog.Error("HuaweiPaySvc.OnPaySuccessReq PurchaseData no [productId]");
return -1;
}
string productId = productIdJson.ToString();
if (string.IsNullOrEmpty(productId) || !goodsId.Equals(productId))
{
TraceLog.Error("HuaweiPaySvc.OnPaySuccessReq goodsId {0} productId {1} not same", goodsId, productId);
return -1;
}
PayDiamondDesc desc = PayCommSvc.GetPayDiamondDesc(itemId);
if (desc == null)
{
TraceLog.Error("HuaweiPaySvc.OnPaySuccessReq uid {0} invalid itemId {1}", payReq.Uid, itemId);
return -1;
}
if (! long.TryParse(split[0], out long uidInOrderId))
{
TraceLog.Error("HuaweiPaySvc.OnPaySuccessReq invalid uid {0}", split[0]);
return -1;
}
//这个订单号是不是这个用户的
if (player.UserID != uidInOrderId)
{
player.Error("HuaweiPaySvc.OnPaySuccessReq orderId {0} uid {1} orderUid {2} not same"
, orderId, player.UserID, uidInOrderId);
return -1;
}
if (!int.TryParse(split[5], out int payParam1) || !int.TryParse(split[6], out int payParam2))
{
TraceLog.Error("HuaweiPaySvc.OnPaySuccessReq invalid payParam1 {0} payParam2 {1}", split[5], split[6]);
return -1;
}
// 发到httpPay去校验payToken和订单状态
ref SSPayGoogleSuccessReq ssReq = ref CSStructPool<SSPayGoogleSuccessReq>.Instance.GetObjRef();
ssReq.Uid = player.UserID;
ssReq.PurchaseData.SetString(purchaseData);
ssReq.Signature.SetString(signature);
ssReq.OrderId.SetString(orderId);
ssReq.PayType = (int)PayType.Huawei;
ssReq.ItemID = desc.itemID;
ssReq.OrderId3rd.SetString(orderId3rd);
ssReq.GmTestPay = gmTestPay;
ssReq.PayParam1 = payParam1;
ssReq.PayParam2 = payParam2;
ssReq.Currency.SetString(jsonData["currency"].ToString());
// 华为的支付时间是毫秒
if (long.TryParse(jsonData["purchaseTime"].ToString(), out long purchaseTime))
{
ssReq.PayTime3rd = purchaseTime/1000;
}
GameBillLogUtils.LogPayGoogleSuccessReq(ref ssReq);
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.PayGoogleSuccessReq, ref ssReq, player.UserID);
return 0;
}
//public static int FillSSPayGoogleSuccReqByPurchaseData(string purchaseData, ref SSPayGoogleSuccessReq req)
//{
// JsonData jsonData = JsonMapper.ToObject(purchaseData);
// if (jsonData == null)
// {
// TraceLog.Error("HuaweiPaySvc.FillSSPayGoogleSuccReqByPurchaseData invalid purchaseData");
// return -1;
// }
// req.PurchaseData.SetString(purchaseData);
// JsonData payload = jsonData["developerPayload"];
// if (payload != null)
// {
// req.OrderId.SetString(payload.ToString());
// }
// JsonData order3rd = jsonData["orderId"];
// if (order3rd != null)
// {
// req.OrderId3rd.SetString(order3rd.ToString());
// }
// req.ItemID.SetString(desc.itemID);
// req.PayParam1 = payParam1;
// req.PayParam2 = payParam2;
//}
}
}