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.
157 lines
4.1 KiB
157 lines
4.1 KiB
using System;
|
|
|
|
|
|
namespace Sog
|
|
{
|
|
public static class PayUtils
|
|
{
|
|
private static long m_OrderIdSeq = 0;
|
|
|
|
/// <summary>
|
|
/// uid - time - orderSeq - serverId - itemId - param1 - param2 - paymentId - payUrlId
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <returns></returns>
|
|
public static string GenOrderIdForUser(long uid,uint serverId, int itemId, int p1, int p2,
|
|
string paymentId,long payTime = 0)
|
|
{
|
|
long timeNow = payTime > 0 ? payTime : AppTime.GetNowSysSecond();
|
|
m_OrderIdSeq++;
|
|
|
|
string transParam1 = "";
|
|
if (p1 < 0)
|
|
{
|
|
transParam1 = string.Format("{0}=",-1 * p1);
|
|
}
|
|
|
|
return string.Format("{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}"
|
|
, uid, timeNow, m_OrderIdSeq, serverId, itemId, p1 >= 0 ? p1:transParam1, p2, paymentId);
|
|
}
|
|
public static string GenSimpleOrderIdForUser(long uid, int itemId, long payTime = 0)
|
|
{
|
|
long timeNow = payTime > 0 ? payTime : AppTime.GetNowSysSecond();
|
|
m_OrderIdSeq++;
|
|
if (m_OrderIdSeq > 9999)
|
|
{
|
|
m_OrderIdSeq = 1;
|
|
}
|
|
if(itemId > 9999)
|
|
{
|
|
itemId = itemId % 10000;
|
|
}
|
|
return string.Format("{0}-{1}-{2}--{3}---"
|
|
, uid, timeNow, m_OrderIdSeq, itemId);
|
|
}
|
|
/// <summary>
|
|
/// 根据交易id获取时间,如果id非法返回0
|
|
/// </summary>
|
|
/// <param name="orderId"></param>
|
|
/// <returns></returns>
|
|
public static long GetTimeFromOrderId(string orderId)
|
|
{
|
|
string[] split = orderId.Split('-');
|
|
|
|
if(split.Length < 4)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
string strTime = split[1];
|
|
if(string.IsNullOrEmpty(strTime))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
long lTime = 0;
|
|
bool bSuccess = long.TryParse(strTime, out lTime);
|
|
if(bSuccess == false)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return lTime;
|
|
|
|
}
|
|
|
|
public static int GetItemIdFromOrderId(string orderId)
|
|
{
|
|
string[] split = orderId.Split('-');
|
|
|
|
if (split.Length < 5)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return int.Parse(split[4]);
|
|
}
|
|
|
|
public static long GetUidFromOrderId(string orderId)
|
|
{
|
|
string[] split = orderId.Split('-');
|
|
|
|
if (split.Length < 5)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
long uid = 0;
|
|
bool bSuccess = long.TryParse(split[0], out uid);
|
|
if (bSuccess == false)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return uid;
|
|
}
|
|
public static long GetParam1FromOrderId(string orderId)
|
|
{
|
|
string[] split = orderId.Split('-');
|
|
|
|
if (split.Length < 6)
|
|
{
|
|
return 0;
|
|
}
|
|
string[] split2 = split[5].Split("=");
|
|
long param1 = 0;
|
|
bool bSuccess = false;
|
|
if (split2.Length == 1)
|
|
{
|
|
bSuccess = long.TryParse(split2[0], out param1);
|
|
if (bSuccess == false)
|
|
{
|
|
return 0;
|
|
}
|
|
return param1;
|
|
}
|
|
else if(split2.Length > 0)
|
|
{
|
|
bSuccess = long.TryParse(split2[0], out param1);
|
|
if (bSuccess == false)
|
|
{
|
|
return 0;
|
|
}
|
|
return param1 * -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static long GetParam2FromOrderId(string orderId)
|
|
{
|
|
string[] split = orderId.Split('-');
|
|
|
|
if (split.Length < 7)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
long param2 = 0;
|
|
bool bSuccess = long.TryParse(split[6], out param2);
|
|
if (bSuccess == false)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return param2;
|
|
}
|
|
}
|
|
}
|
|
|