forked from ian-cuc/suite-demo-c-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserCheck.aspx.cs
72 lines (61 loc) · 2.5 KB
/
UserCheck.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
using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;
using System.Text;
using System.Net;
using System.IO;
using System.Runtime.Serialization.Json;
using Suite.Common;
using System.Web.Security;
namespace Suite
{
public partial class UserCheck : System.Web.UI.Page
{
public string appId = string.Empty;
public string timestamp = string.Empty;
public string nonceStr = string.Empty;
public string signature = string.Empty;
public string jsApiList = string.Empty;
public string corpId = string.Empty;
string corpSecret = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
corpId = ConfigurationManager.AppSettings["CorpId"];//从配置文件获取corpId
if (string.IsNullOrEmpty(corpId))
{
Helper.WriteLog(string.Format("CorpId 配置项没有配置!"));
}
corpSecret = ConfigurationManager.AppSettings["CorpSecret"];//从配置文件获取CorpSecret
if (string.IsNullOrEmpty(corpSecret))
{
Helper.WriteLog(string.Format("CorpSecret 配置项没有配置!"));
}
GetConfig();
}
public double GetTimeStamp()
{
DateTime dt1 = Convert.ToDateTime("1970-01-01 00:00:00");
TimeSpan ts = DateTime.Now - dt1;
return Math.Ceiling(ts.TotalSeconds);
}
private string GetConfig()
{
nonceStr = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
timestamp = GetTimeStamp().ToString();
string url = Request.Url.ToString();
appId = "4801092";
string jsApiTicket = Helper.GetJsApiTicket();
Helper.WriteLog("nonceStr:" + nonceStr);
Helper.WriteLog("timestamp:" + timestamp);
Helper.WriteLog("url:" + url);
Helper.WriteLog("jsApiTicket:" + jsApiTicket);
string string1 = "jsapi_ticket={0}&noncestr={1}×tamp={2}&url={3}";
string1 = string.Format(string1, jsApiTicket, nonceStr, timestamp, url);
Helper.WriteLog("signature not sha1:" + string1);
signature = FormsAuthentication.HashPasswordForStoringInConfigFile(string1, "SHA1").ToLower();
Helper.WriteLog("signature sha1:" + signature);
return "";
}
}
}