专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > ASP.NET

求Paypal的支付接口C#的·有的哥们给个吧·多谢

发布时间:2011-06-22 17:13:33 文章来源:www.iduyao.cn 采编人员:星星草
求Paypal的支付接口C#的·有的哥们给个吧·谢谢
RT

------解决方案--------------------
支付接口谁能给啊 比如要用支付宝接口,你就得去他公司申请的
------解决方案--------------------
1.到https://developer.paypal.com注册一个开发帐号,好了之后再进入Sandbox建立测试用的Paypal虚拟帐号(至少应该建立一个Business的和一个Personal的),信息可以是假的,注意:这里的至少两个测试帐号是在你所建立的开发帐号里面建立的,不要注册错了;

2.测试是很麻烦,但是是必不可少的,因为如果客户买过一次出错之后,就不会来第二次了,所以花半天时间做测试是很重要的;

3.代码帖出来给大家参考一下,我做的是不很细,支付成功后返回的结果我就没有做,因为我在测试的时候已经没有问题了,所以没有做,改天有空会完善的;
 
 
ASP.Net/C#
 
C# code

using System;
using System.IO;
using System.Text;
using System.Net;
using System.Web;

public partial class csIPNexample :System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);

// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;

//for proxy
//WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
//req.Proxy = proxy;

//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();

if (strResponse == "VERIFIED")
{
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strResponse == "INVALID")
{
// log for manual investigation
}
else
{
//log response/ipn data for manual investigation
}
}
}
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: