您可以將ID作爲整數與「令牌」一起傳遞,該令牌將是購物車ID和隨機祕密字符串的(密碼強的)散列。支付處理器會知道祕密,所以它可以執行散列本身並進行比較以查看它是否有效。
例如,你可以使用下面的(未經測試)代碼來創建令牌:
public static string GenerateHash(long CartID)
{
string SourceText = CartID.ToString();
//Salt the source text (secret)
SourceText += "5E95C91F7F947BD92ACA2CF81C3ADBD9B563839D85EA69F9DEA5A2DC330D0F50";
//Create an encoding object to ensure the encoding standard for the source text
UnicodeEncoding Ue = new UnicodeEncoding();
//Retrieve a byte array based on the source text
byte[] ByteSourceText = Ue.GetBytes(SourceText);
//Instantiate an MD5 Provider object
System.Security.Cryptography.SHA1CryptoServiceProvider SHA1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
//Compute the hash value from the source
byte[] ByteHash = SHA1.ComputeHash(ByteSourceText);
//And convert it to String format for return, also modify for URL use
return Convert.ToBase64String(ByteHash).Replace("=", "").Replace("+", "-").Replace("/", "_");
}
結果傳遞這個功能,你的車ID一起,因爲哈希是一個單向函數不能逆轉。在付款處理器上,您可以在傳入的購物車ID上調用相同的功能,並將其與令牌進行比較。
這將防止篡改查詢字符串,但允許您使用整數。
他們在不同的域名? – Fosco 2010-07-14 13:06:49
他們在同一個域上。 – NYSystemsAnalyst 2010-07-14 13:14:52