All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET,2.0,AJAX中Webservice调用方法示例_.net资料_编程技术
[delphi语法4]数据类型:枚举类型
XML WebService完全实例详细解析_[XML教程]
数据库维护_[SQL,Server教程]
新标准的熟悉和入门_[Html教程]
DropDownList绑定数据库字段获取下拉列表值_[Asp.Net教程]
如何使用PHP和PEAR进行不同时区的转换_php资料_编程技术
SQL Server数据库开发要注意的21点_[SQL Server教程]
使用PHP的Socket写的POP3类_[PHP教程]
PHP实例:PHP采集百度音乐程序_[PHP教程]
Reading number is top 10 pictures
China's first snake village2
含苞欲放的素颜美少女1
战场废物2
BingBingFan apple dew point photo gallery2
男人,就要活出棱角
Fierce! China's special forces training the devil2
BingBingFan apple dew point photo gallery5
狗狗与主人神同步2
Sora aoi in China3
美丽的桂林风光1
Download software ranking
Unix video tutorial14
jdk1.6 for windows
Proficient in JavaScript
Tram sex maniac 2 (H) rar bag15
星际争霸1.08硬盘免安装版
Professional killers2 data package
VC++6.0简体中文版
Eclipse 4.2.2 For Win32
Unix video tutorial12
C#编程思想
aaa published in(发表于) 2013/12/13 9:43:39 Edit(编辑)
支付宝接口(刚完成,应该是目前最好的了)_.net资料_编程技术

支付宝接口(刚完成,应该是目前最好的了)_.net资料_编程技术

支付宝接口(刚完成,应该是目前最好的了)_.net资料_编程技术-你的首页-uuhomepage.com

支付宝的接口调用很不方便,刚做好一个封装,实现了虚拟交易和实物交易。
解决方案中有三个项目以及NDoc生成的文档,简单的序列图:CommonAliPay,封装的支付宝接口。
TestAli,asp.net的测试项目
TestCommonAliPay,Nunit的测试项目。
调用方法:
1、引入CommonAliPay.dll
2、实现支付宝服务接口的方法调用方式:
AliPay ap = new AliPay();
string key = "";//填写自己的key
string partner = "";//填写自己的Partner
StandardGoods bp = new StandardGoods("trade_create_by_buyer", partner, key, "MD5", "卡2", Guid.NewGuid().ToString(), 2.551m, 1, "hao_ding2000@yahoo.com.cn", "hao_ding2000@yahoo.com.cn"
, "EMS", 25.00m, "BUYER_PAY","1");
bp.Notify_Url = "http://203.86.79.185/ali/notify.aspx";
ap.CreateStandardTrade("https://www.alipay.com/cooperate/gateway.do", bp, this);上面是通用的调用方式。
下面是只支持虚拟货物的方式:
string key = "";//填写自己的key
string partner = "";//填写自己的Partner
AliPay ap = new AliPay();
DigitalGoods bp = new DigitalGoods("create_digital_goods_trade_p", partner, key, "MD5", "卡2", Guid.NewGuid().ToString(), 2.551m, 1, "hao_ding2000@yahoo.com.cn", "hao_ding2000@yahoo.com.cn");
bp.Notify_Url = "http://203.86.79.185/ali/notify.aspx";
ap.CreateDigitalTrade("https://www.alipay.com/cooperate/gateway.do", bp, this);3、实现支付宝通知接口方法的调用(支持虚拟和实物):
protected void Page_Load(object sender, EventArgs e)
{

string key = "";//填写自己的key
string partner = "";//填写自己的Partner
AliPay ap = new AliPay();
string notifyid = Request.Form["notify_id"];
Verify v = new Verify("notify_verify", partner, notifyid);
ap.WaitSellerSendGoods+=new AliPay.ProcessNotifyEventHandler(ap_WaitSellerSendGoods);
ap.WaitBuyerPay += new AliPay.ProcessNotifyEventHandler(ap_WaitBuyerPay);
ap.ProcessNotify(this, "https://www.alipay.com/cooperate/gateway.do",key,v, "utf-8");
}


void ap_WaitBuyerPay(object sender, NotifyEventArgs e)
{
// //加入自己的处理逻辑
Log4net.log.Error("wait buyer pay fire");
}



private void ap_WaitSellerSendGoods(object sender, NotifyEventArgs e)
{
//加入自己的处理逻辑
Log4net.log.Error("WaitSellerSendGoods fire");
}支付宝的交易状态都被定义成了类似名称的事件。
部分源代码解析:
1、解析Forms集合到NotifyEventArgs类,因为后面此类的数据要用来做MD5Sign,所以所有值类型,不能存在初始值,如:int的0等。因此用Nullable范型。
private NotifyEventArgs ParseNotify(NameValueCollection nv, object obj)
{
PropertyInfo[] propertyInfos = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);


foreach (PropertyInfo pi in propertyInfos)
{
string v = nv.Get(pi.Name.ToLower());
if (v != null)
{
if (pi.PropertyType == typeof(string))
{


pi.SetValue(obj, v, null);


}
else if (pi.PropertyType == typeof(int?))
{
pi.SetValue(obj, int.Parse(v), null);
}
else if (pi.PropertyType == typeof(decimal?))
{


pi.SetValue(obj, decimal.Parse(v), null);
}
else if (pi.PropertyType == typeof(DateTime?))
{


pi.SetValue(obj, DateTime.Parse(v), null);
}
else if (pi.PropertyType == typeof(bool))
{


pi.SetValue(obj, bool.Parse(v), null);
}
else
{
//转型失败会抛出异常
pi.SetValue(obj, v, null);
}
}


}
return (NotifyEventArgs)obj;


}
2、从类型中获取排序后的参数
/**////


/// 获取排序后的参数
///

///
///
private SortedList GetParam(object obj)
{

PropertyInfo[] propertyInfos = obj.GetType().GetProperties(BindingFlags.Public|BindingFlags.Instance);
SortedList sortedList = new SortedList(StringComparer.CurrentCultureIgnoreCase);
foreach (PropertyInfo pi in propertyInfos)
{


if (pi.GetValue(obj, null) != null)
{
if (pi.Name == "Sign" || pi.Name == "Sign_Type")
{
continue;
}
sortedList.Add(pi.Name.ToLower(), pi.GetValue(obj, null).ToString());

}
}
return sortedList;

}3、从SortedList中产生参数
private string GetUrlParam(SortedList sortedList,bool isEncode)
{
StringBuilder param = new StringBuilder();
StringBuilder encodeParam = new StringBuilder();
if (isEncode == false)
{


foreach (KeyValuePair kvp in sortedList)
{
string t = string.Format("{0}={1}", kvp.Key, kvp.Value);
param.Append(t + "&");
}
return param.ToString().TrimEnd('&');
}
else
{
foreach (KeyValuePair kvp in sortedList)
{
string et = string.Format("{0}={1}", HttpUtility.UrlEncode(kvp.Key), HttpUtility.UrlEncode(kvp.Value));
encodeParam.Append(et + "&");
}
return encodeParam.ToString().TrimEnd('&');
}

}






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.