Example #1
0
    protected void OnlinePaymentAlipayToBank(int Count, double SumMoney, string Body, string UserDistillIDs)
    {
        //业务参数赋值;
        SystemOptions sysOptions = new SystemOptions();
        partner = sysOptions["OnlinePay_Alipay_ForUserDistill_UserNumber"].ToString("");//OnlinePayOut_Alipay_UserNumber		//partner		合作伙伴ID			保留字段
        key = sysOptions["OnlinePay_Alipay_ForUserDistill_MD5Key"].ToString("");   //OnlinePayOut_Alipay_MD5Key //partner账户的支付宝安全校验码

        gateway = sysOptions["MemberSharing_Alipay_Gateway"].ToString("");  //"https://www.alipay.com/cooperate/gateway.do";
        service = "bptb_pay_file";
        sign_type = "MD5";
        _input_charset = "GB2312";                                                  //编码类型
        file_digest_type = "MD5";                                                   //文件摘要算法
        biz_type = "d_sale";                                                        //业务类型

        agentID = sysOptions["OnlinePay_Alipay_ForUserDistill_UserNumber"].ToString("");// "2088001456282873";

        Shove.Alipay.Alipay ap = new Shove.Alipay.Alipay();

        DateTime dtNow = DateTime.Now;

        string FileName = "";
        string FileAddr = "";
        string ZipFileName = "";
        string ZipFileAddr = "";

        int i = 0;

        if ((Body != "") && (Count > 0) && (SumMoney > 0))
        {
            string strDateTime = dtNow.ToString("yyyyMMdd");

            #region     CSV文件标准格式

            //日期,总金额,总笔数,支付宝帐号(Email)
            //20080418,10,1,[email protected]
            //商户流水号,收款银行户名,收款银行帐号,收款开户银行,收款银行所在省份,收款银行所在市,收款支行名称,金额,对公对私标志,备注
            //2007052801,韦吴石,6221885511000609058,工商银行,广东省,深圳市,工商银行深圳宝安分行,10,2,2132

            #endregion

            string headStr = "日期,总金额,总笔数,支付宝帐号(Email)\r\n";
            headStr += strDateTime + "," + SumMoney.ToString() + "," + Count.ToString() + "," + partner + "\r\n";
            headStr += "商户流水号,收款银行户名,收款银行帐号,收款开户银行,收款银行所在省份,收款银行所在市,收款支行名称,金额,对公对私标志,备注\r\n";
            Body = headStr + Body;

            System.Random rad = new Random();
            string Num = rad.Next(1, 999).ToString();
            Num = Num + dtNow.Hour.ToString() + dtNow.Minute.ToString() + dtNow.Second.ToString();
            Num = Num.PadLeft(9, '0');

            FileName = "PAPX_" + strDateTime + "_P" + Num + ".csv".ToLower();
            FileAddr = MapPath("../App_Log/Admin/AlipayPayment/PABX/" + FileName).ToLower();
            ZipFileName = "PAPX_" + strDateTime + "_P" + Num + ".Zip".ToLower();
            ZipFileAddr = MapPath("../App_Log/Admin/AlipayPayment/PABX/" + ZipFileName).ToLower();

            if (!System.IO.File.Exists(FileAddr))
            {
                try
                {
                    //File.WriteAllText(FileAddr, Body);
                    if (!Shove._IO.File.WriteFile(FileAddr, Body))
                    {
                        DAL.Procedures.P_UserDistillPayByAlipayWriteLog("CSV文件写入失败:" + FileAddr);

                        Shove._Web.JavaScript.Alert(this.Page, "CSV文件写入失败");

                        return;
                    }

                }
                catch
                {
                    DAL.Procedures.P_UserDistillPayByAlipayWriteLog("CSV文件写入异常:" + FileAddr);
                    Shove._Web.JavaScript.Alert(this.Page, "CSV文件写入异常");

                    return;
                }
            }
            else
            {
                Shove._Web.JavaScript.Alert(this.Page, "文件写已存在");

                return;
            }

            if (System.IO.File.Exists(FileAddr))
            {
                if (!System.IO.File.Exists(ZipFileAddr))
                {
                    try
                    {
                        Shove._IO.File.Compress(FileAddr, ZipFileAddr);
                    }
                    catch
                    {

                        DAL.Procedures.P_UserDistillPayByAlipayWriteLog("文件压缩出现异常:" + FileAddr);
                        Shove._Web.JavaScript.Alert(this.Page, "文件压缩出现异常");
                        return;
                    }
                }

            }
            else
            {

                DAL.Procedures.P_UserDistillPayByAlipayWriteLog("CSV文件不存在(1):" + FileAddr);
                Shove._Web.JavaScript.Alert(this.Page, "CSV文件不存在");

                return;
            }
        }

        if (!System.IO.File.Exists(ZipFileAddr))
        {

            DAL.Procedures.P_UserDistillPayByAlipayWriteLog("ZIP文件不存在(2):" + FileAddr);
            Shove._Web.JavaScript.Alert(this.Page, "ZIP文件不存在");

            return;
        }

        byte[] Date = System.IO.File.ReadAllBytes(ZipFileAddr);
        digest_bptb_pay_file = Shove.Alipay.Alipay.GetMD5(Date, _input_charset);

        string[] Sortedstr = ap.GetUploadParams
            (
            service,
            _input_charset,
            partner,
            file_digest_type,
            biz_type,
            agentID
            );                                                                      //签名

        // 读文件流
        FileStream fs = new FileStream(ZipFileAddr, FileMode.Open, FileAccess.Read, FileShare.Read);

        // 这部分需要完善
        string ContentType = "application/octet-stream";
        byte[] fileBytes = new byte[fs.Length];
        fs.Read(fileBytes, 0, Convert.ToInt32(fs.Length));
        fs.Close();

        // 生成需要上传的二进制数组
        CreateBytes cb = new Shove.Alipay.CreateBytes();
        // 所有表单数据
        ArrayList bytesArray = new ArrayList();
        // 普通表单
        string[] fields = new string[Sortedstr.Length + 1];

        char[] delimiterChars = { '=' };

        for (i = 0; i < Sortedstr.Length; i++)
        {
            string fieldName = Sortedstr[i].Split(delimiterChars)[0];
            string fieldValue = Sortedstr[i].Split(delimiterChars)[1];

            bytesArray.Add(cb.CreateFieldData(fieldName, fieldValue));
            fields[i] = fieldName + "=" + fieldValue;
        }

        bytesArray.Add(cb.CreateFieldData("digest_bptb_pay_file", digest_bptb_pay_file));
        fields[i] = "digest_bptb_pay_file=" + digest_bptb_pay_file;
        sign = AlipayCommon.GetSign(fields, key).Trim();
        bytesArray.Add(cb.CreateFieldData("sign", sign));
        bytesArray.Add(cb.CreateFieldData("sign_type", "MD5"));

        // 文件表单
        bytesArray.Add(cb.CreateFieldData("bptb_pay_file", ZipFileAddr, ContentType, fileBytes));

        // 合成所有表单并生成二进制数组
        byte[] bytes = cb.JoinBytes(bytesArray);

        // 返回的内容
        byte[] responseBytes;
        // 上传到指定Url        
        bool uploaded = cb.UploadData(gateway, bytes, out responseBytes);
        if (!uploaded)
        {

            DAL.Procedures.P_UserDistillPayByAlipayWriteLog("上传到指定Url失败:" + FileAddr);
            try
            {
                File.Delete(FileAddr);
                File.Delete(ZipFileAddr);
            }
            catch
            {
            }
            Shove._Web.JavaScript.Alert(this.Page, "上传支付数据到指定Url失败!");

            return;
        }

        string UploadResult = System.Text.Encoding.Default.GetString(responseBytes);

        if (UploadResult.IndexOf("上传成功") >= 0)
        {
            //把上传的支付明细写入数据库(FileName)和更新状态
            int returnValue = 0;
            string returnDecription = "";
            if (DAL.Procedures.P_UserDistillPayByAlipay(_User.ID, ZipFileName, UserDistillIDs, 2, ref returnValue, ref returnDecription) < 0)
            {
                DAL.Procedures.P_UserDistillPayByAlipayWriteLog("提款ID:" + UserDistillIDs + "写入数据库(FileName)和更新状态失败。");
            }
            if (returnDecription != "")
            {
                DAL.Procedures.P_UserDistillPayByAlipayWriteLog("把上传的支付明细写入数据库(FileName)和更新状态出错:" + returnDecription);
                Shove._Web.JavaScript.Alert(this.Page, "出错:" + returnDecription);
                BindData(true);
                return;
            }

            Shove._Web.JavaScript.Alert(this.Page, UploadResult + "银行处理需要到明天才有结果,请耐心等待处理结果!");

            BindData(true);
        }
        else
        {

            DAL.Procedures.P_UserDistillPayByAlipayWriteLog("上传支付到银行明细失败:" + UploadResult);
            Shove._Web.JavaScript.Alert(this.Page, UploadResult.Replace("\n", "").Replace("\r", ""));
        }

    }
