Esempio n. 1
0
        /// <summary>
        /// 发送请求
        /// </summary>
        /// <param name="postURL">请求地址</param>
        /// <returns></returns>
        public static string SendRequest(string postData, string postURL, string encodingStr)
        {
            PayLogs.WriteLogs("请求:" + postURL + "\r\n" + postData);

            try
            {
                WebRequest req = WebRequest.Create(postURL);
                req.Method      = "POST";
                req.ContentType = "application/x-www-form-urlencoded;charset=" + encodingStr;
                req.Timeout     = 100000;

                using (StreamWriter sw = new StreamWriter(req.GetRequestStream(), Encoding.GetEncoding(encodingStr)))
                {
                    sw.Write(postData);
                }

                using (WebResponse response = req.GetResponse())
                {
                    using (Stream sr = response.GetResponseStream())
                    {
                        byte[]       tmpByte   = new byte[1024];
                        int          n         = 1;
                        MemoryStream stmMemory = new MemoryStream();

                        while (n > 0)
                        {
                            n = sr.Read(tmpByte, 0, tmpByte.Length);
                            stmMemory.Write(tmpByte, 0, n);
                        }

                        string receiveData = Encoding.GetEncoding(encodingStr).GetString(stmMemory.ToArray());

                        PayLogs.WriteLogs("返回:" + postURL + "\r\n" + receiveData);

                        return(receiveData);
                    }
                }
            }
            catch (Exception ex)
            {
                PayLogs.WriteLogs(ex);
                return(null);
            }
        }
        /// <summary>
        /// 强制转账
        /// </summary>
        /// <param name="payAccNo">付款账号</param>
        /// <param name="recvAccNo">收款账号</param>
        /// <param name="recvAccNm">收款账号名</param>
        /// <param name="memo">备注</param>
        /// <param name="tranAmt">金额</param>
        /// <param name="strResult">返回说明</param>
        /// <returns></returns>
        public bool Transfer(string payAccNo, string recvAccNo, string recvAccNm, string memo, double tranAmt, ref string strResult, string supplier_name)
        {
            StringBuilder PostData     = new StringBuilder();
            string        Payment_Flow = DateTime.Now.ToString("yyyyMMddHHmmss") + new Public_Class().Createvkey(6);

            PostData.Append("<?xml version=\"1.0\" encoding=\"GBK\" ?>");
            PostData.Append("<stream>");
            PostData.Append("	<action>DLMDETRN</action>");
            PostData.Append("	<userName>"+ userName + "</userName>");
            //PostData.Append("	<clientID>" + DateTime.Now.ToString("yyyyMMddHHmmss") + new Public_Class().Createvkey(6) + "</clientID>");
            PostData.Append("	<clientID>"+ Payment_Flow + "</clientID>");
            PostData.Append("	<accountNo>"+ mainAccNo + "</accountNo>");
            PostData.Append("	<payAccNo>"+ payAccNo + "</payAccNo>");
            PostData.Append("	<tranType>BF</tranType>");
            PostData.Append("	<recvAccNo>"+ recvAccNo + "</recvAccNo>");
            PostData.Append("	<recvAccNm>"+ recvAccNm + "</recvAccNm>");
            PostData.Append("	<tranAmt>"+ tranAmt + "</tranAmt>");
            PostData.Append("	<freezeNo></freezeNo>");
            PostData.Append("	<ofreezeamt></ofreezeamt>");
            PostData.Append("	<memo>"+ memo + "</memo>");
            PostData.Append("	<tranFlag>1</tranFlag>");
            PostData.Append("</stream>");

            string xmlResult = HttpUtil.SendRequest(PostData.ToString(), PostServer, encodingStr);

            DateTime CurTime = DateTime.Now;
            PaymentInformationInfo payInfoEntity = new PaymentInformationInfo();

            //付款账户
            payInfoEntity.Payment_PayingTeller = supplier_name;
            //付款账号
            payInfoEntity.Payment_Account = payAccNo;
            //收款账号
            payInfoEntity.Payment_Receivable = recvAccNo;
            //收款账户
            payInfoEntity.Payment_Account_Receivable = recvAccNm;

            //担保类型付款类型 1担保付款 2货款结算  3出金   4收取交易佣金  5支付投标保证金  6退还投标保证金  7支付商家保证金 8退还商家保证金 9其它

            payInfoEntity.Payment_Type = 0;
            //付款金额
            payInfoEntity.Payment_Amount = tranAmt;
            //备注信息
            payInfoEntity.Payment_Remarks = memo;
            //付款时间
            payInfoEntity.Payment_Account_Time = CurTime;



            if (xmlResult == null || xmlResult.Length == 0)
            {
                //付款状态
                payInfoEntity.Payment_Status   = 2;
                payInfoEntity.Payment_Flow     = Payment_Flow;
                payInfoEntity.Payment_Remarks1 = "中信支付备注说明:付款账户:" + supplier_name + ",付款账号:" + payAccNo + ",收款账户:" + recvAccNm + ",收款账号:" + recvAccNo + ",付款类型:" + "" + memo + "" + ", 付款金额:" + tranAmt + ",备注信息:" + memo + ",付款时间:" + CurTime + ",请求失败(没有返回数据),流水号:" + Payment_Flow + "";
                PayLogs.WriteLogs(PostData.ToString());
                strResult = "请求失败";

                MyPayInfo.AddPaymentInformation(payInfoEntity);
                return(false);
            }

            if (StatusCode(xmlResult) == "t")
            {
                strResult = GetXMLElement(xmlResult, "/stream/statusText");

                //付款状态
                payInfoEntity.Payment_Status   = 1;
                payInfoEntity.Payment_Flow     = Payment_Flow;
                payInfoEntity.Payment_Remarks1 = "中信支付备注说明:付款账户:" + supplier_name + ",付款账号:" + payAccNo + ",收款账户:" + recvAccNm + ",收款账号:" + recvAccNo + ",付款类型:" + "" + memo + "" + ", 付款金额:" + tranAmt + ",备注信息:" + memo + ",付款时间:" + CurTime + ",付款成功:,流水号:" + Payment_Flow + "";
                PayLogs.WriteLogs(PostData.ToString());
                MyPayInfo.AddPaymentInformation(payInfoEntity);
                return(true);
            }
            else if (tranAmt == 0)
            {
                strResult = GetXMLElement(xmlResult, "/stream/statusText");

                //付款状态
                payInfoEntity.Payment_Status   = 1;
                payInfoEntity.Payment_Flow     = Payment_Flow;
                payInfoEntity.Payment_Remarks1 = "中信支付备注说明:付款账户:" + supplier_name + ",付款账号:" + payAccNo + ",收款账户:" + recvAccNm + ",收款账号:" + recvAccNo + ",付款类型:" + "" + memo + "" + ", 付款金额:" + tranAmt + ",备注信息:" + memo + ",付款时间:" + CurTime + ",付款成功:,流水号:" + Payment_Flow + "";
                PayLogs.WriteLogs(PostData.ToString());
                MyPayInfo.AddPaymentInformation(payInfoEntity);
                return(true);
            }
            else
            {
                strResult = GetXMLElement(xmlResult, "/stream/statusText");
                payInfoEntity.Payment_Status   = 0;
                payInfoEntity.Payment_Flow     = Payment_Flow;
                payInfoEntity.Payment_Remarks1 = "中信支付备注说明:付款账户:" + supplier_name + ",付款账号:" + payAccNo + ",收款账户:" + recvAccNm + ",收款账号:" + recvAccNo + ",付款类型:" + "" + memo + "" + ", 付款金额:" + tranAmt + ",备注信息:" + memo + ",付款时间:" + CurTime + ",付款状态:付款失败,流水号:" + Payment_Flow + "";
                PayLogs.WriteLogs(PostData.ToString());
                MyPayInfo.AddPaymentInformation(payInfoEntity);
                return(false);
            }
        }
Esempio n. 3
0
 public static void WriteLogs(Exception ex)
 {
     PayLogs.WriteLogs("错误记录:" + ex.Message + "\r\n" + ex.StackTrace);
 }