918²©ÌìÌÃ

Server : Microsoft-IIS/10.0
System : Windows NT EBS-6136 10.0 build 17763 (Windows Server 2016) i586
User : jxgj ( 0)
PHP Version : 7.0.33
Disable Function : passthru,exec,system,shell_exec,proc_open,popen,pcntl_exec,socket_bind,stream_socket_server
Directory :  D:/tmp_aspnet/root/c87b3efd/cc6243dc/
Upload File :
Current Directory [ Writeable ] Root Directory [ Writeable ]


Current File : D:/tmp_aspnet/root/c87b3efd/cc6243dc/App_Code.ikzyaddn.3.cs
?#pragma checksum "D:\wwwroot\zgyzd233com\wwwroot\App_Code\AlipaySubmit.cs" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "9F44C35BA9820B43C6D493130B59917A"

#line 1 "D:\wwwroot\zgyzd233com\wwwroot\App_Code\AlipaySubmit.cs"
using System.Web;
using System.Text;
using System.IO;
using System.Net;
using System;
using System.Collections.Generic;
using System.Xml;

namespace Com.Alipay
{
    /// <summary>
    /// ÀàÃû£ºSubmit
    /// Ö°ÄÜ£ºÖ§¸¶±¦¸÷½Ó¿ÚÒªÇóÌá½»Àà
    /// ¾ßÌ壺»ú¹ØÖ§¸¶±¦¸÷½Ó¿Ú±íµ¥HTMLÎı¾£¬»ñȡԶ³ÌHTTPÊý¾Ý
    /// °æ±¾£º3.3
    /// Åú¸ÄÈÕÆÚ£º2011-07-05
    /// ×¢Ã÷£º
    /// ÒÔÏ´úÂëÖ»ÊÇΪÁË·½±ãÉÌ»§²âÊÔ¶øÌṩµÄÑùÀý´úÂë£¬ÉÌ»§Äܹ»Æ¾¾Ý×Ô¼ºÍøÕ¾µÄ±ØÒª£¬ÒÀÕÕ¼¼ÊõÎĵµ±àд,²¢·Ç¿Ï¶¨ÒªÊ¹ÓøôúÂë¡£
    /// ¸Ã´úÂë½ö¹©½ø½¨ºÍ×êÑÐÖ§¸¶±¦½Ó¿ÚʹÓÃ£¬Ö»ÊÇÌṩһ¸ö²Î¿¼
    /// </summary>
    public class Submit
    {
        #region ×Ö¶Î
        //Ö§¸¶±¦Íø¹ØµØÖ·£¨Ð£©
        private static string GATEWAY_NEW = "https://mapi.alipay.com/gateway.do?";
        //ÉÌ»§µÄ˽Կ
        private static string _key = "";
        //±àÂëÌåʽ
        private static string _input_charset = "";
        //ÊðÃû·½Ê½
        private static string _sign_type = "";
        #endregion

        static Submit()
        {
            _key = Config.Key.Trim();
            _input_charset = Config.Input_charset.Trim().ToLower();
            _sign_type = Config.Sign_type.Trim().ToUpper();
        }

        /// <summary>
        /// ÌìÉúÒªÇóʱµÄÊðÃû
        /// </summary>
        /// <param name="sPara">ÒªÇó¸øÖ§¸¶±¦µÄ²ÎÊýÊý×é</param>
        /// <returns>ÊðÃûÁ˾Ö</returns>
        private static string BuildRequestMysign(Dictionary<string, string> sPara)
        {
            //°ÑÊý×éËùÓÐÔªËØ£¬ÒÀÕÕ¡°²ÎÊý=²ÎÊýÖµ¡±µÄģʽÓá°&¡±×Ö·ûÆ´½Ó³É×Ö·û´®
            string prestr = Core.CreateLinkString(sPara);

            //°Ñ×îÖÕµÄ×Ö·û´®ÊðÃû£¬»ñµÃÊðÃûÁ˾Ö
            string mysign = "";
            switch (_sign_type)
            {
                case "MD5":
                    mysign = AlipayMD5.Sign(prestr, _key, _input_charset);
                    break;
                default:
                    mysign = "";
                    break;
            }

            return mysign;
        }

