-
Notifications
You must be signed in to change notification settings - Fork 2
/
weixinapi.ashx.cs
277 lines (257 loc) · 14.2 KB
/
weixinapi.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using WeiXinApi.Util;
using WeiXinApi.Model;
using System.Net;
using System.Web.UI;
using System.Web.SessionState;
using System.Web.Script.Serialization;
using WeiXinApi.Sql;
namespace WeiXinApi
{
/// <summary>
/// weixinapi 的摘要说明
/// </summary>
public class weixinapi : IHttpHandler, IRequiresSessionState
{
public static string Lat = "";
public static string Lon = "";
public void ProcessRequest(HttpContext context)
{
wxmessage wxGlobal = new wxmessage();
FunctionAll fuc = new FunctionAll();
XmlDocument doc = new XmlDocument();
try
{
fuc.MyMenu();
string postXmlStr = PostInput();
if (!string.IsNullOrEmpty(postXmlStr))
{
doc.LoadXml(postXmlStr);
XmlElement root = doc.DocumentElement;
wxGlobal = fuc.GetWxMessage(doc);
string result = "";
string requestContent = "";
if (wxGlobal.MsgType == null)
{
return;
}
else
{
//获取用户发来的信息
switch (wxGlobal.MsgType)
{
case "text"://文本
requestContent = WeiXinXML.CreateTextMsg(doc, wxGlobal.Content);
LogHelper.WriteLog(requestContent);
string[] openids = { "oSsyq09bnj5hSW7lcaMS5R2gHmnk", "oSsyq07cxXuYW8FnCP1-MYt_B_5o", "oSsyq0weqN9UK8JoTpDyht1-TlyU", "oSsyq06MZ7HZmG3Q4gckkHGSLMWE" ,
"oZTyM02MtDG3IeLJn2RcMO7U4pws","oZTyM07BSndJcyK9dRx6YgJqko1s","oZTyM04WHKk60iaxtieCLTtzNw6I"};
string[] types = { "1", "2", "3", "4", "5", "6", "7" };
if (openids.Contains(wxGlobal.FromUserName))
{
string str = string.Empty;
string Title = string.Empty;
if (types.Contains(wxGlobal.Content))
{
DataTable dt = OrderQuery.getOrder(wxGlobal.Content);
str = OrderQuery.test(dt);
switch (wxGlobal.Content)
{
case "1":
Title = "全程陪诊";
break;
case "2":
Title = "检查代预约";
break;
case "3":
Title = "专家号源预约";
break;
case "4":
Title = "专家诊疗建议";
break;
case "5":
Title = "手术直通车";
break;
case "6":
Title = "病床预约";
break;
case "7":
Title = "代领代寄代解读报告单";
break;
default:
Title = "";
break;
}
}
else
str = OrderQuery.test();
switch (wxGlobal.Content)
{
case "1":
result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
break;
case "2":
result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
break;
case "3":
result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
break;
case "4":
result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
break;
case "5":
result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
break;
case "6":
result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
break;
case "7":
result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
break;
default:
result = WeiXinXML.CreateTextMsg(doc, str);
break;
}
}
else
result = WeiXinXML.CreateTextMsg(doc, TuLing.GetTulingMsg(wxGlobal.Content));
break;
case "location"://文本
result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您附近的XXX", "XXXXXXXX", "http://119.29.20.29/image/test.jpg", FunctionAll.GetCodeUrl(null));
break;
case "event":
switch (wxGlobal.EventName)
{
case "subscribe": //订阅
result = WeiXinXML.subscribeRes(doc);
break;
case "unsubscribe": //取消订阅
break;
case "CLICK":
if (wxGlobal.EventKey == "HELLO")
result = WeiXinXML.CreateTextMsg(doc, "微医app - 原名 挂号网,用手机挂号,十分方便!更有医生咨询、智能分诊、院外候诊、病历管理等强大功能。\r\n" +
"预约挂号 聚合全国超过900家重点医院的预约挂号资源\r\n" +
"咨询医生 支持医患之间随时随地图文、语音、视频方式的沟通交流\r\n" +
"智能分诊 根据分诊自测系统分析疾病类型,提供就诊建议\r\n" +
"院外候诊 时间自由可控,不再无谓浪费\r\n" +
"病历管理 病历信息统一管理,个人健康及时监测\r\n" +
"贴心服务 医疗支付、报告提取、医院地图\r\n" +
"权威保障 国家卫计委(原卫生部)指定的全国健康咨询及就医指导平台\r\n" +
"[微医] 目前用户量大,有些不足我们正加班加点的努力完善,希望大家用宽容的心给 [微医] 一点好评,给我们一点激励,让 [微医] 和大家的健康诊疗共成长。");
if (wxGlobal.EventKey == "myprofile")
result = WeiXinXML.CreateTextMsg(doc, "功能测试中,敬请期待!");
if (wxGlobal.EventKey == "jkzx")
result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "点击图片查看您附近的疾控中心", @"测试测试测试测试", "http://119.29.20.29/image/navi.jpg", "http://m.amap.com/around/?locations=&keywords=疾控中心&defaultIndex=3&defaultView=map&searchRadius=5000&key=33fe5b1e0fc0023eb1cd28b392d5e70f");
break;
case "LOCATION": //获取地理位置
Lat = wxGlobal.Latitude; Lon = wxGlobal.Longitude;
break;
}
break;
}
}
context.Response.Write(result);
context.Response.Flush();
LogHelper.WriteLog("系统回复的明文" + result);
}
else
{
valid(context);
return;
}
}
catch (Exception ex)
{
LogHelper.WriteLog(ex.Message);
}
}
public void valid(HttpContext context)
{
var echostr = context.Request["echostr"].ToString();
if (checkSignature(context) && !string.IsNullOrEmpty(echostr))
{
context.Response.Write(echostr);
context.Response.Flush(); //推送...不然微信平台无法验证token
}
}
#region 获取post请求数据
/// <summary>
/// 获取post请求数据
/// </summary>
/// <returns></returns>
private string PostInput()
{
string data = "";
Stream s = System.Web.HttpContext.Current.Request.InputStream;
byte[] b = new byte[s.Length];
s.Read(b, 0, (int)s.Length);
data = Encoding.UTF8.GetString(b);
return data;
}
#endregion
/// <summary>
/// 第一步,公众号开发者验证方法
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public bool checkSignature(HttpContext context)
{
var signature = context.Request["signature"].ToString();
var timestamp = context.Request["timestamp"].ToString();
var nonce = context.Request["nonce"].ToString();
var token = "key";
string[] ArrTmp = { token, timestamp, nonce };
Array.Sort(ArrTmp); //字典排序
string tmpStr = string.Join("", ArrTmp);
tmpStr = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");
tmpStr = tmpStr.ToLower();
if (tmpStr == signature)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 获取token
/// </summary>
/// <returns></returns>
public static wxmessage GetAddress(string lat, string lon)
{
//string appid = "wx3fd9b86495ce9609";
//string secret = "6f6a79781e36f7c69e48533f209bc226";
string strUrl = "http://api.map.baidu.com/geoconv/v1/?coords=" + lat + "," + lon + "&from=1&to=5&ak=MGIAm9Vi0b7bKAanmtGluzTxUryGef9K";
wxmessage mode = new wxmessage();
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
req.Method = "GET";
using (WebResponse wr = req.GetResponse())
{
HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
//Response.Write(content);
//在这里对Access_token 赋值
wxmessage token = new wxmessage();
token = JsonHelper.ParseFromJson<wxmessage>(content);
//mode.Latitude = token.Location_X;
//mode.expires_in = token.expires_in;
}
return mode;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}