BankCardCheckForThree.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. String bodys = "";
  29. String url = host + path;
  30. HttpWebRequest httpRequest = null;
  31. HttpWebResponse httpResponse = null;
  32. if (0 < querys.Length)
  33. {
  34. url = url + "?" + querys;
  35. }
  36. if (host.Contains("https://"))
  37. {
  38. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  39. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  40. }
  41. else
  42. {
  43. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  44. }
  45. httpRequest.Method = method;
  46. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  47. if (0 < bodys.Length)
  48. {
  49. byte[] data = Encoding.UTF8.GetBytes(bodys);
  50. using (Stream stream = httpRequest.GetRequestStream())
  51. {
  52. stream.Write(data, 0, data.Length);
  53. }
  54. }
  55. try
  56. {
  57. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  58. }
  59. catch (WebException ex)
  60. {
  61. httpResponse = (HttpWebResponse)ex.Response;
  62. }
  63. Stream st = httpResponse.GetResponseStream();
  64. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  65. string result = reader.ReadToEnd();
  66. return result;
  67. }
  68. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  69. {
  70. return true;
  71. }
  72. }
  73. }