        /// <summary>
        /// ÌìÉúÒªÒªÇó¸øÖ§¸¶±¦µÄ²ÎÊýÊý×é
        /// </summary>
        /// <param name="sParaTemp">ÒªÇóǰµÄ²ÎÊýÊý×é</param>
        /// <returns>ÒªÒªÇóµÄ²ÎÊýÊý×é</returns>
        private static Dictionary<string, string> BuildRequestPara(SortedDictionary<string, string> sParaTemp)
        {
            //´ýÊðÃûÒªÇó²ÎÊýÊý×é
            Dictionary<string, string> sPara = new Dictionary<string, string>();
            //ÊðÃûÁ˾Ö
            string mysign = "";

            //¹ýÂËÊðÃû²ÎÊýÊý×é
            sPara = Core.FilterPara(sParaTemp);

            //»ñµÃÊðÃûÁ˾Ö
            mysign = BuildRequestMysign(sPara);

            //ÊðÃûÁ˾ÖÓëÊðÃû·½Ê½²ÎÓëÒªÇóÌá½»²ÎÊý×éÖÐ
            sPara.Add("sign", mysign);
            sPara.Add("sign_type", _sign_type);

            return sPara;
        }

        /// <summary>
        /// ÌìÉúÒªÒªÇó¸øÖ§¸¶±¦µÄ²ÎÊýÊý×é
        /// </summary>
        /// <param name="sParaTemp">ÒªÇóǰµÄ²ÎÊýÊý×é</param>
        /// <param name="code">×Ö·û±àÂë</param>
        /// <returns>ÒªÒªÇóµÄ²ÎÊýÊý×é×Ö·û´®</returns>
        private static string BuildRequestParaToString(SortedDictionary<string, string> sParaTemp, Encoding code)
        {
            //´ýÊðÃûÒªÇó²ÎÊýÊý×é
            Dictionary<string, string> sPara = new Dictionary<string, string>();
            sPara = BuildRequestPara(sParaTemp);

            //°Ñ²ÎÊý×éÖÐËùÓÐÔªËØ£¬ÒÀÕÕ¡°²ÎÊý=²ÎÊýÖµ¡±µÄģʽÓá°&¡±×Ö·ûÆ´½Ó³É×Ö·û´®£¬²¢¶Ô²ÎÊýÖµ×öurlencode
            string strRequestData = Core.CreateLinkStringUrlencode(sPara, code);

            return strRequestData;
        }

        /// <summary>
        /// ³ÉÁ¢ÒªÇó£¬ÒÔ±íµ¥HTML´ó¾Ö»ú¹Ø£¨Ä¬ÈÏ£©
        /// </summary>
        /// <param name="sParaTemp">ÒªÇó²ÎÊýÊý×é</param>
        /// <param name="strMethod">Ìá½»·½Ê½¡£Á½¸öÖµ¿ÉÑ¡£ºpost¡¢get</param>
        /// <param name="strButtonValue">È·Èϰ´Å¥ÏÔʾÎÄ×Ö</param>
        /// <returns>Ìá½»±íµ¥HTMLÎı¾</returns>
        public static string BuildRequest(SortedDictionary<string, string> sParaTemp, string strMethod, string strButtonValue)
        {
            //´ýÒªÇó²ÎÊýÊý×é
            Dictionary<string, string> dicPara = new Dictionary<string, string>();
            dicPara = BuildRequestPara(sParaTemp);

            StringBuilder sbHtml = new StringBuilder();

            sbHtml.Append("<form id='alipaysubmit' name='alipaysubmit' action='" + GATEWAY_NEW + "_input_charset=" + _input_charset + "' method='" + strMethod.ToLower().Trim() + "'>");

            foreach (KeyValuePair<string, string> temp in dicPara)
            {
                sbHtml.Append("<input type='hidden' name='" + temp.Key + "' value='" + temp.Value + "'/>");
            }

            //submit°´Å¥¿Ø¼þÇë²»Òªº¬ÓÐnameÊôÐÔ
            sbHtml.Append("<input type='submit' value='" + strButtonValue + "' style='display:none;'></form>");

            sbHtml.Append("<script>document.forms['alipaysubmit'].submit();</script>");

            return sbHtml.ToString();
        }


