Index.aspx.cs
2.2 KB
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
using System;
using System.Net;
using System.Text;
using Quiz.Models;
using Quiz.Utility;
using WeiXinCenter.Cache;
namespace WeiXinCenter
{
public partial class Index : System.Web.UI.Page
{
protected string account = "";
protected void Page_Load(object sender, EventArgs e)
{
account = Request["typeid"];
string openid = "";
if (account == "jyzj")
{
openid = "oZQJpsxjtAnYOFEbYUzLskcuFX10";
}
else if (account == "zkydt")
{
openid = "o_J9ts8D9_PZ14u0MMprhNh_0vks";
}
string isrestart = Request["restart"];
if (isrestart == "1")//重新初始化
{
CacheManage.Initialize();
Response.End();
}
OperationResult m=new OperationResult(OperationResultType.Success);
var Weixinaccount = CacheManage.Authorize.CacheData[account];
WxAccount wxaccount = new WxAccount
{
AccessToken = Weixinaccount.AccessToken,
JsapiTicket = Weixinaccount.JsapiTicket
};
//判断是否token过期
//WebClient client = new WebClient();
//client.Encoding = Encoding.UTF8;
//string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN", wxaccount.AccessToken, openid);
//string userinfojson = client.DownloadString(url);
//WxUser wx = JsonHelper.ParseFromJson<WxUser>(userinfojson);
//if (string.IsNullOrEmpty(wx.openid))
//{
// //判断我本人的OPENID,如果获取到的为空,且错误为40001,代表过期,则重启
// WeixinErrorResponse error = JsonHelper.ParseFromJson<WeixinErrorResponse>(userinfojson);
// if (error != null && error.ErrCode == "40001")//过期
// {
// CacheManage.Initialize();
// Response.End();
// }
//}
Response.Write(JsonHelper.SerializeObject(wxaccount));
Response.End();
}
}
}