AppUtility.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*----------------------------------------------------------------
  2. Copyright (C) 2019 Senparc
  3. 文件名:AppUtility.cs
  4. 文件功能描述:获取RequestMessage中ToUserName中的信息
  5. 创建标识:Senparc - 20150319
  6. ----------------------------------------------------------------*/
  7. using Senparc.NeuChar.Entities;
  8. using Senparc.Weixin.MP.Entities;
  9. namespace Senparc.Weixin.MP.AppStore.Utility
  10. {
  11. /// <summary>
  12. /// 微信请求中ToUserName包含的信息
  13. /// </summary>
  14. public class WeixinRequestInfo
  15. {
  16. /// <summary>
  17. /// 使用此应用的微信账号ID(在微微嗨平台上的唯一ID)
  18. /// </summary>
  19. public int WeixinId { get; set; }
  20. /// <summary>
  21. /// 被请求应用的唯一ID
  22. /// </summary>
  23. public int AppId { get; set; }
  24. }
  25. public static class AppUtility
  26. {
  27. /// <summary>
  28. /// 获取RequestMessage中ToUserName中的信息(这条信息由微微嗨平台向APP发出)
  29. /// </summary>
  30. /// <param name="toUserName">RequestMessage中的ToUserName属性</param>
  31. /// <returns></returns>
  32. public static WeixinRequestInfo GetWeixinRequestInfo(string toUserName)
  33. {
  34. var info = new WeixinRequestInfo();
  35. try
  36. {
  37. var data = toUserName.Split('_');
  38. info.WeixinId = int.Parse(data[1]);
  39. info.AppId = int.Parse(data[2]);
  40. }
  41. catch
  42. {
  43. }
  44. return info;
  45. }
  46. /// <summary>
  47. /// 获取RequestMessage中ToUserName中的信息(这条信息由微微嗨平台向APP发出)
  48. /// </summary>
  49. /// <param name="requestMessage"></param>
  50. /// <returns></returns>
  51. public static WeixinRequestInfo GetWeixinRequestInfo(this IRequestMessageBase requestMessage)
  52. {
  53. return GetWeixinRequestInfo(requestMessage.ToUserName);
  54. }
  55. }
  56. }