private void butOK_Click(object sender, EventArgs e) { if (textConcept.errorProvider1.GetError(textConcept) != "" || textWriteup.errorProvider1.GetError(textWriteup) != "" || textDevelopment.errorProvider1.GetError(textDevelopment) != "" || textReview.errorProvider1.GetError(textReview) != "") { MsgBox.Show(this, "Please enter valid hour estimates before attempting to save."); return; } Job jobOld = JobCur.Copy(); JobCur.HoursEstimateConcept = PIn.Double(textConcept.Text); JobCur.HoursEstimateWriteup = PIn.Double(textWriteup.Text); JobCur.HoursEstimateDevelopment = PIn.Double(textDevelopment.Text); JobCur.HoursEstimateReview = PIn.Double(textReview.Text); if (JobLogs.MakeLogEntryForEstimateChange(JobCur, jobOld, textNote.Text)) { DialogResult = DialogResult.OK; } else { DialogResult = DialogResult.Cancel; } }
private string set_tags(string AdminHotelId, string openid) { string accessToken = TemplateMessage.GetAccessToken(AdminHotelId); string url = string.Format("https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token={0}", accessToken.Trim()); string menuInfo = "{\"openid_list\":[\"" + openid + "\"],\"tagid\":2}"; string val = TemplateMessage.PostWebRequest(url, menuInfo); JobLogs.Writer(log_Folder, "设置用户星标结果:" + val); return(val); }
private string set_tags(string accessToken, List <string> listOpenid) { JavaScriptSerializer jss = new JavaScriptSerializer(); string openids = jss.Serialize(listOpenid); string url = string.Format("https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token={0}", accessToken); string menuInfo = "{\"openid_list\":" + openids + ",\"tagid\":2}"; string val = TemplateMessage.PostWebRequest(url, menuInfo); JobLogs.Writer(log_Folder, "设置用户星标结果:" + val); return(val); }
private void set_user_tag(string AdminHotelId, string openid) { JobLogs.Writer(log_Folder, "设置用户星标"); string data = set_tags(AdminHotelId, openid); JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> userInfo = (Dictionary <string, object>)serializer.DeserializeObject(data); object value = null; string errcode = ""; if (userInfo.TryGetValue("errcode", out value)) { errcode = value.ToString(); } if (errcode == "40001") { Hashtable htToken = new Hashtable(); htToken["Access_Token"] = ""; DataFactory.SqlDataBase().UpdateByHashtable("WX_Access_Token", "AdminHotelId", AdminHotelId, htToken); Dictionary <string, object> csInfo = new Dictionary <string, object>(); csInfo.Add("AdminHotelId", AdminHotelId); // csInfo.Add("HotelId", "0"); // string menuInfo = serializer.Serialize(csInfo); string postUrl = "http://zidinn.com/API/wxtoken.ashx?action=set_token"; TemplateMessage.PostWebRequest(postUrl, menuInfo); data = set_tags(AdminHotelId, openid); userInfo = (Dictionary <string, object>)serializer.DeserializeObject(data); } string accessToken = TemplateMessage.GetAccessToken(AdminHotelId); string url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token={0}", accessToken.Trim()); string cdInfo = "{\"user_id\":\"" + openid + "\"}"; string val = TemplateMessage.PostWebRequest(url, cdInfo); JobLogs.Writer(log_Folder, "测试个性化菜单匹配结果:" + val); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request["action"].ToString(); JobLogs.Writer(log_Folder, action); switch (action) { case "get_union": get_union(context); break; case "get_tags": get_tags(context); break; case "set_tags_all": //所有关注粉丝全部设置为星标用户 set_tags_all(context); break; default: break; } }
public string Analysis(HttpContext context, string jsonDate, string appid) { string resxml = ""; try { JobLogs.Writer(log_Folder, "------------------- 分割线 -------------------"); XmlDocument doc = new XmlDocument(); doc.XmlResolver = null; doc.LoadXml(jsonDate);//读取xml字符串 XmlElement root = doc.DocumentElement; ExmlMsg xmlMsg = GetExmlMsg(root); string messageType = xmlMsg.MsgType;//获取收到的消息类型。文本(text),图片(image),语音等。 string openid = xmlMsg.FromUserName; switch (messageType) { //当消息为文本时 case "text": string con = xmlMsg.Content.Trim(); //自动化测试的专用测试公众号 if (con == "TESTCOMPONENT_MSG_TYPE_TEXT") { resxml = ReplyWX.text_xml("TESTCOMPONENT_MSG_TYPE_TEXT_callback", openid, xmlMsg.ToUserName, xmlMsg.CreateTime); } else { #region ** string[] Contents = con.Split(':'); if (Contents.Length == 2 && Contents[0] == "QUERY_AUTH_CODE") { string auth = Contents[0]; string code = Contents[1]; string Appsecret = ""; string Ticket = ""; string Token = ""; string Code = ""; GetToken(appid, ref Appsecret, ref Ticket, ref Token, ref Code); //获取Token JobLogs.Writer(log_Folder, "Token111111111111" + Token); if (Token == "") { appid = "wx1939f9ee65384f14"; GetToken(appid, ref Appsecret, ref Ticket, ref Token, ref Code); } if (Token != "") { JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> csInfo = new Dictionary <string, object>(); csInfo.Add("component_appid", appid); // csInfo.Add("authorization_code", code); // string menuInfo = serializer.Serialize(csInfo); string postUrl = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=" + Token; string val = TemplateMessage.PostWebRequest(postUrl, menuInfo); JobLogs.Writer(log_Folder, "返回结果:" + val); Dictionary <string, object> dToken = (Dictionary <string, object>)serializer.DeserializeObject(val); if (dToken != null && dToken.Count == 1) { Dictionary <string, object> dInfo = dToken["authorization_info"] as Dictionary <string, object>; string access_token = ""; object value; if (dInfo.TryGetValue("authorizer_access_token", out value)) { access_token = value.ToString(); JobLogs.Writer(log_Folder, "access_token:" + access_token); SendText(access_token, openid, code + "_from_api"); } } } } #endregion } break; case "event": if (!string.IsNullOrEmpty(xmlMsg.EventName) && (xmlMsg.EventName == "subscribe" || xmlMsg.EventName == "SCAN")) { break; JobLogs.Writer("event", jsonDate); //写入日志 Hashtable ht = new Hashtable(); ht["ToUserName"] = xmlMsg.ToUserName; ht["FromUserName"] = xmlMsg.FromUserName; ht["CreateTime"] = xmlMsg.CreateTime; ht["MsgType"] = xmlMsg.MsgType; ht["Event"] = xmlMsg.EventName; ht["EventKey"] = xmlMsg.EventKey; bool zizhu = (string.IsNullOrEmpty(xmlMsg.EventKey) || xmlMsg.EventKey.IndexOf("last_trade_no") >= 0); //是否为自主关注 ht["Independent"] = zizhu; ht["Url"] = context.Request.Url.ToString(); DataFactory.SqlDataBase().InsertByHashtable("Wx_CallbackLog", ht); string AdminHotelId = ApplicationHelper.GetHotelTweetsInfo(xmlMsg.ToUserName).Rows[0]["AdminHotelid"].ToString(); set_user_tag(AdminHotelId, openid); //设置为星标用户 if (zizhu) { //if (xmlMsg.ToUserName.ToString() == "gh_4305dc154099") //{ // //关注智订云推送信息 // resxml = ReplyWX.ZDY_Reply(xmlMsg.ToUserName, xmlMsg.FromUserName, xmlMsg.CreateTime); //} //else //{ // resxml = ReplyWX.AutonomyFollow(xmlMsg.ToUserName, xmlMsg.FromUserName, xmlMsg.CreateTime);//自主关注 //} break; } string[] keys = xmlMsg.EventKey.Split('@'); if (keys.Length < 2) { break; } string key_val = keys[1]; switch (xmlMsg.EventName) { case "subscribe": //用户未关注时,进行关注后的事件推送 switch (key_val) { case "3": //扫描二维码回复事件 3 string userid = keys[2]; ReplyWX.ScanUserCode(xmlMsg.FromUserName, userid, "扫推广码[第三方]"); break; case "4": //扫描酒店/门店二维码回复事件 ReplyWX.ScanHotelCode(xmlMsg.ToUserName, keys[2], xmlMsg.FromUserName, xmlMsg.CreateTime); break; default: break; } break; case "SCAN": //用户已关注时的事件推送 switch (key_val) { case "3": //扫描二维码回复事件 3 string userid = keys[2]; ReplyWX.ScanUserCode(xmlMsg.FromUserName, userid, "扫推广码[第三方]"); break; case "4": //扫描酒店/门店二维码回复事件 ReplyWX.ScanHotelCode(xmlMsg.ToUserName, keys[2], xmlMsg.FromUserName, xmlMsg.CreateTime); break; default: break; } break; case "scancode_push": //用户已关注时的事件推送 switch (key_val) { case "3": //扫描二维码回复事件 3 string userid = keys[2]; ReplyWX.ScanUserCode(xmlMsg.FromUserName, userid, "扫推广码[第三方]"); break; case "4": //扫描酒店/门店二维码回复事件 ReplyWX.ScanHotelCode(xmlMsg.ToUserName, keys[2], xmlMsg.FromUserName, xmlMsg.CreateTime); break; default: break; } break; default: break; } } else if (xmlMsg.EventName == "unsubscribe") //取消订阅 { Hashtable ht = new Hashtable(); ht["ToUserName"] = xmlMsg.ToUserName; ht["FromUserName"] = xmlMsg.FromUserName; ht["CreateTime"] = xmlMsg.CreateTime; ht["MsgType"] = xmlMsg.MsgType; ht["Event"] = xmlMsg.EventName; ht["EventKey"] = xmlMsg.EventKey; ht["Independent"] = "0"; ht["Url"] = context.Request.Url.ToString(); DataFactory.SqlDataBase().InsertByHashtable("Wx_CallbackLog", ht); } else if (xmlMsg.EventName == "CLICK") //点击菜单拉取消息时的事件推送 { string click_key = xmlMsg.EventKey; if (click_key == "wgz") //默认菜单 点击是重新获取一下 菜单权限 { JobLogs.Writer(log_Folder, "------------------默认菜单 点击是重新获取一下 菜单权限-------------------:"); string AdminHotelId = ApplicationHelper.GetHotelTweetsInfo(xmlMsg.ToUserName).Rows[0]["AdminHotelid"].ToString(); set_user_tag(AdminHotelId, openid); //string yd_yrl = string.Format("http://www.zidinn.com/Reservation/HotelList.aspx?AdminHotelid={0}", AdminHotelId); //resxml = ReplyWX.text_xml("<a href='" + yd_yrl + "'>酒店预订</a>", openid, xmlMsg.ToUserName, xmlMsg.CreateTime); } } break; case "image": //2 回复图片消息 break; case "voice": //回复语音消息 break; case "vedio": //回复视频消息 break; case "music": //回复音乐消息 break; case "news": //回复图文消息 break; case "location": //上报地理位置事件 break; case "link": break; default: break; } } catch (Exception ex) { resxml = ex.Message; } return(resxml); }
public void ProcessRequest(HttpContext context) { try { JobLogs.Writer(log_Folder, "------------------- 分割线 -------------------"); context.Request.Url.ToString(); JobLogs.Writer(log_Folder, "授权Url:" + context.Request.Url.ToString()); System.IO.StreamReader stream = new System.IO.StreamReader(context.Request.InputStream, Encoding.UTF8); string postData = stream.ReadToEnd(); stream.Close(); JobLogs.Writer(log_Folder, "授权postData*************************************" + postData); string timestamp = context.Request.QueryString["timestamp"]; //时间戳 string nonce = context.Request.QueryString["nonce"]; //随机数 string encrypt_type = context.Request.QueryString["encrypt_type"]; //加密类型,为aes string msg_signature = context.Request.QueryString["msg_signature"]; //消息体签名,用于验证消息体的正确性 XmlDocument doc = new XmlDocument(); doc.XmlResolver = null; doc.LoadXml(postData);//读取xml字符串 XmlElement root = doc.DocumentElement; string AppId = root.SelectSingleNode("AppId").InnerText; string original_text = ""; WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sAppID); int ret = wxcpt.DecryptMsg(msg_signature, timestamp, nonce, postData, ref original_text); if (original_text == "") { JobLogs.Writer(log_Folder, "--------授权解密失败" + ret + "--------"); context.Response.Write("error"); return; } JobLogs.Writer(log_Folder, "授权解密结果:" + original_text); doc = new XmlDocument(); doc.XmlResolver = null; doc.LoadXml(original_text);//读取xml字符串 root = doc.DocumentElement; string InfoType = root.SelectSingleNode("InfoType").InnerText; JobLogs.Writer(log_Folder, "授权消息类型:" + InfoType); switch (InfoType) { case "component_verify_ticket": //推送component_verify_ticket协议 string CreateTime = root.SelectSingleNode("CreateTime").InnerText; string Ticket = root.SelectSingleNode("ComponentVerifyTicket").InnerText; StringBuilder sb = new StringBuilder(); sb.Append(@"SELECT * FROM Wx_PlatformInfo WHERE AppId = @AppId"); SqlParam[] param = new SqlParam[] { new SqlParam("@AppId", AppId) }; DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sb, param); if (dt == null || dt.Rows.Count < 1) { context.Response.Write("success"); return; } string data_Ticket = dt.Rows[0]["Ticket"].ToString(); string token = dt.Rows[0]["Token"].ToString(); update_code(AppId, token); if (data_Ticket == Ticket) { JobLogs.Writer(log_Folder, "data_Ticket================================================Ticket"); context.Response.Write("success"); return; } string Appsecret = dt.Rows[0]["Appsecret"].ToString(); update_token(AppId, Appsecret, Ticket); break; case "authorized": //授权成功通知 authorized(root); break; case "unauthorized": //取消授权通知 unauthorized(root); break; case "updateauthorized": //授权更新通知 updateauthorized(root); break; default: break; } } catch (Exception) { context.Response.Write("success"); return; } context.Response.Write("success"); return; }
public void ProcessRequest(HttpContext context) { try { string[] path = context.Request.Path.Split(new char[1] { '/' }); string className = path[2].Trim(); string methodName = path[3].Trim(); System.IO.StreamReader stream = new System.IO.StreamReader(context.Request.InputStream, Encoding.UTF8); string postData = stream.ReadToEnd(); stream.Close(); ////写入日志 JobLogs.Writer(log_Folder, "POST数据:" + postData); //认证请求 if (!IsAuthentication(context, className, methodName)) { throw new PMSException("认证失败"); } Type t = Type.GetType("PMS.api." + className); object instance = Activator.CreateInstance(t); MethodInfo methodInfo = t.GetMethod(methodName); if (instance == null || methodInfo == null) { throw new PMSException("api不存在"); } methodInfo.Invoke(instance, new object[] { context, context.Server.UrlDecode(postData) }); } catch (PMSException ex) { int errCode = (int)ex.ReCode; string message = string.Empty; if (ex.ReCode == PMSCode.ERROR) { message = ex.Message; //直接输出消息 } else { message = ex.ReCode.ToString(); } Hashtable ht = new Hashtable(); ht.Add("code", errCode); ht.Add("message", message); string json = LitJson.JsonMapper.ToJson(ht); PMSResponse.WirterString(json); } catch (Exception ex) { PMSException ex_ie = ex.InnerException as PMSException; int errCode = 0; string message = string.Empty; if (ex_ie != null) //如果是自定义异常抛出 { errCode = (int)ex_ie.ReCode; if (ex_ie.ReCode == PMSCode.ERROR) { message = ex_ie.Message; //直接输出消息 } else { message = PMSResponse.GetEnumDesc(ex_ie.ReCode); } } else { errCode = -1; message = "系统异常," + ex.Message; } Hashtable ht = new Hashtable(); ht.Add("code", errCode); ht.Add("message", message); string json = LitJson.JsonMapper.ToJson(ht); PMSResponse.WirterString(json); } }
public void ProcessRequest(HttpContext context) { try { JobLogs.Writer(log_Folder, "------------------- 分割线 -------------------"); ////写入日志 string url = context.Request.Url.ToString(); JobLogs.Writer(log_Folder, "消息与事件URL:" + url); if (context.Request.HttpMethod == "POST") { } else { Valid(context); return; } // wx.zidinn.com/api/$APPID$/callback string[] path = context.Request.Path.Split(new char[1] { '/' }); if (path.Length < 3) { return; } string timestamp = context.Request.QueryString["timestamp"]; //时间戳 string nonce = context.Request.QueryString["nonce"]; //随机数 string encrypt_type = context.Request.QueryString["encrypt_type"]; //加密类型,为aes string msg_signature = context.Request.QueryString["msg_signature"]; //消息体签名,用于验证消息体的正确性 string appid = path[2].Trim(); string className = "Callback"; string methodName = "Analysis"; //认证请求 if (!IsAuthentication(context, className, methodName)) { throw new APIException("认证失败"); } WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sAppID); System.IO.StreamReader stream = new System.IO.StreamReader(context.Request.InputStream, Encoding.UTF8); string postData = stream.ReadToEnd(); stream.Close(); ////写入日志 JobLogs.Writer(log_Folder, "appid:" + appid); JobLogs.Writer(log_Folder, "消息与事件postData:" + postData); string original_text = ""; int ret = wxcpt.DecryptMsg(msg_signature, timestamp, nonce, postData, ref original_text); if (original_text == "") { JobLogs.Writer(log_Folder, "---------------------------------------消息与事件解密失败" + ret + "---------------------------------------"); context.Response.Write("error"); return; } JobLogs.Writer(log_Folder, "消息与事件解密结果:" + original_text); Callback cb = new Callback(); string msg = cb.Analysis(context, original_text, appid); JobLogs.Writer(log_Folder, "返回结果:" + msg); string en_msg = "";//加密消息 if (msg != "" && msg != "error") { ret = wxcpt.EncryptMsg(msg, timestamp, nonce, ref en_msg); if (en_msg == "") { JobLogs.Writer(log_Folder, "++++++++++++++++++++++++++++++++++++++消息与事件加密失败" + ret + "++++++++++++++++++++++++++++++++++++++"); } } JobLogs.Writer(log_Folder, "返回结果(加密):" + en_msg); context.Response.Write(en_msg); return; } catch (APIException ex) { int errCode = (int)ex.ReCode; string message = string.Empty; if (ex.ReCode == APICode.ERROR) { message = ex.Message; //直接输出消息 } else { message = ex.ReCode.ToString(); } Hashtable ht = new Hashtable(); ht.Add("code", errCode); ht.Add("message", message); string json = LitJson.JsonMapper.ToJson(ht); APIResponse.WirterString(json); } catch (Exception ex) { APIException apiex = ex.InnerException as APIException; int errCode = 0; string message = string.Empty; if (apiex != null) //如果是自定义异常抛出 { errCode = (int)apiex.ReCode; if (apiex.ReCode == APICode.ERROR) { message = apiex.Message; //直接输出消息 } else { message = APIResponse.GetEnumDesc(apiex.ReCode); } } else { errCode = -1; message = "系统异常,已记录日志!"; //系统异常写入日志 // Log4J.Error("webapi 系统异常", ex); } Hashtable ht = new Hashtable(); ht.Add("code", errCode); ht.Add("message", message); string json = LitJson.JsonMapper.ToJson(ht); APIResponse.WirterString(json); } }