Example #2
0
        private void DownLoadResult()	//下载结果
        {
            //业务参数赋值;
            string partner = OnlinePay_Alipay_ForUserDistill_UserNumber;        //partner		合作伙伴ID			保留字段
            string key = OnlinePay_Alipay_ForUserDistill_MD5Key_ForPayOut;      //partner账户的支付宝安全校验码
            string gateway = "https://www.alipay.com/cooperate/gateway.do";
            string service = "bptb_result_file";
            string sign = "";
            string _input_charset = "GB2312";                                                  //编码类型
            string biz_type = "d_sale";                                                        //业务类型

            Shove.Alipay.Alipay ap = new Shove.Alipay.Alipay();

            //获取今日之前的处理中的最大日期,按天分组
            DataTable dt = Shove.Database.MSSQL.Select(ConnectionString, " select max([DateTime]) as [DateTime] from T_UserDistillPaymentFiles where Result = 0 and datediff(Day,[DateTime],getdate())>0 group by convert(varchar(8),[DateTime],112)");

            if (dt == null)
            {
                //写日志
                log.Write("获取今日之前的处理中的最大日期,按天分组出错.");
                return;
            }

            foreach (DataRow dr in dt.Rows)
            {
                string fileName = "";
                DateTime time = Shove._Convert.StrToDateTime(dr["DateTime"].ToString(), DateTime.Now.ToShortDateString());

                fileName = "result" + time.ToString("yyyyMMdd");   //文件名的格式

                //string ContentType = "application/octet-stream";
                // 生成需要上传的二进制数组        
                CreateBytes cb = new CreateBytes();

                // 所有表单数据
                ArrayList bytesArray = new ArrayList();

                // 普通表单
                string[] Sortedstr = ap.GetDownloadParams
                    (
                    service,
                    _input_charset,
                    partner,
                    biz_type
                    );

                string[] downFields = new string[Sortedstr.Length + 1];
                int i = 0;

                char[] delimiterChars = { '=' };

                for (i = 0; i < Sortedstr.Length; i++)
                {
                    string fieldName = Sortedstr[i].Split(delimiterChars)[0];
                    string fieldValue = Sortedstr[i].Split(delimiterChars)[1];

                    bytesArray.Add(cb.CreateFieldData(fieldName, fieldValue));
                    downFields[i] = fieldName + "=" + fieldValue;
                }

                string date = time.ToString("yyyyMMdd");
                bytesArray.Add(cb.CreateFieldData("date", date));
                downFields[i] = "date" + "=" + date;
                sign = AlipayCommon.GetSign(downFields, key).Trim();
                bytesArray.Add(cb.CreateFieldData("sign", sign));
                bytesArray.Add(cb.CreateFieldData("sign_type", "MD5"));

                // 合成所有表单并生成二进制数组
                byte[] bytes = cb.JoinBytes(bytesArray);

                // 返回的内容
                byte[] responseBytes;

                // 上传到指定Url
                bool uploaded = false;

                try
                {
                    uploaded = cb.UploadData(gateway, bytes, out responseBytes);
                }
                catch (Exception ex)
                {
                    log.Write("cb.UploadData出错." + ex.Message);
                    continue;
                }

                if (!uploaded)
                {
                    log.Write("cb.UploadData失败.");
                    continue;
                }

                //PathName = System.AppDomain.CurrentDomain.BaseDirectory + "LogFiles\\" + pathname;
                string DownLoadFolder = System.AppDomain.CurrentDomain.BaseDirectory + "LogFiles\\GetAlipayPayResultTask\\RESULT\\";


                #region 查检下载目录是否存在,不存在则创建
                if (!Directory.Exists(DownLoadFolder))
                {
                    try
                    {
                        Directory.CreateDirectory(DownLoadFolder);
                    }
                    catch
                    {
                        log.Write("创建下载文件目录失败.");
                        return;
                    }
                }
                #endregion

                //判断responseByte是否以PK开头(以PK开头说明可以下载)
                if (responseBytes[0] != 80 && responseBytes[1] != 75)
                {
                    log.Write("判断responseByte不是以PK开头");
                    continue;
                }


                try
                {
                    if (File.Exists(DownLoadFolder + fileName + ".zip"))
                    {
                        File.Delete(DownLoadFolder + fileName + ".zip");
                    }

                    using (FileStream file = new FileStream(DownLoadFolder + fileName + ".zip", FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        file.Write(responseBytes, 0, responseBytes.Length);
                    }

                    //解压下载的结果数据包
                    UnZip(DownLoadFolder + fileName + ".zip", DownLoadFolder + fileName);

                    //解压出来的结果文件
                    string strpath = DownLoadFolder + fileName + "\\ALIPAY__RESULT.csv";

                    //保存返回结果数据
                    DataTable dtResult = new DataTable("TableName");
                    int dtResultColCount = 0;

                    //保存返回结果中的文件明细表
                    DataTable dtResultFileDetail = new DataTable("dtResultFileDetail");
                    int dtResultFileDetailColCount = 0;


                    string strline;
                    string[] aryline;

                    System.IO.StreamReader mysr = new System.IO.StreamReader(strpath, Encoding.GetEncoding("GB2312"));
                    int resultFileRow = 0;

                    #region 构建返回结果表 和 返回结果中的文件列表数据表
                    while ((strline = mysr.ReadLine()) != null)
                    {
                        aryline = strline.Split(new char[] { ',' });

                        if (resultFileRow < 2) //构建返回结果表(2行,第1行为标题,第2行为对应的数据)   头部2行 
                        {
                            if (resultFileRow == 0)
                            {
                                dtResultColCount = aryline.Length;
                                for (int j = 0; j < aryline.Length; j++)
                                {
                                    DataColumn newCol = new DataColumn(aryline[j]);//付款日期,批次数,已处理批次个数,处理中批次个数
                                    dtResult.Columns.Add(newCol);
                                }
                            }

                            if (resultFileRow == 1)
                            {
                                DataRow newRow = dtResult.NewRow();
                                for (int j = 0; j < dtResultColCount; j++)
                                {
                                    newRow[j] = aryline[j];
                                }
                                dtResult.Rows.Add(newRow);
                            }
                        }
                        else  //构建文件列表数据表
                        {
                            if (resultFileRow == 2) //结果文件的行2:  批次名称,处理状态,处理成功笔数,处理失败笔数,成功付款总金额,失败付款总金额,处理日期,支付宝帐号,备注
                            {
                                dtResultFileDetailColCount = aryline.Length;
                                for (int j = 0; j < aryline.Length; j++)
                                {
                                    DataColumn newCol = new DataColumn(aryline[j]);
                                    dtResultFileDetail.Columns.Add(newCol);
                                }
                            }

                            if (resultFileRow >= 3) //获取:papx_20090416_p623225643.csv,已处理,2,0,2.00,0.00,20090417,[email protected],处理完成
                            {
                                DataRow newResultFileDetailRow = dtResultFileDetail.NewRow();
                                for (int j = 0; j < dtResultFileDetailColCount; j++)
                                {
                                    try
                                    {
                                        newResultFileDetailRow[j] = aryline[j];
                                    }
                                    catch
                                    {
                                        newResultFileDetailRow[j] = "";
                                    }
                                }
                                dtResultFileDetail.Rows.Add(newResultFileDetailRow);
                            }
                        }

                        resultFileRow++;
                    }
                    #endregion 结束  构建返回结果表 和 返回结果中的文件列表数据表


                    #region 循环处理返回结果中的文件列表的文件,以更新提款状态
                    foreach (DataRow curResultFileDetailRow in dtResultFileDetail.Rows)  //循环每个提交的文件
                    {
                        string CSVFile = curResultFileDetailRow[0].ToString(); //获取文件名
                        CSVFile = CSVFile.Substring(0, CSVFile.IndexOf(".")) + ".zip".ToLower();

                        if ((curResultFileDetailRow[1].ToString() == "已处理") && (curResultFileDetailRow[8].ToString() == "处理完成"))
                        {
                            string FilePath = DownLoadFolder + fileName + "\\" + curResultFileDetailRow[0].ToString();

                            DataTable dtCSVDetail = GetDetail(FilePath);    //获取当前处理的文件的提款记录明细数据

                            //循环处理当前CSV文件中的所有明细
                            foreach (DataRow drCSVDetail in dtCSVDetail.Rows)
                            {
                                if (drCSVDetail[9].ToString().ToLower() == "s")//成功标记
                                {

                                    //派款成功,更新状态标记
                                    long distillID = Shove._Convert.StrToLong(drCSVDetail[0].ToString(), -1);
                                    int returnValue = 0;
                                    string returnDescription = "";

                                    if (DAL.Procedures.P_UserDistillPayByAlipaySuccess(ConnectionString, 1, distillID, 0, ref returnValue, ref returnDescription) < 0)
                                    {
                                        log.Write("派款成功,P_UserDistillPayByAlipaySuccessAndUpdate状态更新失败.");
                                        continue;
                                    }
                                    if (returnValue < 0)
                                    {
                                        DAL.Procedures.P_UserDistillPayByAlipayWriteLog(ConnectionString, "出错!提款ID:" + distillID + "派款成功,但状态更新失败:" + returnDescription);
                                        continue;
                                    }


                                }
                                else
                                {
                                    //支付没有成功,返还会员提款的金额
                                    long distillID = Shove._Convert.StrToLong(drCSVDetail[0].ToString(), -1);
                                    string memo = "批量付款到银行卡失败:";//失败原因
                                    try
                                    {
                                        memo += drCSVDetail[12].ToString();
                                        memo = memo.Length > 50 ? memo.Substring(0, 50) : memo;
                                    }
                                    catch { }

                                    int returnValue = 0;
                                    string returnDescription = "";

                                    if (DAL.Procedures.P_UserDistillPayByAlipayUnsuccess(ConnectionString, 1, distillID, memo, ref returnValue, ref returnDescription) < 0)
                                    {
                                        log.Write("派款失败,P_UserDistillPayByAlipayUnsuccessAndQuash状态更新失败.");
                                        continue;
                                    }
                                    if (returnValue < 0)
                                    {
                                        log.Write("派款成功,但状态更新失败:" + returnDescription);
                                        DAL.Procedures.P_UserDistillPayByAlipayWriteLog(ConnectionString, "出错!提款ID:" + distillID + "派款成功,但状态更新失败:" + returnDescription);
                                        continue;
                                    }
                                }
                            }//end foreach (DataRow drCSVDetail in dtCSVDetail.Rows)


                            if (Shove.Database.MSSQL.ExecuteNonQuery(ConnectionString, "Update T_UserDistillPaymentFiles set [Result] = 1 where  Lower([FileName]) = '" + CSVFile + "'") < 0)
                            {
                                log.Write("更新T_UserDistillPaymentFiles出错.");
                            }
                        }//end if ((curResultFileDetailRow[1].ToString() == "已处理") && (curResultFileDetailRow[8].ToString() == "处理完成"))
                        else if (curResultFileDetailRow[1].ToString() == "处理中")
                        {
                            continue;
                        }
                        else
                        {
                            //文件格式错误的处理         
                            log.Write("文件格式错误的处理,未知处理结果状态.");

                        }
                    }//foreach (DataRow curResultFileDetailRow in dtResultFileDetail.Rows)
                    #endregion 循环处理返回结果中的文件列表的文件,以更新提款状态

                }
                catch (Exception ex)
                {
                    log.Write("未知异常3:" + ex.Message);
                }
            } //end foreach (DataRow dr in dt.Rows)

        }
    protected void OnlinePaymentAlipayToBank(int Count, double SumMoney, string Body, string UserDistillIDs)
    {
        //业务参数赋值;
        SystemOptions sysOptions = new SystemOptions();

        partner = sysOptions["OnlinePay_Alipay_ForUserDistill_UserNumber"].ToString(""); //OnlinePayOut_Alipay_UserNumber		//partner		合作伙伴ID			保留字段
        key     = sysOptions["OnlinePay_Alipay_ForUserDistill_MD5Key"].ToString("");     //OnlinePayOut_Alipay_MD5Key //partner账户的支付宝安全校验码

        gateway          = sysOptions["MemberSharing_Alipay_Gateway"].ToString("");      //"https://www.alipay.com/cooperate/gateway.do";
        service          = "bptb_pay_file";
        sign_type        = "MD5";
        _input_charset   = "GB2312";                                                     //编码类型
        file_digest_type = "MD5";                                                        //文件摘要算法
        biz_type         = "d_sale";                                                     //业务类型

        agentID = sysOptions["OnlinePay_Alipay_ForUserDistill_UserNumber"].ToString(""); // "2088001456282873";

        Shove.Alipay.Alipay ap = new Shove.Alipay.Alipay();

        DateTime dtNow = DateTime.Now;

        string FileName    = "";
        string FileAddr    = "";
        string ZipFileName = "";
        string ZipFileAddr = "";

        int i = 0;

        if ((Body != "") && (Count > 0) && (SumMoney > 0))
        {
            string strDateTime = dtNow.ToString("yyyyMMdd");

            #region     CSV文件标准格式

            //日期,总金额,总笔数,支付宝帐号(Email)
            //20080418,10,1,[email protected]
            //商户流水号,收款银行户名,收款银行帐号,收款开户银行,收款银行所在省份,收款银行所在市,收款支行名称,金额,对公对私标志,备注
            //2007052801,韦吴石,6221885511000609058,工商银行,广东省,深圳市,工商银行深圳宝安分行,10,2,2132

            #endregion

            string headStr = "日期,总金额,总笔数,支付宝帐号(Email)\r\n";
            headStr += strDateTime + "," + SumMoney.ToString() + "," + Count.ToString() + "," + partner + "\r\n";
            headStr += "商户流水号,收款银行户名,收款银行帐号,收款开户银行,收款银行所在省份,收款银行所在市,收款支行名称,金额,对公对私标志,备注\r\n";
            Body     = headStr + Body;

            System.Random rad = new Random();
            string        Num = rad.Next(1, 999).ToString();
            Num = Num + dtNow.Hour.ToString() + dtNow.Minute.ToString() + dtNow.Second.ToString();
            Num = Num.PadLeft(9, '0');

            FileName    = "PAPX_" + strDateTime + "_P" + Num + ".csv".ToLower();
            FileAddr    = MapPath("../App_Log/Admin/AlipayPayment/PABX/" + FileName).ToLower();
            ZipFileName = "PAPX_" + strDateTime + "_P" + Num + ".Zip".ToLower();
            ZipFileAddr = MapPath("../App_Log/Admin/AlipayPayment/PABX/" + ZipFileName).ToLower();

            if (!System.IO.File.Exists(FileAddr))
            {
                try
                {
                    //File.WriteAllText(FileAddr, Body);
                    if (!Shove._IO.File.WriteFile(FileAddr, Body))
                    {
                        DAL.Procedures.P_UserDistillPayByAlipayWriteLog("CSV文件写入失败:" + FileAddr);

                        Shove._Web.JavaScript.Alert(this.Page, "CSV文件写入失败");

                        return;
                    }
                }
                catch
                {
                    DAL.Procedures.P_UserDistillPayByAlipayWriteLog("CSV文件写入异常:" + FileAddr);
                    Shove._Web.JavaScript.Alert(this.Page, "CSV文件写入异常");

                    return;
                }
            }
            else
            {
                Shove._Web.JavaScript.Alert(this.Page, "文件写已存在");

                return;
            }

            if (System.IO.File.Exists(FileAddr))
            {
                if (!System.IO.File.Exists(ZipFileAddr))
                {
                    try
                    {
                        Shove._IO.File.Compress(FileAddr, ZipFileAddr);
                    }
                    catch
                    {
                        DAL.Procedures.P_UserDistillPayByAlipayWriteLog("文件压缩出现异常:" + FileAddr);
                        Shove._Web.JavaScript.Alert(this.Page, "文件压缩出现异常");
                        return;
                    }
                }
            }
            else
            {
                DAL.Procedures.P_UserDistillPayByAlipayWriteLog("CSV文件不存在(1):" + FileAddr);
                Shove._Web.JavaScript.Alert(this.Page, "CSV文件不存在");

                return;
            }
        }

        if (!System.IO.File.Exists(ZipFileAddr))
        {
            DAL.Procedures.P_UserDistillPayByAlipayWriteLog("ZIP文件不存在(2):" + FileAddr);
            Shove._Web.JavaScript.Alert(this.Page, "ZIP文件不存在");

            return;
        }

        byte[] Date = System.IO.File.ReadAllBytes(ZipFileAddr);
        digest_bptb_pay_file = Shove.Alipay.Alipay.GetMD5(Date, _input_charset);

        string[] Sortedstr = ap.GetUploadParams
                             (
            service,
            _input_charset,
            partner,
            file_digest_type,
            biz_type,
            agentID
                             );                                                     //签名

        // 读文件流
        FileStream fs = new FileStream(ZipFileAddr, FileMode.Open, FileAccess.Read, FileShare.Read);

        // 这部分需要完善
        string ContentType = "application/octet-stream";
        byte[] fileBytes   = new byte[fs.Length];
        fs.Read(fileBytes, 0, Convert.ToInt32(fs.Length));
        fs.Close();

        // 生成需要上传的二进制数组
        CreateBytes cb = new Shove.Alipay.CreateBytes();
        // 所有表单数据
        ArrayList bytesArray = new ArrayList();
        // 普通表单
        string[] fields = new string[Sortedstr.Length + 1];

        char[] delimiterChars = { '=' };

        for (i = 0; i < Sortedstr.Length; i++)
        {
            string fieldName  = Sortedstr[i].Split(delimiterChars)[0];
            string fieldValue = Sortedstr[i].Split(delimiterChars)[1];

            bytesArray.Add(cb.CreateFieldData(fieldName, fieldValue));
            fields[i] = fieldName + "=" + fieldValue;
        }

        bytesArray.Add(cb.CreateFieldData("digest_bptb_pay_file", digest_bptb_pay_file));
        fields[i] = "digest_bptb_pay_file=" + digest_bptb_pay_file;
        sign      = AlipayCommon.GetSign(fields, key).Trim();
        bytesArray.Add(cb.CreateFieldData("sign", sign));
        bytesArray.Add(cb.CreateFieldData("sign_type", "MD5"));

        // 文件表单
        bytesArray.Add(cb.CreateFieldData("bptb_pay_file", ZipFileAddr, ContentType, fileBytes));

        // 合成所有表单并生成二进制数组
        byte[] bytes = cb.JoinBytes(bytesArray);

        // 返回的内容
        byte[] responseBytes;
        // 上传到指定Url
        bool uploaded = cb.UploadData(gateway, bytes, out responseBytes);
        if (!uploaded)
        {
            DAL.Procedures.P_UserDistillPayByAlipayWriteLog("上传到指定Url失败:" + FileAddr);
            try
            {
                File.Delete(FileAddr);
                File.Delete(ZipFileAddr);
            }
            catch
            {
            }
            Shove._Web.JavaScript.Alert(this.Page, "上传支付数据到指定Url失败!");

            return;
        }

        string UploadResult = System.Text.Encoding.Default.GetString(responseBytes);

        if (UploadResult.IndexOf("上传成功") >= 0)
        {
            //把上传的支付明细写入数据库(FileName)和更新状态
            int    returnValue      = 0;
            string returnDecription = "";
            if (DAL.Procedures.P_UserDistillPayByAlipay(_User.ID, ZipFileName, UserDistillIDs, 2, ref returnValue, ref returnDecription) < 0)
            {
                DAL.Procedures.P_UserDistillPayByAlipayWriteLog("提款ID:" + UserDistillIDs + "写入数据库(FileName)和更新状态失败。");
            }
            if (returnDecription != "")
            {
                DAL.Procedures.P_UserDistillPayByAlipayWriteLog("把上传的支付明细写入数据库(FileName)和更新状态出错:" + returnDecription);
                Shove._Web.JavaScript.Alert(this.Page, "出错:" + returnDecription);
                BindData(true);
                return;
            }

            Shove._Web.JavaScript.Alert(this.Page, UploadResult + "银行处理需要到明天才有结果,请耐心等待处理结果!");

            BindData(true);
        }
        else
        {
            DAL.Procedures.P_UserDistillPayByAlipayWriteLog("上传支付到银行明细失败:" + UploadResult);
            Shove._Web.JavaScript.Alert(this.Page, UploadResult.Replace("\n", "").Replace("\r", ""));
        }
    }
 protected void OnlinePaymentAlipayToBank(int Count, double SumMoney, string Body, string UserDistillIDs)
 {
     SystemOptions options = new SystemOptions();
     this.partner = options["OnlinePay_Alipay_ForUserDistill_UserNumber"].ToString("");
     this.key = options["OnlinePay_Alipay_ForUserDistill_MD5Key"].ToString("");
     this.gateway = options["MemberSharing_Alipay_Gateway"].ToString("");
     this.service = "bptb_pay_file";
     this.sign_type = "MD5";
     this._input_charset = "GB2312";
     this.file_digest_type = "MD5";
     this.biz_type = "d_sale";
     this.agentID = options["OnlinePay_Alipay_ForUserDistill_UserNumber"].ToString("");
     Shove.Alipay.Alipay alipay = new Shove.Alipay.Alipay();
     DateTime now = DateTime.Now;
     string str = "";
     string path = "";
     string fileName = "";
     string str4 = "";
     int index = 0;
     if (((Body != "") && (Count > 0)) && (SumMoney > 0.0))
     {
         string str5 = now.ToString("yyyyMMdd");
         string str7 = "日期,总金额,总笔数,支付宝帐号(Email)\r\n";
         Body = (str7 + str5 + "," + SumMoney.ToString() + "," + Count.ToString() + "," + this.partner + "\r\n") + "商户流水号,收款银行户名,收款银行帐号,收款开户银行,收款银行所在省份,收款银行所在市,收款支行名称,金额,对公对私标志,备注\r\n" + Body;
         Random random = new Random();
         string str8 = (random.Next(1, 0x3e7).ToString() + now.Hour.ToString() + now.Minute.ToString() + now.Second.ToString()).PadLeft(9, '0');
         str = "PAPX_" + str5 + "_P" + str8 + ".csv".ToLower();
         path = base.MapPath("../App_Log/Admin/AlipayPayment/PABX/" + str).ToLower();
         fileName = "PAPX_" + str5 + "_P" + str8 + ".Zip".ToLower();
         str4 = base.MapPath("../App_Log/Admin/AlipayPayment/PABX/" + fileName).ToLower();
         if (!System.IO.File.Exists(path))
         {
             try
             {
                 if (!Shove._IO.File.WriteFile(path, Body))
                 {
                     Procedures.P_UserDistillPayByAlipayWriteLog("CSV文件写入失败:" + path);
                     JavaScript.Alert(this.Page, "CSV文件写入失败");
                     return;
                 }
                 if (System.IO.File.Exists(path))
                 {
                     if (System.IO.File.Exists(str4))
                     {
                         goto Label_0388;
                     }
                     try
                     {
                         Shove._IO.File.Compress(path, str4);
                         goto Label_0388;
                     }
                     catch
                     {
                         Procedures.P_UserDistillPayByAlipayWriteLog("文件压缩出现异常:" + path);
                         JavaScript.Alert(this.Page, "文件压缩出现异常");
                         return;
                     }
                 }
                 Procedures.P_UserDistillPayByAlipayWriteLog("CSV文件不存在(1):" + path);
                 JavaScript.Alert(this.Page, "CSV文件不存在");
                 return;
             }
             catch
             {
                 Procedures.P_UserDistillPayByAlipayWriteLog("CSV文件写入异常:" + path);
                 JavaScript.Alert(this.Page, "CSV文件写入异常");
                 return;
             }
         }
         JavaScript.Alert(this.Page, "文件写已存在");
         return;
     }
     Label_0388:
     if (!System.IO.File.Exists(str4))
     {
         Procedures.P_UserDistillPayByAlipayWriteLog("ZIP文件不存在(2):" + path);
         JavaScript.Alert(this.Page, "ZIP文件不存在");
     }
     else
     {
         byte[] buffer4;
         byte[] date = System.IO.File.ReadAllBytes(str4);
         this.digest_bptb_pay_file = Shove.Alipay.Alipay.GetMD5(date, this._input_charset);
         string[] strArray4 = alipay.GetUploadParams(this.service, this._input_charset, this.partner, this.file_digest_type, this.biz_type, this.agentID);
         FileStream stream = new FileStream(str4, FileMode.Open, FileAccess.Read, FileShare.Read);
         string contentType = "application/octet-stream";
         byte[] buffer = new byte[stream.Length];
         stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
         stream.Close();
         CreateBytes bytes = new CreateBytes();
         ArrayList byteArrays = new ArrayList();
         string[] fields = new string[strArray4.Length + 1];
         char[] separator = new char[] { '=' };
         index = 0;
         while (index < strArray4.Length)
         {
             string fieldName = strArray4[index].Split(separator)[0];
             string fieldValue = strArray4[index].Split(separator)[1];
             byteArrays.Add(bytes.CreateFieldData(fieldName, fieldValue));
             fields[index] = fieldName + "=" + fieldValue;
             index++;
         }
         byteArrays.Add(bytes.CreateFieldData("digest_bptb_pay_file", this.digest_bptb_pay_file));
         fields[index] = "digest_bptb_pay_file=" + this.digest_bptb_pay_file;
         this.sign = AlipayCommon.GetSign(fields, this.key).Trim();
         byteArrays.Add(bytes.CreateFieldData("sign", this.sign));
         byteArrays.Add(bytes.CreateFieldData("sign_type", "MD5"));
         byteArrays.Add(bytes.CreateFieldData("bptb_pay_file", str4, contentType, buffer));
         byte[] buffer3 = bytes.JoinBytes(byteArrays);
         if (!bytes.UploadData(this.gateway, buffer3, out buffer4))
         {
             Procedures.P_UserDistillPayByAlipayWriteLog("上传到指定Url失败:" + path);
             try
             {
                 System.IO.File.Delete(path);
                 System.IO.File.Delete(str4);
             }
             catch
             {
             }
             JavaScript.Alert(this.Page, "上传支付数据到指定Url失败!");
         }
         else
         {
             string str12 = Encoding.Default.GetString(buffer4);
             if (str12.IndexOf("上传成功") >= 0)
             {
                 int returnValue = 0;
                 string returnDescription = "";
                 if (Procedures.P_UserDistillPayByAlipay(base._User.ID, fileName, UserDistillIDs, 2, ref returnValue, ref returnDescription) < 0)
                 {
                     Procedures.P_UserDistillPayByAlipayWriteLog("提款ID:" + UserDistillIDs + "写入数据库(FileName)和更新状态失败。");
                 }
                 if (returnDescription != "")
                 {
                     Procedures.P_UserDistillPayByAlipayWriteLog("把上传的支付明细写入数据库(FileName)和更新状态出错:" + returnDescription);
                     JavaScript.Alert(this.Page, "出错:" + returnDescription);
                     this.BindData(true);
                 }
                 else
                 {
                     JavaScript.Alert(this.Page, str12 + "银行处理需要到明天才有结果,请耐心等待处理结果!");
                     this.BindData(true);
                 }
             }
             else
             {
                 Procedures.P_UserDistillPayByAlipayWriteLog("上传支付到银行明细失败:" + str12);
                 JavaScript.Alert(this.Page, str12.Replace("\n", "").Replace("\r", ""));
             }
         }
     }
 }