asp.net 在CS文件中如何POST表单提交,StringBuilder asp.net 在CS文件中如何POST表单提交,StringBuilder

asp.net 在CS文件中如何POST表单提交,StringBuilder

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();
        }
    }
}


评论 1

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论
田螺
田螺 2021-03-28 10:11 回复
[code]签到成功!签到时间:2021/3/28 上午10:11:16,每日签到,生活更精彩![/code]
 Google Chrome 86.0.4240.198