<%@ WebHandler Language="C#" Class="jiesuan" %>
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using .X509Certificates;
using ;
using ;
public class jiesuan : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
= "text/plain";
string orderid = ["order_id"];
string appid = ["appid"];
string secret = ["secret"];
string key = ["key"];
string mch_id = ["mch_id"];
string ip = ["ip"];
string PayResulturl = ["PayResulturl"];
string aa = "私密自助棋牌室-退款";
string strcode = aa;
byte[] buffer = Encoding.(strcode);
string body = Encoding.(buffer, 0, );
DateTime timestart;
int totalhour;
float totalfee;
float pay_price;
float refund_fee;
string out_refund_no;
int roomid;
string openid;
string output = "";
string signapp;
DataSet orderhistory;
if ((["order_id"] != null) && (["order_id"] != ""))
{
.order_history oh = new .order_history();
orderhistory = (" order_margin:0px; padding:0px; border:none; background-color:inherit"> + orderid + "");
pay_price = ([0].Rows[0]["pay_price"]);
roomid = Convert.ToInt32([0].Rows[0]["room_id"]);
openid = [0].Rows[0]["openid"].ToString();
Random = new ();
timestart = ([0].Rows[0]["order_timestart"]);
TimeSpan ts = - timestart;
totalhour = Convert.ToInt32();
totalfee = totalhour * ([0].Rows[0]["price"]);
out_refund_no = roomid + ("yyyyMMddHHmmssfff") + (999).ToString();
refund_fee = totalfee - pay_price;
var dic = new Dictionary<string, string>
{
{"appid", appid},
{"mch_id", mch_id},
{"nonce_str", GetRandomString(20)},
{"op_user_id",mch_id},
{"out_refund_no",out_refund_no},
{"out_trade_no",[0].Rows[0]["out_trade_no"].ToString()},
{"refund_fee","1"},
{"total_fee",[0].Rows[0]["pay_price"].ToString()},
};
("sign", GetSignString(dic));
var sb = new StringBuilder();
("<xml>");
foreach (var d in dic)
{
("<" + + ">" + + "</" + + ">");
}
("</xml>");
var xml = new XmlDocument();
CookieCollection coo = new CookieCollection();
Encoding en = ("UTF-8");
HttpWebResponse response = CreatePostHttpResponse("/secapi/pay/refund", (), en);
Stream stream = ();
StreamReader sr = new StreamReader(stream);
string html = ();
(html);
var root = ;
DataSet ds = new DataSet();
StringReader stram = new StringReader(html);
XmlTextReader reader = new XmlTextReader(stram);
(reader);
string return_code = [0].Rows[0]["return_code"].ToString();
string return_mesage = [0].Rows[0]["return_msg"].ToString();
if (return_code.ToUpper() == "SUCCESS")
{
string result_code = [0].Rows[0]["result_code"].ToString();
if (result_code.ToUpper() == "SUCCESS")
{
if ((["order_id"] != null) && (["order_id"] != ""))
{
model = new ();
.order_history oh1 = new .order_history();
b = new ();
.order_history bll = new .order_history();
model = (roomid);
oh1 = (Convert.ToInt32(orderid));
oh1.order_timeend = ;
oh1.out_refund_no = out_refund_no;
oh1.refund_fee = (refund_fee);
(oh1);
model.attribute1 = "0";
model.room_id =Convert.ToInt32(oh1.room_id);
(model);
var res = new Dictionary<string, string>
{
{"out_refund_no", out_refund_no},
{"return_mesage", return_mesage},
{"return_code", return_code},
{"refund_fee",refund_fee.ToString() },
{"order_timeend", oh1.order_timeend.ToString() },
{"order_id", oh1.order_id.ToString() }
};
signapp = (res);
(signapp);
}
}
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
public string GetMd5Hash(String input)
{
if (input == null)
{
return null;
}
MD5 md5Hash = ();
byte[] data = (Encoding.(input));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < ; i++)
{
(data[i].ToString());
}
return ();
}
public static string XmlSerialize<T>(T obj)
{
string xmlString = string.Empty;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
using (MemoryStream ms = new MemoryStream())
{
(ms, obj);
xmlString = Encoding.(());
}
return xmlString;
}
public static string GetRandomString(int CodeCount)
{
string allChar = "1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,i,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
string[] allCharArray = (',');
string RandomCode = "";
int temp = -1;
Random rand = new Random();
for (int i = 0; i < CodeCount; i++)
{
if (temp != -1)
{
rand = new Random(temp * i * ((int)));
}
int t = ( - 1);
while (temp == t)
{
t = ( - 1);
}
temp = t;
RandomCode += allCharArray[t];
}
return RandomCode;
}
public static string GetWebClientIp()
{
string userIP = "IP";
try
{
if ( == null
|| == null
|| == null)
return "";
string CustomerIP = "";
CustomerIP = ["Cdn-Src-Ip"];
if (!string.IsNullOrEmpty(CustomerIP))
{
return CustomerIP;
}
CustomerIP = ["HTTP_X_FORWARDED_FOR"];
if (!(CustomerIP))
return CustomerIP;
if (["HTTP_VIA"] != null)
{
CustomerIP = ["HTTP_X_FORWARDED_FOR"];
if (CustomerIP == null)
CustomerIP = ["REMOTE_ADDR"];
}
else
{
CustomerIP = ["REMOTE_ADDR"];
}
if (string.Compare(CustomerIP, "unknown", true) == 0)
return ;
return CustomerIP;
}
catch { }
return userIP;
}
private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
public static HttpWebResponse CreatePostHttpResponse(string url, string datas, Encoding charset)
{
string cert =("/apiclient_cert.p12");
string password = ["mch_id"];
X509Certificate2 cer = new X509Certificate2(cert, password, | );
HttpWebRequest request = null;
= new RemoteCertificateValidationCallback(CheckValidationResult);
request = (url) as HttpWebRequest;
= HttpVersion.Version10;
(cer);
= "POST";
= "application/x-www-form-urlencoded";
StringBuilder buffer = new StringBuilder();
(datas);
byte[] data = (());
using (Stream stream = ())
{
(data, 0, );
}
return () as HttpWebResponse;
}
public string GetSignString(Dictionary<string, string> dic)
{
string key = ["key"].ToString();
dic = (d => ).ToDictionary(d => , d => );
var sign = ("", (current, d) => current + ( + "=" + + "&"));
sign += "key=" + key;
.MD5 md5 = .();
sign = ((Encoding.(sign))).Replace("-", null);
return sign;
}
public static string GetTimeStamp()
{
TimeSpan ts = - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64().ToString();
}
}