这是我的IPN监听器,我的所有购买都是成功的,但是当涉及到更新数据库时,没有任何反应。我甚至没有尝试使用帖子中的任何数据,只是一个简单的测试'插入
[HttpPost]
public async Task<ActionResult> Ipn()
{
var ipn = Request.Form.AllKeys.ToDictionary(k => k, k => Request[k]);
ipn.Add("cmd", "_notify-validate");
var isIpnValid = await ValidateIpnAsync(ipn);
if (isIpnValid)
{
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO paypal(transaction_id) VALUES('Test')", con);
cmd.ExecuteNonQuery();
con.Close();
}
return new EmptyResult();
}
private static async Task<bool> ValidateIpnAsync(IEnumerable<KeyValuePair<string, string>> ipn)
{
using (var client = new HttpClient())
{
const string PayPalUrl = "https://www.paypal.com/cgi-bin/webscr";
// This is necessary in order for PayPal to not resend the IPN.
await client.PostAsync(PayPalUrl, new StringContent(string.Empty));
var response = await client.PostAsync(PayPalUrl, new FormUrlEncodedContent(ipn));
var responseString = await response.Content.ReadAsStringAsync();
return (responseString == "VERIFIED");
}
}