åèå®ä¾å¦ä¸ï¼
è°ç¨æ¹æ³ï¼
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ãä»ç±»åä¸è·åæåºåçåæ°
/**//// <summary>
/// è·åæåºåçåæ°
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
private SortedList<string,string> GetParam(object obj)
{
PropertyInfo[] propertyInfos = obj.GetType().GetProperties(BindingFlags.Public|BindingFlags.Instance);
SortedList<string, string> sortedList = new SortedList<string, string>(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<string, string> sortedList,bool isEncode)
{
StringBuilder param = new StringBuilder();
StringBuilder encodeParam = new StringBuilder();
if (isEncode == false)
{
foreach (KeyValuePair<string, string> kvp in sortedList)
{
string t = string.Format("{0}={1}", kvp.Key, kvp.Value);
param.Append(t + "&");
}
return param.ToString().TrimEnd('&');
}
else
{
foreach (KeyValuePair<string, string> kvp in sortedList)
{
string et = string.Format("{0}={1}", HttpUtility.UrlEncode(kvp.Key), HttpUtility.UrlEncode(kvp.Value));
encodeParam.Append(et + "&");
}
return encodeParam.ToString().TrimEnd('&');
}