-
Notifications
You must be signed in to change notification settings - Fork 0
/
360Redirect.aspx.cs
99 lines (89 loc) · 3.91 KB
/
360Redirect.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Security.Cryptography;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Net;
using System.IO;
public partial class _360Redirect : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
#region 获取POST数据
string bid = Request.Form["bid"];
string qihoo_id = Request.Form["qihoo_id"];
string url = Request.Form["url"];
string from_url = Request.Form["from_url"];
string active_time = Request.Form["active_time"]; //请求时间的时间戳
string ext = Request.Form["ext"];
string qid = Request.Form["qid"];
string qmail = Request.Form["qmail"];
string qname = Request.Form["qname"];
string sign = Request.Form["sign"];
#endregion
#region 设置cookie信息
HttpCookie cookie = new HttpCookie("cpsinfo");
cookie.Values.Add("id", "360cps");
cookie.Values.Add("qihoo_id", qihoo_id);
cookie.Values.Add("ext", ext);
cookie.Values.Add("qid", qid);
cookie.Values.Add("qmail", qmail);
cookie.Values.Add("qname", qname);
cookie.Expires = DateTime.Now.AddDays(Cps360Config.COOKIE_RD);
cookie.Domain = Cps360Config.COOKIE_DOMAIN;
cookie.Path = "/";
Response.Cookies.Add(cookie);
#endregion
#region 构造签名
string sign_check = String.Join("#", new string[] { bid, active_time, Cps360Config.CP_KEY, qid, qmail, qname });
sign_check = Cps360Utils.getMd5Hash(sign_check);
#endregion
long currentTime = Cps360Utils.getCurrentTimestamp();
string msg = "";
//检查超时时间和签名,如果失败,向360发送一个错误通知
if (!Cps360Utils.checkActiveTime(long.Parse(active_time), out msg) || sign_check != sign)
{
string from_ip = Page.Request.UserHostAddress;
ASCIIEncoding encoding = new ASCIIEncoding();
string t_sign = Cps360Utils.getMd5Hash(String.Join("#", new string[] { Cps360Config.BID, currentTime.ToString(), Cps360Config.CP_KEY }));
string postData = String.Join("&", new string[] { "bid=" + Cps360Config.BID,
"active_time=" + currentTime,
"sign=" + t_sign,
"pre_bid=" + bid,
"pre_active_time=" + active_time,
"pre_sign=" + sign,
"qid=" + qid,
"qname=" + qname,
"qmail=" + qmail,
"from_url=" + from_url,
"from_ip=" + from_ip });
byte[] data = encoding.GetBytes(postData);
Cps360Utils.postRequest(Cps360Config.FAILED_URL, data);
}
else
{
if (!String.IsNullOrEmpty(qid))
{
//实现自动登录
Cps360Model cpsModel = new Cps360Model();
cpsModel.autoLogin(qid, qname, qmail);
}
}
#region 完成跳转
if (String.IsNullOrEmpty(url))
{
url = Cps360Config.DEFAULT_GO_URL;
}
Response.Redirect(url);
#endregion
}
}