AliPayConfig.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Web;
  7. namespace Central.Control.WebApi.Config
  8. {
  9. /// <summary>
  10. ///
  11. /// </summary>
  12. public class AliPayConfig
  13. {
  14. /// <summary>
  15. /// 支付宝公钥
  16. /// </summary>
  17. public static string alipay_public_key = ConfigurationManager.AppSettings["alipay_public_key"].ToString();
  18. /// <summary>
  19. /// 开发者私钥
  20. /// </summary>
  21. public static string merchant_private_key = ConfigurationManager.AppSettings["alipay_merchant_private_key"].ToString();
  22. /// <summary>
  23. /// 开发者公钥
  24. /// </summary>
  25. public static string merchant_public_key = ConfigurationManager.AppSettings["alipay_merchant_public_key"].ToString();
  26. /// <summary>
  27. /// 应用ID
  28. /// </summary>
  29. public static string appId = ConfigurationManager.AppSettings["alipay_appId"].ToString();
  30. /// <summary>
  31. /// 合作伙伴ID:partnerID
  32. /// </summary>
  33. public static string pid = ConfigurationManager.AppSettings["alipay_partnerId"].ToString();
  34. /// <summary>
  35. /// 支付宝网关
  36. /// </summary>
  37. public static string serverUrl = ConfigurationManager.AppSettings["alipay_serverUrl"].ToString();
  38. public static string mapiUrl = "https://mapi.alipay.com/gateway.do";
  39. public static string monitorUrl = "http://mcloudmonitor.com/gateway.do";
  40. //编码,无需修改
  41. public static string charset = "utf-8";
  42. //签名类型,支持RSA2(推荐!)、RSA
  43. //public static string sign_type = "RSA2";
  44. public static string sign_type = "RSA2";
  45. //版本号,无需修改
  46. public static string version = "1.0";
  47. /// <summary>
  48. /// 公钥文件类型转换成纯文本类型
  49. /// </summary>
  50. /// <returns>过滤后的字符串类型公钥</returns>
  51. public static string getMerchantPublicKeyStr()
  52. {
  53. StreamReader sr = new StreamReader(merchant_public_key);
  54. string pubkey = sr.ReadToEnd();
  55. sr.Close();
  56. if (pubkey != null)
  57. {
  58. pubkey = pubkey.Replace("-----BEGIN PUBLIC KEY-----", "");
  59. pubkey = pubkey.Replace("-----END PUBLIC KEY-----", "");
  60. pubkey = pubkey.Replace("\r", "");
  61. pubkey = pubkey.Replace("\n", "");
  62. }
  63. return pubkey;
  64. }
  65. /// <summary>
  66. /// 私钥文件类型转换成纯文本类型
  67. /// </summary>
  68. /// <returns>过滤后的字符串类型私钥</returns>
  69. public static string getMerchantPriveteKeyStr()
  70. {
  71. StreamReader sr = new StreamReader(merchant_private_key);
  72. string pubkey = sr.ReadToEnd();
  73. sr.Close();
  74. if (pubkey != null)
  75. {
  76. pubkey = pubkey.Replace("-----BEGIN PUBLIC KEY-----", "");
  77. pubkey = pubkey.Replace("-----END PUBLIC KEY-----", "");
  78. pubkey = pubkey.Replace("\r", "");
  79. pubkey = pubkey.Replace("\n", "");
  80. }
  81. return pubkey;
  82. }
  83. }
  84. }