ApiHandlerWapperFactory.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #region Apache License Version 2.0
  2. /*----------------------------------------------------------------
  3. Copyright 2019 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
  4. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  5. except in compliance with the License. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software distributed under the
  8. License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  9. either express or implied. See the License for the specific language governing permissions
  10. and limitations under the License.
  11. Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
  12. ----------------------------------------------------------------*/
  13. #endregion Apache License Version 2.0
  14. /*----------------------------------------------------------------
  15. Copyright (C) 2019 Senparc
  16. 文件名:ApiHandlerWapperFactory.cs
  17. 文件功能描述:针对AccessToken无效或过期的自动处理方法的工厂
  18. 创建标识:Senparc - 20170327
  19. ----------------------------------------------------------------*/
  20. using Senparc.Weixin.Entities;
  21. using Senparc.Weixin.Utilities.WeixinUtility;
  22. using System;
  23. using System.Collections.Generic;
  24. using System.Linq;
  25. using System.Text;
  26. namespace Senparc.Weixin.CommonAPIs
  27. {
  28. ///// <summary>
  29. ///// ApiHandlerWapperFactory的当前平台
  30. ///// </summary>
  31. //public enum ApiHandlerWapperPlatform
  32. //{
  33. // /// <summary>
  34. // /// 公众号
  35. // /// </summary>
  36. // MP,
  37. // /// <summary>
  38. // /// 开放平台
  39. // /// </summary>
  40. // OPEN
  41. //}
  42. ///// <summary>
  43. ///// 针对AccessToken无效或过期的自动处理类(基类)
  44. ///// </summary>
  45. //public static class ApiHandlerWapperFactory
  46. //{
  47. // /// <summary>
  48. // /// 同步方法集合
  49. // /// </summary>
  50. // public static Dictionary<ApiHandlerWapperPlatform, Func<WxJsonResult>> Collection = new Dictionary<ApiHandlerWapperPlatform, Func<WxJsonResult>>();
  51. // /// <summary>
  52. // /// 异步方法集合
  53. // /// </summary>
  54. // public static Dictionary<ApiHandlerWapperPlatform, Func<Task<WxJsonResult>>> CollectionAsync = new Dictionary<ApiHandlerWapperPlatform, Func<Task<WxJsonResult>>>();
  55. // ///// <summary>
  56. // ///// 平台凭证队列
  57. // ///// </summary>
  58. // //public static Dictionary<string, ApiHandlerWapperPlatform> PlatformQueue = new Dictionary<string, ApiHandlerWapperPlatform>();
  59. // /// <summary>
  60. // /// ApiHandlerWapperFactory锁
  61. // /// </summary>
  62. // public static object ApiHandlerWapperFactoryLock = new object();
  63. // private static ApiHandlerWapperPlatform _currentPlatform = ApiHandlerWapperPlatform.MP;
  64. // /// <summary>
  65. // /// 当前平台,值:
  66. // /// </summary>
  67. // public static ApiHandlerWapperPlatform CurrentPlatform
  68. // {
  69. // get
  70. // {
  71. // return _currentPlatform;
  72. // }
  73. // set
  74. // {
  75. // _currentPlatform = value;
  76. // }
  77. // }
  78. // #region 同步方法
  79. // public static Func<T> GetWapperFunc<T>(ApiHandlerWapperPlatform platform) where T : WxJsonResult
  80. // {
  81. // if (!Collection.ContainsKey(platform))
  82. // {
  83. // return null;//也可以抛出异常
  84. // }
  85. // var funWapper = Collection[platform];
  86. // return funWapper as Func<T>;
  87. // }
  88. // /// <summary>
  89. // /// 提供给ApiHandlerWapper使用的全局统一的基础调用方法,兼容公众号、开放平台在不同情况下对接口的统一调用
  90. // /// </summary>
  91. // /// <typeparam name="T"></typeparam>
  92. // /// <param name="funWapper"></param>
  93. // /// <returns></returns>
  94. // public static WxJsonResult RunWapper<T>(ApiHandlerWapperPlatform platform) where T : WxJsonResult
  95. // {
  96. // if (!Collection.ContainsKey(platform))
  97. // {
  98. // return null;//也可以抛出异常
  99. // }
  100. // var funWapper = Collection[platform];
  101. // return funWapper();
  102. // }
  103. // #endregion
  104. // #region 异步方法
  105. // /// <summary>
  106. // /// 【异步方法】提供给ApiHandlerWapper使用的全局统一的基础调用方法,兼容公众号、开放平台在不同情况下对接口的统一调用
  107. // /// </summary>
  108. // /// <typeparam name="T"></typeparam>
  109. // /// <param name="funWapper"></param>
  110. // /// <returns></returns>
  111. // public static async Task<T> RunWapperAsync<T>(Func<Task<T>> funWapper) where T : WxJsonResult
  112. // {
  113. // if (funWapper == null)
  114. // {
  115. // return null;
  116. // }
  117. // return await funWapper();
  118. // }
  119. // #endregion
  120. //}
  121. }