标签:
目前来看,PC段实现微信支付,需要生成二维码,然后用微信扫码支付。
1 public static string Get_Code_URL(SortedDictionary<string, string> sParaTemp) 2 { 3 StringBuilder submitStr = new StringBuilder(); //要提交的数据 4 Dictionary<string, string> dPara = BuildRequestPara(sParaTemp); 5 submitStr.Append("<xml>"); 6 foreach (KeyValuePair<string, string> kvp in dPara) 7 { 8 submitStr.Append("<" + kvp.Key + ">" + kvp.Value + "</" + kvp.Key + ">"); 9 } 10 submitStr.Append("</xml>"); 11 12 //提交 13 HttpWebRequest request = WebRequest.Create(PAY_URL) as HttpWebRequest; 14 byte[] requestBytes = Encoding.GetEncoding("UTF-8").GetBytes(submitStr.ToString()); 15 request.Method = "POST"; 16 request.ContentType = "text/xml"; 17 request.ContentLength = requestBytes.Length; 18 Stream requestStream = request.GetRequestStream(); 19 requestStream.Write(requestBytes, 0, requestBytes.Length); 20 requestStream.Close(); 21 22 //获取结果 23 HttpWebResponse response = request.GetResponse() as HttpWebResponse; 24 StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.GetEncoding("UTF-8")); 25 string result = reader.ReadToEnd(); 26 27 //处理结果 28 Dictionary<string, string> dicResult = ReceivePostXmlData(result); 29 if (dicResult["return_code"] != null && dicResult["return_code"].Equals("SUCCESS")) 30 { 31 if (dicResult.Keys.Contains("code_url")) 32 { 33 return dicResult["code_url"].ToString(); 34 } 35 else { 36 return ""; 37 } 38 } 39 return ""; 40 }
1 SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>(); 2 sParaTemp.Add("appid", WXConfig.APPID); 3 sParaTemp.Add("mch_id", WXConfig.MCH_ID); 4 sParaTemp.Add("trade_type", "NATIVE"); 5 sParaTemp.Add("body", cp[0].OrderItem); 6 sParaTemp.Add("nonce_str", WXConfig.WX_Nonce_Str()); 7 sParaTemp.Add("notify_url", "http://my.test.sci99.com/wx_notify_url.aspx"); 8 sParaTemp.Add("out_trade_no", cp[0].PayID.ToString()); 9 sParaTemp.Add("spbill_create_ip", Page.Request.UserHostAddress); 10 sParaTemp.Add("total_fee", (cp[0].CountMoney*10*10).ToString()); //单位分 11 sParaTemp.Add("product_id", cp[0].PayID.ToString()); 12 13 string CODE_URL = WXConfig.Get_Code_URL(sParaTemp);
标签:
原文地址:http://www.cnblogs.com/chenliang-zibo/p/4337577.html