public void UpLoad(string url, string uname, string pwd, string ppath) { ManualResetEvent waitObject; FileInfo fileInf = new FileInfo(ppath); string fileName = fileInf.Name; FtpState state = new FtpState(); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + url + "/" + fileInf.Name)); request.Method = WebRequestMethods.Ftp.UploadFile; request.KeepAlive = false; request.Credentials = new NetworkCredential(uname, pwd); state.Request = request; state.FileName = ppath; // Get the event to wait on. waitObject = state.OperationComplete; // Asynchronously get the stream for the file contents. request.BeginGetRequestStream(new AsyncCallback(EndGetStreamCallback), state); // Block the current thread until all operations are complete. // waitObject.WaitOne(); // The operations either completed or threw an exception. if (state.OperationException != null) { B_Site_Log.Insert("FTP1", state.OperationException.ToString()); throw state.OperationException; } else { } }
private void EndGetStreamCallback(IAsyncResult ar) { FtpState state = (FtpState)ar.AsyncState; Stream requestStream = null; try { requestStream = state.Request.EndGetRequestStream(ar); // Copy the file contents to the request stream. const int bufferLength = 2048; byte[] buffer = new byte[bufferLength]; int count = 0; int readBytes = 0; FileStream stream = File.OpenRead(state.FileName); do { readBytes = stream.Read(buffer, 0, bufferLength); requestStream.Write(buffer, 0, readBytes); count += readBytes; }while (readBytes != 0); // IMPORTANT: Close the request stream before sending the request. requestStream.Close(); // Asynchronously get the response to the upload request. state.Request.BeginGetResponse(new AsyncCallback(EndGetResponseCallback), state); } // Return exceptions to the main application thread. catch (Exception e) { state.OperationException = e; state.OperationComplete.Set(); B_Site_Log.Insert("FTP2", e.Message); return; } }
public void Upload(Stream file, string fname) { FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + fname)); reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); reqFTP.Method = WebRequestMethods.Ftp.UploadFile; reqFTP.KeepAlive = false; reqFTP.UseBinary = true; reqFTP.ContentLength = file.Length; int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; try { Stream strm = reqFTP.GetRequestStream(); contentLen = file.Read(buff, 0, buffLength); while (contentLen != 0) { strm.Write(buff, 0, contentLen); contentLen = file.Read(buff, 0, buffLength); } strm.Close(); } catch (Exception ex) { B_Site_Log.Insert("FTP UP", fname + ":" + ex.Message); throw new Exception(ex.Message); } finally { file.Close(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string spliteFlag = "&signMsg="; string requestStr = Request.Form.ToString(); string srcStr = requestStr.Substring(0, requestStr.IndexOf(spliteFlag)); string signStr = requestStr.Substring(requestStr.IndexOf(spliteFlag) + spliteFlag.Length); string spliteFlag2 = "¬ifyType=";//0为页面通知,1为异步通知 int pos = signStr.IndexOf(spliteFlag2); if (pos > 0) { signStr = signStr.Substring(0, pos); } else { pos = srcStr.IndexOf(spliteFlag2); if (pos > 0) { srcStr = srcStr.Substring(0, pos); } } signStr = System.Web.HttpUtility.UrlDecode(signStr); bool verifyResult = Mobo360SignUtil.Instance.verifyData(signStr, srcStr); //NotifyType 1:异步,0:同步 //apiName=PAY_RESULT_NOTIFY¬ifyTime=20150327093653&tradeAmt=0.01&merchNo=210001110003583&merchParam=&orderNo=PD12&tradeDate=20150327&accNo=761003&accDate=20150327&orderStatus=1&signMsg=YIfQ7JGp4MIe5hu19lEmWF22aM9xcaL5LqMKlddEv4L7V2vv36qtPKwdS40HOLX1aaVHXgCnwoXnHacrXghRxvM3B1yFuKcCC2q5HnRBnN3Pxg%2bmBUt5WKMJwOC6VbJgqAQvW4UYaubVl7V4TGbAoYGjWuuIFWRthAacPdpK%2bH4%3d¬ifyType=1 //apiName=PAY_RESULT_NOTIFY¬ifyTime=20150327094538&tradeAmt=0.01&merchNo=210001110003583&merchParam=&orderNo=PD13&tradeDate=20150327&accNo=761140&accDate=20150327&orderStatus=1¬ifyType=0&signMsg=dIUoegWS2HgtHlHwz1i62oYPfGyqgNi5HW%2bew734APG0O9xKLHXbR9atFDxwZpXtovQ7wjPuYgqtwD0R0VsNIr5ceA8dlRETepKo0D8Gi1Z4iGtW3UZ%2f92T8ILMRXEw3fUOMTMxyxk265A0VlAla9pCqMMd8QC5pxNoPWOwKFfo%3d #region 校验并更改状态 //if (verifyResult)//其无法通过自己校验 //{ //} //else { B_Site_Log.Insert("MO宝校验失败", requestStr); } string orderNo = Request.Form["orderNo"];//订单号 string notifyType = Request.Form["notifyType"]; double tradeAmt = DataConverter.CDouble(Request.Form["tradeAmt"]); M_UserInfo mu = buser.GetLogin(false); try { if (notifyType.Equals("0")) { function.WriteErrMsg("支付成功"); return; } if (notifyType.Equals("1")) { M_Payment pinfo = payBll.SelModelByPayNo(orderNo); if (pinfo.Status == 3) { return; } pinfo.Status = 3; pinfo.PlatformInfo = "MO宝在线付款"; pinfo.SuccessTime = DateTime.Now; pinfo.PayTime = DateTime.Now; pinfo.CStatus = true; pinfo.MoneyTrue = tradeAmt; payBll.Update(pinfo); DataTable orderDT = orderBll.GetOrderbyOrderNo(pinfo.PaymentNum); foreach (DataRow dr in orderDT.Rows) { M_OrderList orderMod = orderBll.SelModelByOrderNo(dr["OrderNo"].ToString()); if (orderMod.OrderStatus >= 99) { return; //订单已处理,避免重复 } else { orderBll.UpOrderinfo("Paymentstatus=1,Receivablesamount=" + tradeAmt, orderMod.id); } orderCom.SendMessage(orderMod, paylogMod, "payed"); paylogMod.Remind += "订单" + orderMod.OrderNo + "购买生效"; FinalStep(orderMod); //-------支付成功处理,并写入日志 paylogMod.OrderID = orderMod.id; paylogMod.UserID = mu.UserID; paylogMod.PayMethod = (int)M_Order_PayLog.PayMethodEnum.Other; paylogMod.PayMoney = orderMod.Ordersamount; paylogMod.PayPlatID = 16; paylogBll.insert(paylogMod); Response.Write("SUCCESS"); // 验证签名通过后,商户系统回写“SUCCESS”以表明商户收到了通知 B_Site_Log.Insert(pinfo.PaymentNum + ":MO宝处理成功", "状态:" + requestStr); } } } catch (Exception ex) { B_Site_Log.Insert(orderNo + ":MO宝支付处理失败", "原因:" + ex.Message + ":" + requestStr); } #endregion } }
protected void Page_Load(object sender, EventArgs e) { //DataTable pay = payPlatBll.GetPayPlatByClassid(12); M_PayPlat platMod = payPlatBll.SelModelByClass(M_PayPlat.Plat.Alipay_Instant); SortedDictionary <string, string> sArrary = GetRequestPost(); ///////////////////////以下参数是需要设置的相关配置参数,设置后不会更改的////////////////////// ZoomLa.Model.M_Alipay_config con = new ZoomLa.Model.M_Alipay_config(); string partner = platMod.AccountID; string key = platMod.MD5Key; string input_charset = con.Input_charset; string sign_type = con.Sign_type; string transport = con.Transport; ////////////////////////////////////////////////////////////////////////////////////////////// if (sArrary.Count > 0)//判断是否有带返回参数 { ZoomLa.BLL.B_Alipay_notify aliNotify = new ZoomLa.BLL.B_Alipay_notify(sArrary, Request.Form["notify_id"], partner, key, input_charset, sign_type, transport); string responseTxt = aliNotify.ResponseTxt; //获取远程服务器ATN结果,验证是否是支付宝服务器发来的请求 string sign = Request.Form["sign"]; //获取支付宝反馈回来的sign结果 string mysign = aliNotify.Mysign; //获取通知返回后计算后(验证)的签名结果 //判断responsetTxt是否为ture,生成的签名结果mysign与获得的签名结果sign是否一致 //responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 //mysign与sign不等,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 string order_no = Request.Form["out_trade_no"]; //获取订单号 ZLLog.L(ZLEnum.Log.safe, "支付宝:" + aliNotify.ResponseTxt + ":" + order_no + ":" + Request.Form["buyer_email"] + ":" + Request.Form["trade_status"] + ":" + Request.Form["price"] + ":" + Request.Form["subject"]); if (responseTxt == "true" && sign == mysign) //验证成功 { //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 string trade_no = Request.Form["trade_no"]; //支付宝交易号 string total_fee = Request.Form["price"]; //获取总金额 string subject = Request.Form["subject"]; //商品名称、 string body = Request.Form["body"]; //商品描述、订单备注、描述 string buyer_email = Request.Form["buyer_email"]; //买家支付宝账号 string trade_status = Request.Form["trade_status"]; //交易状态 if (Request.Form["trade_status"] == "WAIT_BUYER_PAY") //没有付款 { } else if (trade_status.Equals("WAIT_SELLER_SEND_GOODS"))//付款成功,但是卖家没有发货 { } else if (trade_status.Equals("TRADE_SUCCESS"))//付款成功 { try { M_Payment pinfo = payBll.SelModelByPayNo(order_no); if (pinfo.Status != (int)M_Payment.PayStatus.NoPay) { return; } pinfo.Status = (int)M_Payment.PayStatus.HasPayed; pinfo.PlatformInfo = "支付宝在线付款"; //平台反馈信息 pinfo.SuccessTime = DateTime.Now; //交易成功时间 pinfo.CStatus = true; //处理状态 pinfo.AlipayNO = trade_no; //保存支付宝交易号 pinfo.MoneyTrue = Convert.ToDecimal(total_fee); payBll.Update(pinfo); DataTable orderDT = orderBll.GetOrderbyOrderNo(pinfo.PaymentNum); foreach (DataRow dr in orderDT.Rows) { M_Order_PayLog paylogMod = new M_Order_PayLog(); M_OrderList orderMod = orderBll.SelModelByOrderNo(dr["OrderNo"].ToString()); OrderHelper.FinalStep(pinfo, orderMod, paylogMod); orderCom.SendMessage(orderMod, paylogMod, "payed"); } Response.Write("success"); ZLLog.L(ZLEnum.Log.safe, "支付宝支付成功!支付单:" + order_no); } catch (Exception ex) { ZLLog.L(ZLEnum.Log.pay, new M_Log() { Action = "支付回调报错", Message = "平台:支付宝,支付单:" + order_no + ",原因:" + ex.Message }); } } else if (Request.Form["trade_status"] == "WAIT_BUYER_CONFIRM_GOODS")//卖家已经发货,等待买家确认 { } else if (Request.Form["trade_status"] == "TRADE_FINISHED") { } else//其他状态判断。普通即时到帐中,其他状态不用判断,直接打印success。 { B_Site_Log.Insert("支付宝付款,未成功截获", trade_status); } } else//验证失败 { ZLLog.L(ZLEnum.Log.safe, new M_Log() { Action = "支付验证失败", Message = "平台:支付宝,支付单:" + order_no }); Response.Write("fail"); } } else { Response.Write("success"); } }