OpenTicketHelper.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using Senparc.Weixin.Exceptions;
  7. using Senparc.Weixin.MP.Sample.CommonService.Utilities;
  8. namespace Senparc.Weixin.MP.Sample.CommonService.OpenTicket
  9. {
  10. /// <summary>
  11. /// OpenTicket即ComponentVerifyTicket
  12. /// </summary>
  13. public class OpenTicketHelper
  14. {
  15. public static string GetOpenTicket(string componentAppId)
  16. {
  17. //实际开发过程不一定要用文件记录,也可以用数据库。
  18. var openTicketPath = Server.GetMapPath("~/App_Data/OpenTicket");
  19. string openTicket = null;
  20. var filePath = Path.Combine(openTicketPath, string.Format("{0}.txt", componentAppId));
  21. if (File.Exists(filePath))
  22. {
  23. using (TextReader tr = new StreamReader(filePath))
  24. {
  25. openTicket = tr.ReadToEnd();
  26. }
  27. }
  28. else
  29. {
  30. throw new WeixinException("OpenTicket不存在!");
  31. }
  32. //其他逻辑
  33. return openTicket;
  34. }
  35. }
  36. }