using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Security.Cryptography; using System.Text; using System.Collections; using System.Collections.Specialized; using System.Data; using System.Data.SqlClient; using MySql.Data.MySqlClient; using System.Configuration; using System.Data.Common; using System.Text.RegularExpressions; namespace GamePay { public partial class _Default : System.Web.UI.Page { private static string AllpayUrl = "https://www.2asp.cn/Cashier/AioCheckOut"; //正式 protected void Page_Load(object sender, EventArgs e) { string constr = "User Id=root;Host=127.0.0.1;Database=mall;password=66520"; //数据库连接 MySqlConnection mycn = new MySqlConnection(constr); mycn.Open(); MySqlCommand mycm = new MySqlCommand("select a.Id,a.ShopName,a.Userid,a.RegionFullName, a.OrderStatus,a.ProductTotalAmount,a.OrderDate,a.OrderType,b.* from himall_orders as a, himall_orderitems as b where b.orderid=a.id and a.id=" + Request.QueryString["orderid"].ToString(), mycn); MySqlDataReader msdr = mycm.ExecuteReader(); if (msdr.Read()) { if (msdr.HasRows) { string num=msdr.FieldCount.ToString(); string money = msdr.GetInt32(5).ToString(); SortedDictionary<string, string> testStr = new SortedDictionary<string, string>(); testStr.Add("MerchantTradeNo", msdr.GetString(0)+"DH" + new Random().Next(0, 999).ToString()); testStr.Add("MerchantTradeDate", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); testStr.Add("ReturnURL", "{#ZC_BLOG_HOST#}receive.aspx"); testStr.Add("RelateNumber", msdr.GetString(0) + "DH" + new Random().Next(0, 999).ToString()); testStr.Add("CustomerName", HttpUtility.UrlEncode(msdr.GetString(1))); string str = string.Empty; string str_pre = string.Empty; foreach (var test in testStr) { str += string.Format("&{0}={1}", test.Key, test.Value); } str_pre += "HashKey=rVFOgTEmWCdvvq6b" + str + "&HashIV=Zy48yy98M9kmOwdB"; string urlEncodeStrPost = HttpUtility.UrlEncode(str_pre); string ToLower = urlEncodeStrPost.ToLower(); MD5 md5Hasher = MD5.Create(); byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(ToLower)); StringBuilder sBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) { sBuilder.Append(data[i].ToString("X2")); //MD5码 大小写 } string sCheckMacValue = sBuilder.ToString(); testStr.Add("CheckMacValue", sCheckMacValue); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<html><body>").AppendLine(); sb.Append("<form name='allpayTradeTest' id='allpayTradeTest' action='" + AllpayUrl + "' method='POST'>").AppendLine(); foreach (var aa in testStr) { sb.Append("<input type='hidden' name='" + aa.Key + "' value='" + aa.Value + "'>").AppendLine(); } sb.Append("</form>").AppendLine(); sb.Append("<script> var theForm = document.forms['allpayTradeTest']; if (!theForm) { theForm = document.allpayTradeTest; } theForm.submit(); </script>").AppendLine(); sb.Append("<html><body>").AppendLine(); Response.Write(sb.ToString()); Response.End(); } } msdr.Close(); mycn.Close(); } } }