如何通过WCF调用Pay U Money服务器?

时间:2017-10-23 12:49:11

标签: wcf payumoney

我正在为Pay you Money创建一个wcf服务我为pay you Money编写了类似asp.net c#的代码,但是使用HttpWebRequest我面临这个错误:

  

SORRY!我们无法处理您的付款

我在简单的asp.net c#中试过相同的代码并且工作正常。在这里,我不知道出了什么问题,我怎么能解决这个问题?

enter code here

      public PayUMoneyModel PayUMoney(PayUMoneyModel Data)
    {
        PayUMoneyModel objPayUMoneyModel = new PayUMoneyModel();
        action1 = ConfigurationManager.AppSettings["PAYU_BASE_URL"] + 
        "/_payment";
        try
        {

            string[] hashVarsSeq;
            string hash_string = string.Empty;


            if (string.IsNullOrEmpty(Data.txnid)) // generating txnid
            {
                Random rnd = new Random();
                string strHash = Generatehash512(rnd.ToString() + 
                 DateTime.Now);
                txnid1 = strHash.ToString().Substring(0, 20);

            }
            else if(Data.txnid!=null)
            {
                txnid1 = Data.txnid;
            }


               Data.txnid = txnid1;
                Data.key= ConfigurationManager.AppSettings["MERCHANT_KEY"];
                string salt= ConfigurationManager.AppSettings["SALT"];
            System.Collections.Hashtable data = new System.Collections.Hashtable();

            data.Add("key", Data.key);
            data.Add("txnid", Data.txnid);

           string AmountForm = Convert.ToDecimal(Data.amount).ToString("g29");// eliminating trailing zeros

            //amount.Text = AmountForm;

            data.Add("amount", 1.00);
            data.Add("firstname", Data.firstname);
            data.Add("email", Data.email);
            data.Add("phone", Data.phone);
            data.Add("productinfo", Data.productinfo);
            data.Add("surl", Data.surl);
            data.Add("furl", Data.furl);
            data.Add("lastname", Data.lastname);
            data.Add("curl", Data.curl);
            data.Add("address1", Data.address1);
            data.Add("address2", Data.address2);
            data.Add("city", Data.city);
            data.Add("state", Data.state);
            data.Add("country",Data.country);
            data.Add("zipcode", Data.zipcode);
            data.Add("udf1", Data.udf1);
            data.Add("udf2", Data.udf2);
            data.Add("udf3", Data.udf3);
            data.Add("udf4", Data.udf4);
            data.Add("udf5", Data.udf5);
            data.Add("pg", Data.pg);

            data.Add("service_provider", "payu_paisa");
     hash_string = Data.key + "|" + Data.txnid + "|" + AmountForm + "|" + Data.productinfo+ "|" + Data.firstname + "|" + Data.email + "|||||||||||" + salt;
              string hash = Generatehash512(hash_string);
            data.Add("hash", hash);
            data.Add("abc", hash_string);
            string strForm = PreparePOSTForm(action1, data);

            if (strForm != "")
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(action1);
               // httpWebRequest.ContentType = "text/html";
               httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentLength = strForm.Length;
                string Json = "";
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(strForm,0,strForm.Length);
                    streamWriter.Flush();
                    streamWriter.Close();
                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        Json = streamReader.ReadToEnd().Replace(";", "");
                    }
                }
                HttpContext.Current.Response.Write(Json);
            }

        }
        catch(Exception ex)
        {
            throw ex;
        }
        return objPayUMoneyModel;
    }

这是我的帖子表格方法

      private string PreparePOSTForm(string url, System.Collections.Hashtable data)      // post form
    {
        //Set a name for the form
        string formID = "PostForm";
        //Build the form using the specified data to be posted.
        StringBuilder strForm = new StringBuilder();
        strForm.Append("<form id=\"" + formID + "\" name=\"" +
                       formID + "\" action=\"" + url +
                       "\" method=\"POST\">");

        foreach (System.Collections.DictionaryEntry key in data)
        {

            strForm.Append("<input type=\"hidden\" name=\"" + key.Key +
                           "\" value=\"" + key.Value + "\">");
        }


        strForm.Append("</form>");
        //Build the JavaScript which will do the Posting operation.
        StringBuilder strScript = new StringBuilder();
        strScript.Append("<script language='javascript'>");
        strScript.Append("var v" + formID + " = document." +
                         formID + ";");
        strScript.Append("v" + formID + ".submit();");
        strScript.Append("</script>");
        //Return the form and the script concatenated.
        //(The order is important, Form then JavaScript)
        return strForm.ToString() + strScript.ToString();
    }

这是Payumoney网站提供的关键和盐: - 重点:-rjQUPktU 盐:-e5iIg1jwi8

0 个答案:

没有答案