Authorize.aspx.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. namespace LYFZ.WeixinServers
  8. {
  9. public partial class Authorize : System.Web.UI.Page
  10. {
  11. protected void Page_Load(object sender, EventArgs e)
  12. {
  13. // 企业id;
  14. string strEntId = "";
  15. // 公众号或小程序appid;
  16. string strAppId = "";
  17. // app类型:公众号或小程序;
  18. string strAppType = "";
  19. // app的微信号;
  20. string strAppWxId = "";
  21. if (VerifyParam(out strEntId, out strAppId, out strAppType, out strAppWxId))
  22. {
  23. // 根据企业id获取企业信息;
  24. LoginModel.enterprise model = GlobalCache.GetEnterpriseModel(strEntId);
  25. if (model != null)
  26. {
  27. string authorizeParameter = LYFZ.WinAPI.SDKSecurity.Encode(strAppType + "&" + strAppId + "&" + strEntId);
  28. string url = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=" +
  29. LYFZ.WXLibrary.OpenPlatformConfig.OpenAppID + "&pre_auth_code=" +
  30. LYFZ.WXLibrary.OpenPlatformConfig.Pre_auth_code + "&redirect_uri=" +
  31. LYFZ.WXLibrary.OpenPlatformConfig.Redirect_uri +
  32. "?auth_parameters=" + authorizeParameter;
  33. this.divInfo.InnerHtml = "<h3>利亚方舟影楼管理系统微信公众平台授权登录</h3>"
  34. + " <span>利亚方舟影楼管理软件微信平台为用户提供第三方的公众平台管理、客户互动,模板消息推送等,满足您的需要。</span>"
  35. + " <h3>点击“微信公众号登录授权”即可完成公众号与平台的邦定</h3>"
  36. + " <a href=\"" + url + "\"><img style=\"border:hidden;\" src=\"WeiXinAPP/images/icon_button3_1.png\" alt=\"微信公众号登录授权\" /></a>"
  37. + " <h3>可授权权限集</h3>"
  38. + " <p>"
  39. + " <b> 消息管理权限:</b> 帮助公众号接收用户消息,进行人工客服回复或自动回复"
  40. + " <br /><b> 自定义菜单权限:</b>帮助公众号使用自定义菜单"
  41. + " <br /><b> 网页服务权限:</b>帮助公众号实现第三方网页服务和活动"
  42. + " <br /><b> 群发与通知权限:</b>帮助公众号进行群发和模板消息业务通知"
  43. + " <br /><b> 用户管理权限:</b>帮助公众号获取用户信息,进行用户管理"
  44. + " </p>";
  45. }
  46. else
  47. {
  48. this.divInfo.InnerHtml = "<h3>请求错误:不是有效的企业ID</h3>";
  49. }
  50. }
  51. else
  52. {
  53. this.divInfo.InnerHtml = "<h3>非法请求!</h3>";
  54. }
  55. #if 参考
  56. if (string.IsNullOrEmpty(strEntId) || string.IsNullOrEmpty(strAppId))
  57. {
  58. this.divInfo.InnerHtml = "<h3>非法请求!</h3>";
  59. }
  60. else
  61. {
  62. LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces cusModel = null;
  63. try
  64. {
  65. // LYFZ.WXLibrary.CommonHandleClass.WriteLog("JMGDomainName: " + JMGDomainName, JMGDomainName, Global.LogsDongleDomainList);
  66. cusModel = Global.GetCustomerModel(strEntId);
  67. if (cusModel != null && cusModel.ID > 0)
  68. {
  69. string authorizeParameter = LYFZ.WinAPI.SDKSecurity.Encode("" + strAppId + "&" + strEntId);
  70. string url = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=" + LYFZ.WXLibrary.OpenPlatformConfig.OpenAppID + "&pre_auth_code=" + LYFZ.WXLibrary.OpenPlatformConfig.Pre_auth_code + "&redirect_uri=" + LYFZ.WXLibrary.OpenPlatformConfig.Redirect_uri + "?authorizeParameter=" + authorizeParameter;
  71. this.divInfo.InnerHtml = "<h3>利亚方舟影楼管理系统微信公众平台授权登录</h3>"
  72. + " <span>利亚方舟影楼管理软件微信平台为用户提供第三方的公众平台管理、客户互动,模板消息推送等,满足您的需要。</span>"
  73. + " <h3>点击“微信公众号登录授权”即可完成公众号与平台的邦定</h3>"
  74. + " <a href=\"" + url + "\"><img style=\"border:hidden;\" src=\"WeiXinAPP/images/icon_button3_1.png\" alt=\"微信公众号登录授权\" /></a>"
  75. + " <h3>可授权权限集</h3>"
  76. + " <p>"
  77. + " <b> 消息管理权限:</b> 帮助公众号接收用户消息,进行人工客服回复或自动回复"
  78. + " <br /><b> 自定义菜单权限:</b>帮助公众号使用自定义菜单"
  79. + " <br /><b> 网页服务权限:</b>帮助公众号实现第三方网页服务和活动"
  80. + " <br /><b> 群发与通知权限:</b>帮助公众号进行群发和模板消息业务通知"
  81. + " <br /><b> 用户管理权限:</b>帮助公众号获取用户信息,进行用户管理"
  82. + " </p>";
  83. }
  84. else
  85. {
  86. // LYFZ.WXLibrary.CommonHandleClass.WriteLog("请求错误:不是有效的JMG域名", JMGDomainName, Global.LogsDongleDomainList);
  87. this.divInfo.InnerHtml = "<h3>请求错误:不是有效的JMG域名</h3>";
  88. }
  89. }
  90. catch (Exception ex)
  91. {
  92. // LYFZ.WXLibrary.CommonHandleClass.WriteLog("请求错误:" + ex.Message, JMGDomainName, Global.LogsDongleDomainList);
  93. this.divInfo.InnerHtml = "<h3>请求错误:" + ex.Message + "</h3>";
  94. }
  95. }
  96. #endif
  97. }
  98. /// <summary>
  99. /// 参数校验
  100. /// </summary>
  101. /// <param name="strEntId">企业id</param>
  102. /// <param name="strAppId">app对象id</param>
  103. /// <param name="strAppType">app对象类型</param>
  104. /// <param name="strAppWxId">app对象的微信号</param>
  105. /// <returns>若参数有效返回true,参数无效或空返回false</returns>
  106. public bool VerifyParam(out string strEntId, out string strAppId, out string strAppType, out string strAppWxId)
  107. {
  108. strEntId = strAppId = strAppType = strAppWxId = "";
  109. if (this.Request.QueryString["ent_id"] != null &&
  110. this.Request.QueryString["app_id"] != null &&
  111. this.Request.QueryString["app_type"] != null &&
  112. this.Request.QueryString["app_wx_id"] != null)
  113. {
  114. strEntId = this.Request["ent_id"];
  115. strAppId = this.Request["app_id"];
  116. strAppType = this.Request["app_type"];
  117. strAppWxId = this.Request["app_wx_id"];
  118. if (string.IsNullOrEmpty(strEntId) || string.IsNullOrEmpty(strAppId) || string.IsNullOrEmpty(strAppType) || string.IsNullOrEmpty(strAppWxId))
  119. return false;
  120. return true;
  121. }
  122. return false;
  123. }
  124. }
  125. }