forked from ian-cuc/suite-demo-c-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOAuth2Check.ashx.cs
57 lines (50 loc) · 2.02 KB
/
OAuth2Check.ashx.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;
using System.Web.Services;
using Suite.Common;
namespace Suite
{
/// <summary>
/// OAuth2Check 的摘要说明
/// </summary>
public class OAuth2Check : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{ //code说明 :code作为换取access_token的票据,每次用户授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。
string code = HttpContext.Current.Request["code"];
Helper.WriteLog("code:" + code);
string corpId = ConfigurationManager.AppSettings["CorpId"];//从配置文件获取corpId
if (string.IsNullOrEmpty(corpId))
{
Helper.WriteLog(string.Format("CorpId 配置项没有配置!"));
}
string corpSecret = ConfigurationManager.AppSettings["CorpSecret"];//从配置文件获取CorpSecret
if (string.IsNullOrEmpty(corpSecret))
{
Helper.WriteLog(string.Format("CorpSecret 配置项没有配置!"));
}
string redirectUrl = "http://live.fumasoft.com:8011/Test.aspx";
redirectUrl = HttpUtility.UrlEncode(redirectUrl);
string url = "https://oapi.dingtalk.com/connect/oauth2/authorize?appid="+ corpId + "&redirect_uri="+ redirectUrl + "&response_type=code&scope=snsapi_base&state=abcd1234";
Helper.WriteLog("url:" + url);
string result = Helper.GetCorpExecuteResult(url);
Helper.WriteLog("result:" + result);
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}