C # Micro Payment refund Query Interface V3.3.6

Source: Internet
Author: User
Tags cdata md5 encryption

#region Micro-Payment Refund Enquiry

String Nonce = Createrandomcode (15). ToLower (); Generate 15 Random characters
String sign1 = "appid=" + PayHandle.AppID.ToString () +//AppID of the public number
"&mch_id=" + PayHandle.MechID.ToString () +//merchant number
"&nonce_str=" + nonce +//random string
"&out_trade_no=" + row["Wxo_ocode"]. ToString (); Merchant Order Number
String sign2 = Sign1 + "&key=" + PayHandle.PayKey.ToString (); Merchant key
String sign = T9. UTIL.ENCRYPTUTIL.MD5 (SIGN2, 32). ToUpper (); MD5 encryption
Call the refund query interface
String URL = "Https://api.mch.weixin.qq.com/pay/refundquery";
String requstcontext = "<xml>" +
"<appid><! [cdata["+ PayHandle.AppID.ToString () +"]]></appid> "+
"<mch_id><! [cdata["+ PayHandle.MechID.ToString () +"]]></mch_id> "+
"<nonce_str><! [cdata["+ Nonce +"]]></nonce_str> "+
"<sign><! [cdata["+ sign +"]]></sign> "+
"<out_trade_no><! [cdata["+ row[" Wxo_ocode "]. ToString () + "]]></out_trade_no>" +
"</xml>";
String refundquery = Sendinfo (URL, Requstcontext); Call the method that sends the request to the server

XmlDocument doc = new XmlDocument ();
Doc. LOADXML (Refundquery);
XmlElement rootelement = doc. DocumentElement;
String Code = Rootelement.selectsinglenode ("Return_code"). InnerText; Protocol level judgment
if (Code = = "SUCCESS")//Protocol level verification
{
String result_code = Rootelement.selectsinglenode ("Result_code"). InnerText;
if (Result_code = = "SUCCESS")//Business Level Authentication
{
int count = Convert.ToInt32 (Rootelement.selectsinglenode ("Refund_count"). InnerText);//Refund Record Count
if (Count >= 2)
{
Data processing
}
Else
{
Data processing
}
}
Else
{
This. Clientscript.registerstartupscript (GetType (), "", "&LT;SCRIPT&GT;SHOWFW (' An unknown error, please contact the administrator! ');</script> ");
}
}
Else
{
This. Clientscript.registerstartupscript (GetType (), "", "&LT;SCRIPT&GT;SHOWFW (' An unknown error, please contact the administrator! ');</script> ");
}
#endregion
#region Generate random strings
<summary>
Generate Random string
</summary>
<param name= "Codecount" ></param>
<param name= "Allchar" ></param>
<returns></returns>
public static string Createrandomcode (int codecount)
{
The character that appears in the captcha avoids some easily confusing characters.
String Allchar = "3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,j,k,m,n,p,q,r,s,t,u,w,x,y";
string[] Allchararray = Allchar.split (', ');
String randomcode = "";
int temp =-1;
BOOL Brecreate = (Codecount < 6 && allchararray.length > 15);

Random rand = new Random ();
for (int i = 0; i < Codecount; i++)
{
if (temp! =-1)
{
Rand = new Random (i * temp * ((int) DateTime.Now.Ticks));
}
int t = rand. Next (allchararray.length);
if (temp = = T && brecreate)
{
Return Createrandomcode (Codecount);
}
temp = t;
Randomcode + = allchararray[t];
}
return randomcode;
}
#endregion
#region send information to the server
<summary>
Sending information to the server
</summary>
<param name= "PostURL" ></param>
<param name= "PostData" ></param>
<returns></returns>
public string Sendinfo (string PostURL, String postdata)
{
Stream outstream = null;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding Encoding = Encoding.UTF8;
byte[] data = encoding. GetBytes (PostData);
Prepare request ...
Try
{
Setting parameters
Request = WebRequest.Create (PostURL) as HttpWebRequest;
Cookiecontainer Cookiecontainer = new Cookiecontainer ();
Request. Cookiecontainer = Cookiecontainer;
Request. AllowAutoRedirect = true;
Request. Method = "POST";
Request. ContentType = "application/x-www-form-urlencoded";
Request. ContentLength = data. Length;
OutStream = Request. GetRequestStream ();
OutStream. Write (data, 0, data. Length);
OutStream. Close ();
Send request and get corresponding response data
Response = Request. GetResponse () as HttpWebResponse;
Until request. The GetResponse () program only starts sending a POST request to the destination Web page
Instream = Response. GetResponseStream ();
sr = new StreamReader (instream, encoding);
Return result Web page (HTML) code
String content = Sr. ReadToEnd ();
string err = string. Empty;
return content;
}
catch (Exception ex)
{
T9. Util.LogUtil.WriteLog (ex. Message + "\ r \ n" + ex. StackTrace, "WebLog");
return string. Empty;
}
}
#endregion

C # Micro Payment refund Query Interface V3.3.6

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.