SenparcWeixinSetting.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*----------------------------------------------------------------
  2. Copyright (C) 2019 Senparc
  3. 文件名:SenparcWeixinSetting.cs
  4. 文件功能描述:Senparc.Weixin JSON 配置
  5. 创建标识:Senparc - 20170302
  6. 修改标识:Senparc - 20180622
  7. 修改描述:v5.0.3.1 SenparcWeixinSetting 添加 Cache_Memcached_Configuration 属性
  8. 修改标识:Senparc - 20180622
  9. 修改描述:v5.0.6.2 WeixinRegister.UseSenparcWeixin() 方法去除 isDebug 参数,提供扩展缓存自动扫描添加功能
  10. 修改标识:Senparc - 20180622
  11. 修改描述:v5.0.8 SenparcWeixinSetting 构造函数提供 isDebug 参数
  12. 修改标识:Senparc - 20180802
  13. 修改描述:v15.2.0 SenparcWeixinSetting 添加 TenPayV3_WxOpenTenpayNotify 属性,用于设置小程序支付回调地址
  14. ----------------------------------------------------------------*/
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Text;
  18. namespace Senparc.Weixin.Entities
  19. {
  20. /// <summary>
  21. /// <para>Senparc.Weixin JSON 配置</para>
  22. /// </summary>
  23. public class SenparcWeixinSetting : SenparcWeixinSettingItem//继承 SenparcWeixinSettingItem 是为了可以得到一组默认的参数,方便访问
  24. {
  25. #region 微信全局
  26. /// <summary>
  27. /// 是否处于 Debug 状态(仅限微信范围)
  28. /// </summary>
  29. public bool IsDebug { get; set; }
  30. #endregion
  31. /// <summary>
  32. /// 系统中所有微信设置的参数,默认已经添加一个 Key 为“Default”的对象
  33. /// </summary>
  34. public SenparcWeixinSettingItemCollection Items { get; set; }
  35. /// <summary>
  36. /// SenparcWeixinSetting 构造函数
  37. /// </summary>
  38. public SenparcWeixinSetting() : this(false)
  39. { }
  40. /// <summary>
  41. /// SenparcWeixinSetting 构造函数
  42. /// </summary>
  43. /// <param name="isDebug">是否开启 Debug 模式</param>
  44. public SenparcWeixinSetting(bool isDebug)
  45. {
  46. IsDebug = isDebug;
  47. Items = new SenparcWeixinSettingItemCollection();
  48. Items["Default"] = this;//储存第一个默认参数
  49. }
  50. #if !NETSTANDARD2_0 && !NETCOREAPP2_0 && !NETCOREAPP2_1 || NETCOREAPP2_2 && !NETSTANDARD2_0
  51. /// <summary>
  52. /// 从 Web.Config 文件自动生成 SenparcWeixinSetting
  53. /// </summary>
  54. /// <param name="isDebug">设置微信的 Debug 状态 </param>
  55. /// <returns></returns>
  56. public static SenparcWeixinSetting BuildFromWebConfig(bool isDebug)
  57. {
  58. var senparcWeixinSetting = new SenparcWeixinSetting(isDebug);
  59. //微信公众号URL对接信息
  60. senparcWeixinSetting.Token = System.Configuration.ConfigurationManager.AppSettings["WeixinToken"];
  61. senparcWeixinSetting.EncodingAESKey = System.Configuration.ConfigurationManager.AppSettings["WeixinEncodingAESKey"];
  62. //高级接口信息
  63. senparcWeixinSetting.WeixinAppId = System.Configuration.ConfigurationManager.AppSettings["WeixinAppId"];
  64. senparcWeixinSetting.WeixinAppSecret = System.Configuration.ConfigurationManager.AppSettings["WeixinAppSecret"];
  65. //SDK提供的代理功能设置
  66. senparcWeixinSetting.AgentUrl = System.Configuration.ConfigurationManager.AppSettings["WeixinAgentUrl"];
  67. senparcWeixinSetting.AgentToken = System.Configuration.ConfigurationManager.AppSettings["WeixinAgentToken"];
  68. senparcWeixinSetting.SenparcWechatAgentKey = System.Configuration.ConfigurationManager.AppSettings["SenparcWechatAgentKey"];
  69. //微信支付相关参数
  70. //微信支付V2
  71. //senparcWeixinSetting.WeixinPay_Tenpay = System.Configuration.ConfigurationManager.AppSettings["WeixinPay_Tenpay"];
  72. senparcWeixinSetting.WeixinPay_PartnerId = System.Configuration.ConfigurationManager.AppSettings["WeixinPay_PartnerId"];
  73. senparcWeixinSetting.WeixinPay_Key = System.Configuration.ConfigurationManager.AppSettings["WeixinPay_Key"];
  74. senparcWeixinSetting.WeixinPay_AppId = System.Configuration.ConfigurationManager.AppSettings["WeixinPay_AppId"];
  75. senparcWeixinSetting.WeixinPay_AppKey = System.Configuration.ConfigurationManager.AppSettings["WeixinPay_AppKey"];
  76. senparcWeixinSetting.WeixinPay_TenpayNotify = System.Configuration.ConfigurationManager.AppSettings["WeixinPay_TenpayNotify"];
  77. //微信支付V3
  78. senparcWeixinSetting.TenPayV3_MchId = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_MchId"];
  79. senparcWeixinSetting.TenPayV3_SubMchId = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_SubMchId"];
  80. senparcWeixinSetting.TenPayV3_Key = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_Key"];
  81. senparcWeixinSetting.TenPayV3_AppId = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_AppId"];
  82. senparcWeixinSetting.TenPayV3_AppSecret = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_AppSecret"];
  83. senparcWeixinSetting.TenPayV3_TenpayNotify = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_TenpayNotify"];
  84. senparcWeixinSetting.TenPayV3_WxOpenTenpayNotify = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_WxOpenTenpayNotify"];
  85. if (string.IsNullOrEmpty(senparcWeixinSetting.TenPayV3_WxOpenTenpayNotify))
  86. {
  87. senparcWeixinSetting.TenPayV3_WxOpenTenpayNotify = senparcWeixinSetting.TenPayV3_TenpayNotify + "WxOpen";//设置默认值
  88. }
  89. //开放平台
  90. senparcWeixinSetting.Component_Appid = System.Configuration.ConfigurationManager.AppSettings["Component_Appid"];
  91. senparcWeixinSetting.Component_Secret = System.Configuration.ConfigurationManager.AppSettings["Component_Secret"];
  92. senparcWeixinSetting.Component_Token = System.Configuration.ConfigurationManager.AppSettings["Component_Token"];
  93. senparcWeixinSetting.Component_EncodingAESKey = System.Configuration.ConfigurationManager.AppSettings["Component_EncodingAESKey"];
  94. //微信企业号
  95. senparcWeixinSetting.WeixinCorpId = System.Configuration.ConfigurationManager.AppSettings["WeixinCorpId"];
  96. senparcWeixinSetting.WeixinCorpSecret = System.Configuration.ConfigurationManager.AppSettings["WeixinCorpSecret"];
  97. //小程序
  98. //小程序消息URL对接信息
  99. senparcWeixinSetting.WxOpenToken = System.Configuration.ConfigurationManager.AppSettings["WxOpenToken"];
  100. senparcWeixinSetting.WxOpenEncodingAESKey = System.Configuration.ConfigurationManager.AppSettings["WxOpenEncodingAESKey"];
  101. //小程序秘钥信息
  102. senparcWeixinSetting.WxOpenAppId = System.Configuration.ConfigurationManager.AppSettings["WxOpenAppId"];
  103. senparcWeixinSetting.WxOpenAppSecret = System.Configuration.ConfigurationManager.AppSettings["WxOpenAppSecret"];
  104. ////Cache.Redis连接配置
  105. //senparcWeixinSetting.Cache_Redis_Configuration = System.Configuration.ConfigurationManager.AppSettings["Cache_Redis_Configuration"];
  106. ////Cache.Redis连接配置
  107. //senparcWeixinSetting.Cache_Memcached_Configuration = System.Configuration.ConfigurationManager.AppSettings["Cache_Memcached_Configuration"];
  108. return senparcWeixinSetting;
  109. }
  110. #endif
  111. }
  112. }