protected void Page_Load(object sender, EventArgs e) { log.Info(Request.Url.AbsoluteUri); LogRequestInfo(this.ReqParas); string key = AlipaySetting.Key; //填写自己的key string partner = AlipaySetting.Partner;//填写自己的Partner AliPay ap = new AliPay(); string notifyid = ReqParas["notify_id"]; Verify v = new Verify("notify_verify", partner, notifyid); ap.TradeClosed += new AliPay.ProcessNotifyEventHandler(ap_TradeClosed); ap.TradeFinished += new AliPay.ProcessNotifyEventHandler(ap_TradeFinished); ap.WaitBuyerConfirmGoods += new AliPay.ProcessNotifyEventHandler(ap_WaitBuyerConfirmGoods); ap.WaitBuyerPay += new AliPay.ProcessNotifyEventHandler(ap_WaitBuyerPay); ap.WaitSellerConfirmTrade += new AliPay.ProcessNotifyEventHandler(ap_WaitSellerConfirmTrade); ap.WaitSellerSendGoods += new AliPay.ProcessNotifyEventHandler(ap_WaitSellerSendGoods); ap.WaitSysConfirmPay += new AliPay.ProcessNotifyEventHandler(ap_WaitSysConfirmPay); ap.WaitSysPaySeller += new AliPay.ProcessNotifyEventHandler(ap_WaitSysPaySeller); ap.ModifyTradeBaseTotalFee += new AliPay.ProcessNotifyEventHandler(ap_ModifyTradeBaseTotalFee); ap.RefundClose += new AliPay.ProcessNotifyEventHandler(ap_RefundClose); ap.RefundSuccess += new AliPay.ProcessNotifyEventHandler(ap_RefundSuccess); ap.WaitSellerAgree += new AliPay.ProcessNotifyEventHandler(ap_WaitSellerAgree); ap.ProcessNotify(this, AlipaySetting.PushUrl, key, v, "utf-8"); }
protected void Page_Load(object sender, EventArgs e) { string key = AlipaySetting.Key; //填写自己的key string partner = AlipaySetting.Partner;//填写自己的Partner AliPay ap = new AliPay(); string notifyid = Request.Form["notify_id"]; Verify v = new Verify("notify_verify", partner, notifyid); ap.NotifyEvent += new AliPay.ProcessNotifyEventHandler(ap_NotifyEvent); ap.ProcessNotify(this, AlipaySetting.PushUrl, key, v, "utf-8"); ap.CommonProcessNotify(this,AlipaySetting.VerifyUrl,AlipaySetting.Key,v,AlipaySetting.EncodeType); }
/// <summary> /// ������ص�Notify /// </summary> /// <param name="page">����Page����</param> /// <param name="verifyUrl">��֤�ĵ�ַ���磺https://www.alipay.com/cooperate/gateway.do</param> /// <param name="key">�˻��Ľ��װ�ȫУ���루key��</param> /// <param name="verify">verify����</param> /// <param name="encode">����</param> /// <exception cref="SignVerifyFailedException">֧����֪ͨǩ����֤ʧ��</exception> /// <exception cref="CommonAliPayBaseException">֧����֪ͨ��֤ʧ��</exception> public void ProcessNotify(Page page, string verifyUrl, string key, Verify verify, string encode) { if (VerifyNotify(verifyUrl, verify)) //��֤�ɹ� { NotifyEventArgs dn = new NotifyEventArgs(); dn = ParseNotify(GetReqParas(page), dn);//�����¼����� //SortedList<string, string> sortedList = GetParam(dn); SortedList<string, string> sortedList = GetParamFromReqPara(GetReqParas(page)); string param = GetUrlParam(sortedList, false); #if (DEBUG) Log4net.log.Error(param + "param"); #endif string sign = GetMd5Sign(encode, param + key); if (sign == dn.Sign)//��֤ǩ�� { // ����״̬���� switch (dn.Trade_Status) { case "WAIT_SELLER_SEND_GOODS": OnWaitSellerSendGoods(dn); break; case "WAIT_BUYER_PAY": OnWaitBuyerPay(dn); break; case "WAIT_SELLER_CONFIRM_TRADE": OnWaitSellerConfirmTrade(dn); break; case "WAIT_SYS_CONFIRM_PAY": OnWaitSysConfirmPay(dn); break; case "WAIT_BUYER_CONFIRM_GOODS": OnWaitBuyerConfirmGoods(dn); break; case "WAIT_SYS_PAY_SELLER": OnWaitSysPaySeller(dn); break; case "TRADE_FINISHED": OnTradeFinished(dn); break; case "TRADE_CLOSED": OnTradeClosed(dn); break; case "modify.tradeBase.totalFee": OnModifyTradeBaseTotalFee(dn); break; default: throw new NotImplementedException(dn.Trade_Status); } // �˿�״̬���� switch (dn.Refund_Status) { case "REFUND_CLOSED": OnRefundClose(dn); break; case "REFUND_SUCCESS": OnRefundSuccess(dn); break; case "WAIT_SELLER_AGREE": OnWaitSellerAgree(dn); break; } page.Response.Write("success"); } else { page.Response.Write("fail"); throw new CommonAliPayBaseException("֧����֪ͨǩ����֤ʧ��", 102); #if (DEBUG) Log4net.log.Error("֧����֪ͨǩ����֤ʧ��"); #endif } } else { page.Response.Write("fail"); throw new CommonAliPayBaseException("֧����֪ͨ��֤ʧ��", 101); } }
/// <summary> /// ֪ͨ��֤�ӿ� /// </summary> /// <param name="verifyUrl"></param> /// <param name="verify">��֤����</param> /// <returns>true��ͨ����֤</returns> private bool VerifyNotify(string verifyUrl, Verify verify) { //#if (DEBUG) // { // return true; // } //#endif string param; SortedList<string, string> sl = GetParam(verify); param = GetUrlParam(sl, true); string result = PostData(verifyUrl, param, "utf-8"); //����result return bool.Parse(result); ; }
/// <summary> /// ������ص�Notify /// </summary> /// <param name="page">����Page����</param> /// <param name="verifyUrl">��֤�ĵ�ַ���磺https://www.alipay.com/cooperate/gateway.do</param> /// <param name="key">�˻��Ľ��װ�ȫУ���루key��</param> /// <param name="verify">verify����</param> /// <param name="encode">����</param> /// <exception cref="SignVerifyFailedException">֧����֪ͨǩ����֤ʧ��</exception> /// <exception cref="CommonAliPayBaseException">֧����֪ͨ��֤ʧ��</exception> public void CommonProcessNotify(Page page, string verifyUrl, string key, Verify verify, string encode) { if (VerifyNotify(verifyUrl, verify)) //��֤�ɹ� { NotifyEventArgs dn = new NotifyEventArgs(); dn = ParseNotify(page.Request.Form, dn);//�����¼����� SortedList<string, string> sortedList = GetParam(dn); string param = GetUrlParam(sortedList, false); #if (DEBUG) Log4net.log.Error(param + "param"); #endif string sign = GetMd5Sign(encode, param + key); if (sign == dn.Sign)//��֤ǩ�� { OnNotifyEvent(dn); } else { throw new SignVerifyFailedException("֧����֪ͨǩ����֤ʧ��", 102); } } else { throw new CommonAliPayBaseException("֧����֪ͨ��֤ʧ��", 101); } }