PostInfo.aspx.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using LYFZ.Weixin.SDK;
  2. using LYFZ.WXLibrary;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. namespace LYFZ.WeixinServers.WeiXinAPP
  11. {
  12. public partial class PostInfo : System.Web.UI.Page
  13. {
  14. string postinfoddomaine = "post";
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. /* if (!Global.LogsDongleDomainList.Contains(postinfoddomaine))
  18. {
  19. Global.LogsDongleDomainList.Add(postinfoddomaine);
  20. }*/
  21. try
  22. {
  23. string signature = Request["signature"];
  24. string timestamp = Request["timestamp"];// yyyyMMddhhmmss
  25. string nonce = Request["nonce"];
  26. if (Request.HttpMethod == "GET")
  27. {
  28. if (Request.QueryString["type"] == null)
  29. {
  30. Response.Write("如果你在浏览器中看到这句话,说明此地址可以接口的Url,请注意保持Token一致。" + LYFZ.Weixin.SDK.BasicAPI.GetSignature(timestamp, nonce, Global.lyfzToken));
  31. }
  32. }
  33. else
  34. {
  35. var ent = "";
  36. if (!CheckSignature(signature, timestamp, nonce, Global.lyfzToken, out ent))
  37. {
  38. CommonHandleClass.WriteLog("POST:验证失败,非法提交", postinfoddomaine, Global.LogsDongleDomainList);
  39. WriteContent("验证失败,非法提交!");
  40. return;
  41. }
  42. try
  43. {
  44. WriteContent(PostHandler());
  45. }
  46. catch (Exception ex)
  47. {
  48. CommonHandleClass.WriteLog("POST:出错,原因:" + ex.Message, postinfoddomaine, Global.LogsDongleDomainList);
  49. WriteContent("服务器处理出错误!原因:" + ex.Message);
  50. return;
  51. }
  52. }
  53. }
  54. catch { }
  55. finally
  56. {
  57. Response.End();
  58. }
  59. }
  60. #region 获取web客户端ip
  61. /// <summary>
  62. /// 获取web客户端ip
  63. /// </summary>
  64. /// <returns></returns>
  65. public static string GetWebClientIp()
  66. {
  67. string userIP = "0.0.0.0";
  68. try
  69. {
  70. if (System.Web.HttpContext.Current == null
  71. || System.Web.HttpContext.Current.Request == null
  72. || System.Web.HttpContext.Current.Request.ServerVariables == null)
  73. return "";
  74. string CustomerIP = "";
  75. //CDN加速后取到的IP simone 090805
  76. CustomerIP = System.Web.HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
  77. if (!string.IsNullOrEmpty(CustomerIP))
  78. {
  79. return CustomerIP;
  80. }
  81. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  82. if (!String.IsNullOrEmpty(CustomerIP))
  83. return CustomerIP;
  84. if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
  85. {
  86. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  87. if (CustomerIP == null)
  88. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
  89. }
  90. else
  91. {
  92. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
  93. }
  94. if (string.Compare(CustomerIP, "unknown", true) == 0)
  95. return System.Web.HttpContext.Current.Request.UserHostAddress;
  96. return CustomerIP;
  97. }
  98. catch { }
  99. return userIP;
  100. }
  101. #endregion
  102. bool CheckSignature(string signature, string timestamp, string nonce, string token, out string ent)
  103. {
  104. // if (Convert.ToInt64(DateTime.Now.ToString("yyyyMMddhhmmss")) - Convert.ToInt64(timestamp) > 200)
  105. // {
  106. return BasicAPI.CheckSignature(signature, timestamp, nonce, token, out ent);
  107. // }
  108. // else {
  109. // ent = "签名已过期";
  110. // return false;
  111. // }
  112. }
  113. LYFZ.WeixinServiceDate.DAL.DAL_CustomerInterfaces cusDal = new WeixinServiceDate.DAL.DAL_CustomerInterfaces();
  114. string PostHandler()
  115. {
  116. string retMsg = "Set Success";
  117. if (Request.Form["newPost"] != null && Request.Form["newPost"].ToString() == "1")
  118. {
  119. try
  120. {
  121. LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces cusModel = new WeixinServiceDate.Model.Model_CustomerInterfaces();
  122. string JMGDomainName = "";
  123. string ShellDomainName = "";
  124. string IPAddress = "";
  125. int PortNumber = 0;
  126. int UseType = 0;
  127. string CompanyName = "";
  128. // string ThirdPartyPlatformURL = "";
  129. string myToken = "";
  130. string EncodingAESKey = "";
  131. string AppID = "";
  132. string AppSecret = "";
  133. string OfficialAccount = "";
  134. string OfficialAccountName = "";
  135. if (Request.Form["OfficialAccountName"] != null)
  136. {
  137. OfficialAccountName = System.Web.HttpUtility.UrlDecode(Request.Form["OfficialAccountName"].ToString().Trim());
  138. }
  139. if (Request.Form["OfficialAccount"] != null)
  140. {
  141. OfficialAccount = System.Web.HttpUtility.UrlDecode(Request.Form["OfficialAccount"].ToString().Trim());
  142. }
  143. try
  144. {
  145. JMGDomainName = System.Web.HttpUtility.UrlDecode(Request.Form["JMGDomainName"].ToString().Trim());
  146. ShellDomainName = System.Web.HttpUtility.UrlDecode(Request.Form["ShellDomainName"].ToString().Trim());
  147. IPAddress = Request.Form["IPAddress"].ToString().Trim();
  148. // PortNumber = Convert.ToInt32(Request.Form["PortNumber"].ToString());
  149. // UseType = 0;// Convert.ToInt32(Request.Form["UseType"].ToString());
  150. CompanyName = System.Web.HttpUtility.UrlDecode(Request.Form["CompanyName"].ToString()).Trim();
  151. // ThirdPartyPlatformURL = "";//LYFZ.WinAPI.SDKSecurity.Decode(Request.Form["ThirdPartyPlatformURL"].ToString().Trim());
  152. myToken = Request.Form["Token"].ToString().Trim();
  153. // EncodingAESKey = "";//Request.Form["EncodingAESKey"].ToString().Trim();
  154. AppID = Request.Form["AppID"].ToString().Trim();
  155. AppSecret = Request.Form["AppSecret"].ToString().Trim();
  156. }
  157. catch
  158. {
  159. CommonHandleClass.WriteLog("域名信息更新提交失败,参数不完整或格式不正确", postinfoddomaine, Global.LogsDongleDomainList);
  160. return System.Web.HttpUtility.UrlEncode("Exception:参数不正确");
  161. }
  162. if (JMGDomainName.Trim().Length > 0)
  163. {
  164. cusModel = Global.GetCustomerModel(JMGDomainName);
  165. if (cusModel != null && cusModel.ID > 0)
  166. {
  167. try
  168. {
  169. cusModel.ShellDomainName = ShellDomainName;
  170. cusModel.IPAddress = IPAddress;
  171. cusModel.PortNumber = 0;
  172. cusModel.UseType = 0;
  173. cusModel.CompanyName = CompanyName;
  174. cusModel.RefreshTime = DateTime.Now;
  175. cusModel.OfficialAccount = OfficialAccount;
  176. cusModel.OfficialAccountName = OfficialAccountName;
  177. cusModel.ThirdPartyPlatformURL = "";
  178. cusModel.Token = myToken;
  179. cusModel.AppID = AppID;
  180. cusModel.AppSecret = AppSecret;
  181. cusModel.EncodingAESKey = EncodingAESKey;
  182. cusModel.ISEnabled = 1;
  183. if (cusDal.Update(cusModel))
  184. {
  185. cusModel = (LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces)cusDal.GetModelObject("JMGDomainName", JMGDomainName);
  186. Global.UpdateCustInfo(JMGDomainName, cusModel);
  187. try
  188. {
  189. Global.UpdateAuthorizedAPPIDHandleJMGDomainName(cusModel.AppID, cusModel.JMGDomainName, cusModel.CompanyName);
  190. }
  191. catch (Exception ex)
  192. {
  193. CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的的客户更新授权处理对象加密锁域名时出错:" + ex.Message, postinfoddomaine, Global.LogsDongleDomainList);
  194. }
  195. CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息更新提交成功", postinfoddomaine, Global.LogsDongleDomainList);
  196. }
  197. else
  198. {
  199. retMsg = "Exception:Refresh Failed";
  200. CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息更新提交失败,数据库更新记录时失败", postinfoddomaine, Global.LogsDongleDomainList);
  201. }
  202. }
  203. catch (Exception ex)
  204. {
  205. retMsg = "Exception:" + ex.Message;
  206. CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息更新提交失败,错误信息为:" + ex.Message, postinfoddomaine, Global.LogsDongleDomainList);
  207. Global.RefreshLoadCustDaTable();
  208. }
  209. }
  210. else
  211. {
  212. try
  213. {
  214. cusModel.JMGDomainName = JMGDomainName;
  215. cusModel.ShellDomainName = ShellDomainName;
  216. cusModel.IPAddress = IPAddress;
  217. cusModel.PortNumber = PortNumber;
  218. cusModel.UseType = Convert.ToInt32(UseType);
  219. cusModel.CompanyName = CompanyName;
  220. cusModel.CallFrequency = 0;
  221. cusModel.OfficialAccount = OfficialAccount;
  222. cusModel.OfficialAccountName = OfficialAccountName;
  223. if (cusModel.ThirdPartyPlatformURL.Trim().Length <= 5)
  224. {
  225. cusModel.ThirdPartyPlatformURL = "";
  226. }
  227. cusModel.Token = myToken;
  228. cusModel.AppID = AppID;
  229. cusModel.AppSecret = AppSecret;
  230. cusModel.EncodingAESKey = EncodingAESKey;
  231. cusModel.ISEnabled = 1;
  232. if (cusDal.Add(cusModel))
  233. {
  234. cusModel = (LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces)cusDal.GetModelObject("JMGDomainName", JMGDomainName);
  235. Global.UpdateCustInfo(JMGDomainName, cusModel);
  236. // retMsg += ":" + IPAddress;
  237. CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息提交成功", postinfoddomaine, Global.LogsDongleDomainList);
  238. }
  239. else
  240. {
  241. retMsg = "Exception:Add Failed";
  242. CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息提交失败,数据库添加记录时失败", postinfoddomaine, Global.LogsDongleDomainList);
  243. }
  244. }
  245. catch (Exception ex)
  246. {
  247. retMsg = "Exception:" + ex.Message;
  248. CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息提交失败,错误信息为:" + ex.Message, postinfoddomaine, Global.LogsDongleDomainList);
  249. Global.RefreshLoadCustDaTable();
  250. }
  251. }
  252. }
  253. else
  254. {
  255. retMsg = "Exception:JMG domain name not be null";
  256. CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息提交失败,错误信息为:加密狗域名不能为空", postinfoddomaine, Global.LogsDongleDomainList);
  257. }
  258. }
  259. catch (Exception ex)
  260. {
  261. retMsg = "Exception:" + ex.Message;
  262. CommonHandleClass.WriteLog("域名信息提交失败,错误信息为:" + ex.Message, postinfoddomaine, Global.LogsDongleDomainList);
  263. }
  264. }
  265. return System.Web.HttpUtility.UrlEncode(retMsg);
  266. }
  267. private void WriteContent(string str)
  268. {
  269. Response.Output.Write(str);
  270. }
  271. }
  272. }