AutoReplyApi.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. 文件名:AutoReplyApi.cs
  17. 文件功能描述:获取自动回复规则接口
  18. 创建标识:Senparc - 20150907
  19. 修改标识:Senparc - 20160718
  20. 修改描述:将其接口增加了异步方法
  21. 修改标识:Senparc - 20170707
  22. 修改描述:v14.5.1 完善异步方法async/await
  23. ----------------------------------------------------------------*/
  24. /*
  25. Api地址:http://mp.weixin.qq.com/wiki/7/7b5789bb1262fb866d01b4b40b0efecb.html
  26. */
  27. using System.Threading.Tasks;
  28. using Senparc.NeuChar;
  29. using Senparc.Weixin.CommonAPIs;
  30. using Senparc.Weixin.MP.AdvancedAPIs.AutoReply;
  31. using Senparc.Weixin.MP.CommonAPIs;
  32. namespace Senparc.Weixin.MP.AdvancedAPIs
  33. {
  34. /// <summary>
  35. /// 获取自动回复规则
  36. /// </summary>
  37. public static class AutoReplyApi
  38. {
  39. #region 同步方法
  40. /// <summary>
  41. /// 获取自动回复规则
  42. /// </summary>
  43. /// <param name="accessTokenOrAppId">调用接口凭证</param>
  44. /// <returns></returns>
  45. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "AutoReplyApi.GetCurrentAutoreplyInfo", true)]
  46. public static GetCurrentAutoreplyInfoResult GetCurrentAutoreplyInfo(string accessTokenOrAppId)
  47. {
  48. return ApiHandlerWapper.TryCommonApi(accessToken =>
  49. {
  50. string urlFormat = Config.ApiMpHost + "/cgi-bin/get_current_autoreply_info?access_token={0}";
  51. return CommonJsonSend.Send<GetCurrentAutoreplyInfoResult>(accessToken, urlFormat, null, CommonJsonSendType.GET);
  52. }, accessTokenOrAppId);
  53. }
  54. #endregion
  55. #if !NET35 && !NET40
  56. #region 异步方法
  57. /// <summary>
  58. /// 【异步方法】获取自动回复规则
  59. /// </summary>
  60. /// <param name="accessTokenOrAppId">调用接口凭证</param>
  61. /// <returns></returns>
  62. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "AutoReplyApi.GetCurrentAutoreplyInfoAsync", true)]
  63. public static async Task<GetCurrentAutoreplyInfoResult> GetCurrentAutoreplyInfoAsync(string accessTokenOrAppId)
  64. {
  65. return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
  66. {
  67. string urlFormat = Config.ApiMpHost + "/cgi-bin/get_current_autoreply_info?access_token={0}";
  68. return await CommonJsonSend.SendAsync<GetCurrentAutoreplyInfoResult>(accessToken, urlFormat, null, CommonJsonSendType.GET);
  69. }, accessTokenOrAppId);
  70. }
  71. #endregion
  72. #endif
  73. }
  74. }