        /// <summary>
        /// ³ÉÁ¢ÒªÇó£¬ÒÔ·ÂÕÕÔ¶³ÌHTTPµÄPOSTÒªÇó·½Ê½»ú¹Ø²¢»ñȡ֧¸¶±¦µÄ´¦ÖÃÁ˾Ö
        /// </summary>
        /// <param name="sParaTemp">ÒªÇó²ÎÊýÊý×é</param>
        /// <returns>Ö§¸¶±¦´¦ÖÃÁ˾Ö</returns>
        public static string BuildRequest(SortedDictionary<string, string> sParaTemp)
        {
            Encoding code = Encoding.GetEncoding(_input_charset);

            //´ýÒªÇó²ÎÊýÊý×é×Ö·û´®
            string strRequestData = BuildRequestParaToString(sParaTemp,code);

            //°ÑÊý×éת»»³ÉÁ÷ÖÐËùÐè×Ö½ÚÊý×éÀàÐÍ
            byte[] bytesRequestData = code.GetBytes(strRequestData);

            //»ú¹ØÒªÇóµØÖ·
            string strUrl = GATEWAY_NEW + "_input_charset=" + _input_charset;

            //ÒªÇóÔ¶³ÌHTTP
            string strResult = "";
            try
            {
                //ÉèÖÃHttpWebRequest¸ù»ùÐÅÏ¢
                HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(strUrl);
                myReq.Method = "post";
                myReq.ContentType = "application/x-www-form-urlencoded";

                //Ìî³äPOSTÊý¾Ý
                myReq.ContentLength = bytesRequestData.Length;
                Stream requestStream = myReq.GetRequestStream();
                requestStream.Write(bytesRequestData, 0, bytesRequestData.Length);
                requestStream.Close();

                //·¢ËÍPOSTÊý¾ÝÒªÇó·þÎñÆ÷
                HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
                Stream myStream = HttpWResp.GetResponseStream();

                //»ñÈ¡·þÎñÆ÷·µ»ØÐÅÏ¢
                StreamReader reader = new StreamReader(myStream, code);
                StringBuilder responseData = new StringBuilder();
                String line;
                while ((line = reader.ReadLine()) != null)
                {
                    responseData.Append(line);
                }

                //¿ªÊÍ
                myStream.Close();

                strResult = responseData.ToString();
            }
            catch (Exception exp)
            {
                strResult = "±¨´í£º"+exp.Message;
            }

            return strResult;
        }

