BankCardCheckForThree.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Security;
  7. using System.Security.Cryptography.X509Certificates;
  8. using System.Text;
  9. using Library;
  10. // using MongoDB.Bson;
  11. // using MongoDB.Driver;
  12. // using MongoDB.Driver.Linq;
  13. namespace MySystem
  14. {
  15. public class BankCardCheckForThree
  16. {
  17. public readonly static BankCardCheckForThree Instance = new BankCardCheckForThree();
  18. private BankCardCheckForThree()
  19. {
  20. }
  21. private const String host = "https://bankcard3c.shumaidata.com";
  22. private const String path = "/bankcard3c";
  23. private const String method = "GET";
  24. private const String appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  25. public string Do(string bankcard, string idcard, string name)
  26. {
  27. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
  28. function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
  29. function.WriteLog(querys, "验证三要素日志");
  30. String bodys = "";
  31. String url = host + path;
  32. HttpWebRequest httpRequest = null;
  33. HttpWebResponse httpResponse = null;
  34. if (0 < querys.Length)
  35. {
  36. url = url + "?" + querys;
  37. }
  38. if (host.Contains("https://"))
  39. {
  40. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  41. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  42. }
  43. else
  44. {
  45. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  46. }
  47. httpRequest.Method = method;
  48. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  49. if (0 < bodys.Length)
  50. {
  51. byte[] data = Encoding.UTF8.GetBytes(bodys);
  52. using (Stream stream = httpRequest.GetRequestStream())
  53. {
  54. stream.Write(data, 0, data.Length);
  55. }
  56. }
  57. try
  58. {
  59. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  60. }
  61. catch (WebException ex)
  62. {
  63. httpResponse = (HttpWebResponse)ex.Response;
  64. }
  65. Stream st = httpResponse.GetResponseStream();
  66. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  67. string result = reader.ReadToEnd();
  68. function.WriteLog(result, "验证三要素日志");
  69. function.WriteLog("\n\n", "验证三要素日志");
  70. return result;
  71. }
  72. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  73. {
  74. return true;
  75. }
  76. }
  77. }