Esempio n. 1
0
        /// <summary>
        /// 构造支付宝批量付款到支付宝账户有密接口
        /// </summary>
        /// <param name="payDetail"></param>
        /// <param name="batch_no">保证其唯一性,格式:当天日期[8位]+序列号[3至16位],如:201101010000001</param>
        public void BatchTransfers(List <BatchPayItem> payDetail, string batch_no)
        {
            string pay_date = DateTime.Now.ToString("yyyyMMdd");
            //获取当天日期,格式:年[4位]月[2位]日[2位],如:20110101

            //保证其唯一性,格式:当天日期[8位]+序列号[3至16位],如:201101010000001

            //格式:流水号1^收款方帐号1^收款帐号1真实姓名^付款金额1^备注说明1|流水号2^收款方帐号2^收款帐号2真实姓名^付款金额2^备注说明2....
            double total = 0;
            //付款详细数据
            string detail_data = "";

            foreach (BatchPayItem s in payDetail)
            {
                total       += s.Amount;
                detail_data += s.ToString() + "|";
            }
            detail_data = detail_data.Substring(0, detail_data.Length - 1);
            //付款总笔数
            string batch_num = payDetail.Count.ToString();
            //批量付款笔数(最少1笔,最多1000笔)。

            //付款总金额
            string batch_fee = total.ToString();

            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();

            sParaTemp.Add("pay_date", pay_date);
            sParaTemp.Add("batch_no", batch_no);
            sParaTemp.Add("batch_num", batch_num);
            sParaTemp.Add("batch_fee", batch_fee);
            sParaTemp.Add("detail_data", detail_data);

            //增加基本配置
            sParaTemp.Add("service", "batch_trans_notify");
            sParaTemp.Add("partner", partner);
            sParaTemp.Add("_input_charset", _input_charset);
            sParaTemp.Add("email", seller_email);
            sParaTemp.Add("notify_url", notify_url);
            sParaTemp.Add("account_name", _account_name);

            //确认按钮显示文字
            string strButtonValue = "确认";

            //表单提交HTML数据
            string strHtml = "";

            //构造表单提交XML数据
            strHtml = AlipaySubmit.BuildRequest(sParaTemp, "post", strButtonValue);
            HttpContext.Current.Response.Write(strHtml);
            HttpContext.Current.Response.End();
        }
Esempio n. 2
0
        public override bool RefundOrder(IPayHistory order, out string message)
        {
            message = "";
            if (string.IsNullOrEmpty(order.spBillno))
            {
                throw new Exception("支付宝订单号为空,请检查sp_billno");
            }
            ////////////////////////////////////////////请求参数////////////////////////////////////////////

            //服务器异步通知页面路径
            string notify_url = refundNotifyUrl;
            //需http://格式的完整路径,不允许加?id=123这类自定义参数

            //退款批次号
            string batch_no = DateTime.Now.ToString("yyyyMMdd") + order.OrderId.Substring(6, order.OrderId.Length - 6) + "C";
            //必填,每进行一次即时到账批量退款,都需要提供一个批次号,必须保证唯一性

            //退款请求时间
            string refund_date = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            //必填,格式为:yyyy-MM-dd hh:mm:ss

            //退款总笔数
            string batch_num = "1";
            //必填,即参数detail_data的值中,“#”字符出现的数量加1,最大支持1000笔(即“#”字符出现的最大数量999个)

            //单笔数据集
            string detail_data = order.spBillno + "^" + order.Amount + "^协商退款";
            //必填,格式详见“4.3 单笔数据集参数说明”
            //Log(detail_data);

            ////////////////////////////////////////////////////////////////////////////////////////////////

            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();

            sParaTemp.Add("partner", partner);
            sParaTemp.Add("_input_charset", _input_charset);
            sParaTemp.Add("service", "refund_fastpay_by_platform_nopwd");
            sParaTemp.Add("notify_url", notify_url);
            sParaTemp.Add("batch_no", batch_no);
            sParaTemp.Add("refund_date", refund_date);
            sParaTemp.Add("batch_num", batch_num);
            sParaTemp.Add("detail_data", detail_data);

            //建立请求
            string sHtmlText = AlipaySubmit.BuildRequest(sParaTemp);

            //请在这里加上商户的业务逻辑程序代码

            //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(sHtmlText);
            Log(sHtmlText);
            string status = xmlDoc.SelectSingleNode("/alipay/is_success").InnerText;

            if (status == "F")
            {
                message = "退款失败:" + xmlDoc.SelectSingleNode("/alipay/error").InnerText;
                return(false);
            }
            else
            {
                if (status == "T")
                {
                    message = "退款成功";
                    BaseRefundOrder(order);
                    return(true);
                }
                else if (status == "P")
                {
                    message = "退款处理中";
                    //退款通知会用及时到帐接口发过来
                    return(true);
                }
                return(false);
            }
        }