        /// <summary>
        /// ³ÉÁ¢ÒªÇó£¬ÒÔ·ÂÕÕÔ¶³ÌHTTPµÄPOSTÒªÇó·½Ê½»ú¹Ø²¢»ñȡ֧¸¶±¦µÄ´¦ÖÃÁ˾Ö£¬´øÎļþÉÏ´«Ö°ÄÜ
        /// </summary>
        /// <param name="sParaTemp">ÒªÇó²ÎÊýÊý×é</param>
        /// <param name="strMethod">Ìá½»·½Ê½¡£Á½¸öÖµ¿ÉÑ¡£ºpost¡¢get</param>
        /// <param name="fileName">Îļþ¾ø¶Ôõè¾¶</param>
        /// <param name="data">ÎļþÊý¾Ý</param>
        /// <param name="contentType">ÎļþÄÚÈÝÀàÐÍ</param>
        /// <param name="lengthFile">Îļþ³¤¶È</param>
        /// <returns>Ö§¸¶±¦´¦ÖÃÁ˾Ö</returns>
        public static string BuildRequest(SortedDictionary<string, string> sParaTemp, string strMethod, string fileName, byte[] data, string contentType, int lengthFile)
        {

            //´ýÒªÇó²ÎÊýÊý×é
            Dictionary<string, string> dicPara = new Dictionary<string, string>();
            dicPara = BuildRequestPara(sParaTemp);

            //»ú¹ØÒªÇóµØÖ·
            string strUrl = GATEWAY_NEW + "_input_charset=" + _input_charset;

            //ÉèÖÃHttpWebRequest¸ù»ùÐÅÏ¢
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(strUrl);
            //ÉèÖÃÒªÇó·½Ê½£ºget¡¢post
            request.Method = strMethod;
            //ÉèÖÃboundaryValue
            string boundaryValue = DateTime.Now.Ticks.ToString("x");
            string boundary = "--" + boundaryValue;
            request.ContentType = "\r\nmultipart/form-data; boundary=" + boundaryValue;
            //ÉèÖÃKeepAlive
            request.KeepAlive = true;
            //ÉèÖÃÒªÇóÊý¾Ý£¬Æ´½Ó³É×Ö·û´®
            StringBuilder sbHtml = new StringBuilder();
            foreach (KeyValuePair<string, string> key in dicPara)
            {
                sbHtml.Append(boundary + "\r\nContent-Disposition: form-data; name=\"" + key.Key + "\"\r\n\r\n" + key.Value + "\r\n");
            }
            sbHtml.Append(boundary + "\r\nContent-Disposition: form-data; name=\"withhold_file\"; filename=\"");
            sbHtml.Append(fileName);
            sbHtml.Append("\"\r\nContent-Type: " + contentType + "\r\n\r\n");
            string postHeader = sbHtml.ToString();
            //½«ÒªÇóÊý¾Ý×Ö·û´®ÀàÐÍÆ¾¾Ý±àÂëÌåʽת»»³É×Ö½ÚÁ÷
            Encoding code = Encoding.GetEncoding(_input_charset);
            byte[] postHeaderBytes = code.GetBytes(postHeader);
            byte[] boundayBytes = Encoding.ASCII.GetBytes("\r\n" + boundary + "--\r\n");
            //ÉèÖó¤¶È
            long length = postHeaderBytes.Length + lengthFile + boundayBytes.Length;
            request.ContentLength = length;

            //ÒªÇóÔ¶³ÌHTTP
            Stream requestStream = request.GetRequestStream();
            Stream myStream;
            try
            {
                //·¢ËÍÊý¾ÝÒªÇó·þÎñÆ÷
                requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
                requestStream.Write(data, 0, lengthFile);
                requestStream.Write(boundayBytes, 0, boundayBytes.Length);
                HttpWebResponse HttpWResp = (HttpWebResponse)request.GetResponse();
                myStream = HttpWResp.GetResponseStream();
            }
            catch (WebException e)
            {
                return e.ToString();
            }
            finally
            {
                if (requestStream != null)
                {
                    requestStream.Close();
                }
            }

            //¶Áȡ֧¸¶±¦·µ»Ø´¦ÖÃÁ˾Ö
            StreamReader reader = new StreamReader(myStream, code);
            StringBuilder responseData = new StringBuilder();

            String line;
            while ((line = reader.ReadLine()) != null)
            {
                responseData.Append(line);
            }
            myStream.Close();
            return responseData.ToString();
        }

        /// <summary>
        /// ÓÃÓÚ·À´¹µö£¬Å²ÓýӿÚquery_timestampÀ´»ñÈ¡¹¦·ò´ÁµÄ´¦Öú¯Êý
        /// °ÑÎÈ£ºÔ¶³Ì½âÎöXML·¸´í£¬ÓëIIS·þÎñÆ÷ÅäÖÃÓйØ
        /// </summary>
        /// <returns>¹¦·ò´Á×Ö·û´®</returns>
        public static string Query_timestamp()
        {
            string url = GATEWAY_NEW + "service=query_timestamp&partner=" + Config.Partner + "&_input_charset=" + Config.Input_charset;
            string encrypt_key = "";

            XmlTextReader Reader = new XmlTextReader(url);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Reader);

            encrypt_key = xmlDoc.SelectSingleNode("/alipay/response/timestamp/encrypt_key").InnerText;

            return encrypt_key;
        }
    }
}

#line default
#line hidden