123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- using LYFZ.Weixin.SDK;
- using LYFZ.WXLibrary;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace LYFZ.WeixinServers.WeiXinAPP
- {
- public partial class PostInfo : System.Web.UI.Page
- {
- string postinfoddomaine = "post";
- protected void Page_Load(object sender, EventArgs e)
- {
-
- /* if (!Global.LogsDongleDomainList.Contains(postinfoddomaine))
- {
- Global.LogsDongleDomainList.Add(postinfoddomaine);
- }*/
- try
- {
- string signature = Request["signature"];
- string timestamp = Request["timestamp"];// yyyyMMddhhmmss
- string nonce = Request["nonce"];
- if (Request.HttpMethod == "GET")
- {
- if (Request.QueryString["type"] == null)
- {
- Response.Write("如果你在浏览器中看到这句话,说明此地址可以接口的Url,请注意保持Token一致。" + LYFZ.Weixin.SDK.BasicAPI.GetSignature(timestamp, nonce, Global.lyfzToken));
- }
- }
- else
- {
- var ent = "";
- if (!CheckSignature(signature, timestamp, nonce, Global.lyfzToken, out ent))
- {
- CommonHandleClass.WriteLog("POST:验证失败,非法提交", postinfoddomaine, Global.LogsDongleDomainList);
- WriteContent("验证失败,非法提交!");
- return;
- }
- try
- {
- WriteContent(PostHandler());
- }
- catch (Exception ex)
- {
- CommonHandleClass.WriteLog("POST:出错,原因:" + ex.Message, postinfoddomaine, Global.LogsDongleDomainList);
- WriteContent("服务器处理出错误!原因:" + ex.Message);
- return;
- }
- }
- }
- catch { }
- finally
- {
- Response.End();
- }
- }
-
- #region 获取web客户端ip
- /// <summary>
- /// 获取web客户端ip
- /// </summary>
- /// <returns></returns>
- public static string GetWebClientIp()
- {
- string userIP = "0.0.0.0";
- try
- {
- if (System.Web.HttpContext.Current == null
- || System.Web.HttpContext.Current.Request == null
- || System.Web.HttpContext.Current.Request.ServerVariables == null)
- return "";
- string CustomerIP = "";
- //CDN加速后取到的IP simone 090805
- CustomerIP = System.Web.HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
- if (!string.IsNullOrEmpty(CustomerIP))
- {
- return CustomerIP;
- }
- CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
- if (!String.IsNullOrEmpty(CustomerIP))
- return CustomerIP;
- if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
- {
- CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
- if (CustomerIP == null)
- CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
- }
- else
- {
- CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
- }
- if (string.Compare(CustomerIP, "unknown", true) == 0)
- return System.Web.HttpContext.Current.Request.UserHostAddress;
- return CustomerIP;
- }
- catch { }
-
- return userIP;
- }
- #endregion
- bool CheckSignature(string signature, string timestamp, string nonce, string token, out string ent)
- {
- // if (Convert.ToInt64(DateTime.Now.ToString("yyyyMMddhhmmss")) - Convert.ToInt64(timestamp) > 200)
- // {
- return BasicAPI.CheckSignature(signature, timestamp, nonce, token, out ent);
- // }
- // else {
- // ent = "签名已过期";
- // return false;
- // }
- }
- LYFZ.WeixinServiceDate.DAL.DAL_CustomerInterfaces cusDal = new WeixinServiceDate.DAL.DAL_CustomerInterfaces();
- string PostHandler()
- {
- string retMsg = "Set Success";
- if (Request.Form["newPost"] != null && Request.Form["newPost"].ToString() == "1")
- {
- try
- {
- LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces cusModel = new WeixinServiceDate.Model.Model_CustomerInterfaces();
- string JMGDomainName = "";
- string ShellDomainName = "";
- string IPAddress = "";
- int PortNumber = 0;
- int UseType = 0;
- string CompanyName = "";
- // string ThirdPartyPlatformURL = "";
- string myToken = "";
- string EncodingAESKey = "";
- string AppID = "";
- string AppSecret = "";
- string OfficialAccount = "";
- string OfficialAccountName = "";
- if (Request.Form["OfficialAccountName"] != null)
- {
- OfficialAccountName = System.Web.HttpUtility.UrlDecode(Request.Form["OfficialAccountName"].ToString().Trim());
- }
- if (Request.Form["OfficialAccount"] != null)
- {
- OfficialAccount = System.Web.HttpUtility.UrlDecode(Request.Form["OfficialAccount"].ToString().Trim());
- }
- try
- {
- JMGDomainName = System.Web.HttpUtility.UrlDecode(Request.Form["JMGDomainName"].ToString().Trim());
- ShellDomainName = System.Web.HttpUtility.UrlDecode(Request.Form["ShellDomainName"].ToString().Trim());
- IPAddress = Request.Form["IPAddress"].ToString().Trim();
- // PortNumber = Convert.ToInt32(Request.Form["PortNumber"].ToString());
- // UseType = 0;// Convert.ToInt32(Request.Form["UseType"].ToString());
- CompanyName = System.Web.HttpUtility.UrlDecode(Request.Form["CompanyName"].ToString()).Trim();
- // ThirdPartyPlatformURL = "";//LYFZ.WinAPI.SDKSecurity.Decode(Request.Form["ThirdPartyPlatformURL"].ToString().Trim());
- myToken = Request.Form["Token"].ToString().Trim();
- // EncodingAESKey = "";//Request.Form["EncodingAESKey"].ToString().Trim();
- AppID = Request.Form["AppID"].ToString().Trim();
- AppSecret = Request.Form["AppSecret"].ToString().Trim();
- }
- catch
- {
- CommonHandleClass.WriteLog("域名信息更新提交失败,参数不完整或格式不正确", postinfoddomaine, Global.LogsDongleDomainList);
- return System.Web.HttpUtility.UrlEncode("Exception:参数不正确");
- }
- if (JMGDomainName.Trim().Length > 0)
- {
- cusModel = Global.GetCustomerModel(JMGDomainName);
- if (cusModel != null && cusModel.ID > 0)
- {
- try
- {
- cusModel.ShellDomainName = ShellDomainName;
- cusModel.IPAddress = IPAddress;
- cusModel.PortNumber = 0;
- cusModel.UseType = 0;
- cusModel.CompanyName = CompanyName;
- cusModel.RefreshTime = DateTime.Now;
- cusModel.OfficialAccount = OfficialAccount;
- cusModel.OfficialAccountName = OfficialAccountName;
- cusModel.ThirdPartyPlatformURL = "";
- cusModel.Token = myToken;
- cusModel.AppID = AppID;
- cusModel.AppSecret = AppSecret;
- cusModel.EncodingAESKey = EncodingAESKey;
- cusModel.ISEnabled = 1;
- if (cusDal.Update(cusModel))
- {
- cusModel = (LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces)cusDal.GetModelObject("JMGDomainName", JMGDomainName);
- Global.UpdateCustInfo(JMGDomainName, cusModel);
- try
- {
- Global.UpdateAuthorizedAPPIDHandleJMGDomainName(cusModel.AppID, cusModel.JMGDomainName, cusModel.CompanyName);
- }
- catch (Exception ex)
- {
- CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的的客户更新授权处理对象加密锁域名时出错:" + ex.Message, postinfoddomaine, Global.LogsDongleDomainList);
- }
- CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息更新提交成功", postinfoddomaine, Global.LogsDongleDomainList);
- }
- else
- {
- retMsg = "Exception:Refresh Failed";
- CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息更新提交失败,数据库更新记录时失败", postinfoddomaine, Global.LogsDongleDomainList);
- }
- }
- catch (Exception ex)
- {
- retMsg = "Exception:" + ex.Message;
- CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息更新提交失败,错误信息为:" + ex.Message, postinfoddomaine, Global.LogsDongleDomainList);
- Global.RefreshLoadCustDaTable();
- }
- }
- else
- {
- try
- {
- cusModel.JMGDomainName = JMGDomainName;
- cusModel.ShellDomainName = ShellDomainName;
- cusModel.IPAddress = IPAddress;
- cusModel.PortNumber = PortNumber;
- cusModel.UseType = Convert.ToInt32(UseType);
- cusModel.CompanyName = CompanyName;
- cusModel.CallFrequency = 0;
- cusModel.OfficialAccount = OfficialAccount;
- cusModel.OfficialAccountName = OfficialAccountName;
- if (cusModel.ThirdPartyPlatformURL.Trim().Length <= 5)
- {
- cusModel.ThirdPartyPlatformURL = "";
- }
- cusModel.Token = myToken;
- cusModel.AppID = AppID;
- cusModel.AppSecret = AppSecret;
- cusModel.EncodingAESKey = EncodingAESKey;
- cusModel.ISEnabled = 1;
- if (cusDal.Add(cusModel))
- {
- cusModel = (LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces)cusDal.GetModelObject("JMGDomainName", JMGDomainName);
- Global.UpdateCustInfo(JMGDomainName, cusModel);
- // retMsg += ":" + IPAddress;
- CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息提交成功", postinfoddomaine, Global.LogsDongleDomainList);
- }
- else
- {
- retMsg = "Exception:Add Failed";
- CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息提交失败,数据库添加记录时失败", postinfoddomaine, Global.LogsDongleDomainList);
- }
- }
- catch (Exception ex)
- {
- retMsg = "Exception:" + ex.Message;
- CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息提交失败,错误信息为:" + ex.Message, postinfoddomaine, Global.LogsDongleDomainList);
- Global.RefreshLoadCustDaTable();
- }
- }
- }
- else
- {
- retMsg = "Exception:JMG domain name not be null";
- CommonHandleClass.WriteLog("域名为:" + JMGDomainName + " 的信息提交失败,错误信息为:加密狗域名不能为空", postinfoddomaine, Global.LogsDongleDomainList);
- }
- }
- catch (Exception ex)
- {
- retMsg = "Exception:" + ex.Message;
- CommonHandleClass.WriteLog("域名信息提交失败,错误信息为:" + ex.Message, postinfoddomaine, Global.LogsDongleDomainList);
- }
- }
- return System.Web.HttpUtility.UrlEncode(retMsg);
- }
- private void WriteContent(string str)
- {
- Response.Output.Write(str);
- }
- }
- }
|