Skip to content

Instantly share code, notes, and snippets.

@payjscn
Last active July 12, 2024 01:12
Show Gist options
  • Save payjscn/fbdda8ae6b29a37d589623af07f3743a to your computer and use it in GitHub Desktop.
Save payjscn/fbdda8ae6b29a37d589623af07f3743a to your computer and use it in GitHub Desktop.
PAYJS 扫码支付接口 C# DEMO
//using System.IO;
//using System.Text;
//using System.Net;
//using System.Net.Security;
//using System.Security.Cryptography.X509Certificates;
private const String host = "https://payjs.cn";
private const String path = "/api/native";
private const String method = "POST";
static void Main(string[] args)
{
String querys = "";
String bodys = "mchid=****&total_fee=12&out_trade_no=2134099892932&sign=******************";
String url = host + path;
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
if (0 < querys.Length)
{
url = url + "?" + querys;
}
if (host.Contains("https://"))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = method;
if (0 < bodys.Length)
{
byte[] data = Encoding.UTF8.GetBytes(bodys);
using (Stream stream = httpRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
}
catch (WebException ex)
{
httpResponse = (HttpWebResponse)ex.Response;
}
Console.WriteLine(httpResponse.StatusCode);
Console.WriteLine(httpResponse.Method);
Console.WriteLine(httpResponse.Headers);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("\n");
}
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment