protected void Page_Load(object sender, EventArgs e) { Request.ContentEncoding = Encoding.UTF8; string keyword = Request.QueryString["keyword"]; String userId = Request.QueryString["userId"]; logger.Info("keyword=" + keyword); AgentErrorCodeDao agentErrorCodeDao = new AgentErrorCodeDao(); AgentErrorCode agentErrorCode = agentErrorCodeDao.GetByKey(keyword); if (agentErrorCode != null) { agentErrorCodeDao.UpdateQueryCount(agentErrorCode); this.lblKeyword.Text = agentErrorCode.keyword; logger.Info("solution=" + agentErrorCode.solution); this.lblErrorSolution.Text = agentErrorCode.solution.Replace("解决办法", "<br>解决办法").Replace("解决方法", "<br>解决方法"); this.lblErrerDesc.Text = agentErrorCode.errorDesc; this.lblContact.Text = agentErrorCode.contactName.Replace("联系电话", "<br><br>联系电话"); ; String dir = this.Server.MapPath("~/") + @"\ErrorImages\"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } String path = dir + agentErrorCode.seq + ".jpg"; if (!File.Exists(path) || !File.GetCreationTime(path).ToString("yyyy-MM-dd").Equals(DateTime.Now.ToString("yyyy-MM-dd"))) { if (agentErrorCode.errorImg != null) { System.IO.File.WriteAllBytes(path, agentErrorCode.errorImg); } } if (agentErrorCode.errorImg != null) { this.Image1.ImageUrl = "http://" + Properties.Settings.Default.Host + "/Wechat/ErrorImages/" + agentErrorCode.seq + ".jpg"; } WechatQueryLog wechatQueryLog = new ChinaUnion_BO.WechatQueryLog(); wechatQueryLog.agentName = ""; wechatQueryLog.module = Util.MyConstant.module_Error; wechatQueryLog.subSystem = "报错处理"; wechatQueryLog.queryTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); wechatQueryLog.queryString = keyword; wechatQueryLog.wechatId = userId; WechatQueryLogDao wechatQueryLogDao = new WechatQueryLogDao(); try { wechatQueryLogDao.Add(wechatQueryLog); } catch { } } }
private void btnQuery_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; this.dgErrorCode.Rows.Clear(); dgErrorCode.Columns.Clear(); dgErrorCode.Columns.Add("序号", "序号"); dgErrorCode.Columns.Add("子系统", "子系统"); dgErrorCode.Columns.Add("报错关键字", "报错关键字"); dgErrorCode.Columns.Add("报错描述", "报错描述"); DataGridViewImageColumn column = new DataGridViewImageColumn(); column.HeaderText = "出错截图信息"; column.Name = "Image"; //column.Image =System.Drawing.Image.FromFile( "./TestError.png"); dgErrorCode.Columns.Add(column); //dgErrorCode.Columns.Add("出错截图信息", "出错截图信息"); dgErrorCode.Columns.Add("原因及处理方法", "原因及处理方法"); dgErrorCode.Columns.Add("联系方式", "联系方式"); // dgErrorCode.Columns.Add("备注", "备注"); dgErrorCode.Columns.Add("查询次数", "查询次数"); AgentErrorCodeDao agentErrorCodeDao = new AgentErrorCodeDao(); IList<AgentErrorCode> ErrorCodeList = agentErrorCodeDao.GetList(this.txtErrorCode.Text.Trim()); if (ErrorCodeList != null && ErrorCodeList.Count > 0) { for (int i = 0; i < ErrorCodeList.Count; i++) { dgErrorCode.Rows.Add(); DataGridViewRow row = dgErrorCode.Rows[i]; row.Cells[0].Value = (i + 1).ToString(); row.Cells[1].Value = ErrorCodeList[i].module; row.Cells[2].Value = ErrorCodeList[i].keyword; row.Cells[3].Value = ErrorCodeList[i].errorDesc; row.Cells[4].Value = ErrorCodeList[i].errorImg; row.Cells[5].Value = ErrorCodeList[i].solution; row.Cells[6].Value = ErrorCodeList[i].contactName; row.Cells[7].Value = ErrorCodeList[i].queryCount; } this.dgErrorCode.AutoResizeColumns(); this.dgErrorCode.AutoResizeRows(); //dgErrorCode.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True; } this.Cursor = Cursors.Default; }
/// <summary> /// 处理企业号的信息 /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { logger.Info(context.Request.Url.AbsoluteUri); //string sToken = "AgentFee"; //string sCorpID = "wx4fe8b74e01fffcbb"; //string sEncodingAESKey = "gvGJnhpjeljcKzvfe8B8vnmMBBLkJFuzUYSjsGcDQFE"; string sToken = Properties.Settings.Default.Wechat_ErrorCode_Token;// "ErrorCode"; string sCorpID = Properties.Settings.Default.Wechat_CorpId;// "wx31204de5a3ae758e"; string sEncodingAESKey = Properties.Settings.Default.Wechat_ErrorCode_EncodingAESKey;// "VcEu5ijaEa6xVklONE9APWJgfvh1UhGjXGKAdeHWAWQ"; System.Collections.Specialized.NameValueCollection queryStrings = context.Request.QueryString; Tencent.WXBizMsgCrypt wxcpt = new Tencent.WXBizMsgCrypt(sToken, sEncodingAESKey, sCorpID); context.Request.ContentEncoding = Encoding.UTF8; string sReqMsgSig = queryStrings["msg_signature"]; string sReqTimeStamp = queryStrings["timestamp"]; string sReqNonce = queryStrings["nonce"]; // 获取Post请求的密文数据 StreamReader reader = new StreamReader(context.Request.InputStream, Encoding.GetEncoding("UTF-8")); string sReqData = reader.ReadToEnd(); reader.Close(); string sMsg = ""; // 解析之后的明文 int ret = wxcpt.DecryptMsg(sReqMsgSig, sReqTimeStamp, sReqNonce, sReqData, ref sMsg); if (ret != 0) { logger.Info("ERR: Decrypt Fail, ret: " + ret); System.Console.WriteLine("ERR: Decrypt Fail, ret: " + ret); return; } // ret==0表示解密成功,sMsg表示解密之后的明文xml串 XmlDocument doc = new XmlDocument(); doc.LoadXml(sMsg); WechatMessage wechatMessage = new WechatMessage(doc.DocumentElement); StringBuilder sb = new StringBuilder(); sb.AppendFormat("<xml>"); sb.AppendFormat("<ToUserName><![CDATA[{0}]]></ToUserName>", wechatMessage.FromUserName); sb.AppendFormat("<FromUserName><![CDATA[{0}]]></FromUserName>", wechatMessage.ToUserName); sb.AppendFormat("<CreateTime>{0}</CreateTime>", wechatMessage.CreateTime); AgentWechatAccountDao agentWechatAccountDao = new AgentWechatAccountDao(); AgentWechatAccount agentWechatAccount = agentWechatAccountDao.Get(wechatMessage.FromUserName); if (agentWechatAccount != null && wechatMessage != null && !String.IsNullOrEmpty(wechatMessage.Event) && wechatMessage.Event.Equals("enter_agent")) { WechatQueryLog wechatQueryLog = new ChinaUnion_BO.WechatQueryLog(); wechatQueryLog.agentName = ""; wechatQueryLog.module = Util.MyConstant.module_Error; wechatQueryLog.subSystem = "报错处理"; wechatQueryLog.queryTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); wechatQueryLog.queryString = "成员进入应用"; wechatQueryLog.wechatId = agentWechatAccount.contactId; WechatQueryLogDao wechatQueryLogDao = new WechatQueryLogDao(); try { wechatQueryLogDao.Add(wechatQueryLog); } catch { } } try { if (String.IsNullOrEmpty(wechatMessage.Content)) { wechatMessage.Content = "help"; } switch (wechatMessage.Content.ToLower()) { case "help": case "?": case "?": sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "请输入错误关键字查询错误详细说明,例如:输入\"系统异常\"查询包含\"系统异常\"的错误信息"); break; default: AgentErrorCodeDao agentErrorCodeDao = new AgentErrorCodeDao(); int maxArticleCnt = 10; IList<AgentErrorCode> agentErrorCodeList = agentErrorCodeDao.GetList(wechatMessage.Content); if (agentErrorCodeList != null && agentErrorCodeList.Count > 0) { sb.AppendFormat("<MsgType><![CDATA[news]]></MsgType>"); if (agentErrorCodeList.Count > maxArticleCnt) { sb.AppendFormat("<ArticleCount>{0}</ArticleCount>", maxArticleCnt); } else if (agentErrorCodeList.Count <= 10 && agentErrorCodeList.Count > 0) { sb.AppendFormat("<ArticleCount>{0}</ArticleCount>", agentErrorCodeList.Count); } sb.AppendFormat("<Articles>"); int count = 0; foreach (AgentErrorCode agentErrorCode in agentErrorCodeList) { count++; if (count > maxArticleCnt) { break; } String dir = context.Server.MapPath("~/") + @"\ErrorImages\"; logger.Info("Path=" + dir + agentErrorCode.seq + ".jpg"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } String path = dir + agentErrorCode.seq + ".jpg"; if (!File.Exists(path) || !File.GetCreationTime(path).ToString("yyyy-MM-dd").Equals(DateTime.Now.ToString("yyyy-MM-dd"))) { if (agentErrorCode.errorImg != null) { logger.Info("path=" + path); System.IO.File.WriteAllBytes(path, agentErrorCode.errorImg); } else { logger.Info("path=no image"); } } sb.AppendFormat("<item>"); sb.Append("<Title>").AppendFormat("{0}报错查询结果", agentErrorCode.keyword).Append("</Title>"); // String errorCondition = wechatMessage.Content.Substring("error:".Length); StringBuilder sbDesc = new StringBuilder(); //sbDesc.AppendFormat("本月佣金告知单({0})", feeMonth); sbDesc.AppendFormat("问题描述:\n{0}\n\n", agentErrorCode.errorDesc); sbDesc.AppendFormat("处理方法:\n{0}\n\n", agentErrorCode.solution); sbDesc.AppendFormat("联系人员:{0}\n\n", agentErrorCode.contactName); sbDesc.AppendFormat("备注:\n{0}\n", agentErrorCode.comment); sb.Append("<Description>").AppendFormat("<![CDATA[{0}]]>", sbDesc.ToString()).Append("</Description>"); sb.Append("<PicUrl>").AppendFormat("<![CDATA[{0}{1}{2}]]>", "http://"+Properties.Settings.Default.Host+"/Wechat/ErrorImages/", agentErrorCode.seq, ".jpg").Append("</PicUrl>"); //logger.Info("path=" + "http://"http://"+Properties.Settings.Default.Host+"/Wechat/ErrorCodeQuery.aspx?keyword=" + context.Server.UrlEncode(agentErrorCode.keyword)); sb.Append("<Url>").AppendFormat("<![CDATA[{0}{1}{2}]]>", "http://" + Properties.Settings.Default.Host + "/Wechat/ErrorCodeQuery.aspx?keyword=", context.Server.UrlEncode(agentErrorCode.keyword), "&userId=" + wechatMessage.FromUserName).Append("</Url>"); // sb.Append("<Url>").AppendFormat("<![CDATA[{0}]]>", url1).Append("</Url>"); sb.AppendFormat("</item>"); // logger.Info(sb.ToString()); } sb.AppendFormat("</Articles>"); } else { sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "没有找到与" + wechatMessage.Content+"相关的错误详细信息,请更改查询条件或者与联通相关人员确认。"); } break; } } catch (Exception ex) { logger.Info(ex.Message); } // sb.AppendFormat("<AgentID>{0}</AgentID>", textMessage.AgentID); sb.AppendFormat("</xml>"); string sRespData = sb.ToString(); string sEncryptMsg = ""; //xml格式的密文 ret = wxcpt.EncryptMsg(sRespData, sReqTimeStamp, sReqNonce, ref sEncryptMsg); logger.Info("ret=" + ret); if (ret != 0) { System.Console.WriteLine("ERR: EncryptMsg Fail, ret: " + ret); return; } context.Response.Write(sEncryptMsg); // TODO: // 加密成功,企业需要将加密之后的sEncryptMsg返回 // HttpUtils.SetResponse(sEncryptMsg); }
/// <summary> /// 异步 开始事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void worker_DoWork(object sender, DoWorkEventArgs e) { //需要执行的代码 worker.ReportProgress(1, "开始导入错误代码...\r\n"); //导入代理商类型说明 AgentErrorCodeDao agentErrorCodeDao = new AgentErrorCodeDao(); for (int i = 0; i < this.dgErrorCode.RowCount; i++) { AgentErrorCode agentErrorCode = new AgentErrorCode(); agentErrorCode.keyword = dgErrorCode[2, i].Value.ToString(); agentErrorCode.errorDesc = dgErrorCode[4, i].Value.ToString(); byte[] b = new byte[0]; String fullpath = dgErrorCode[3, i].Value.ToString(); if (File.Exists(fullpath)) { FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read); //将图片以文件流的形式进行保存 BinaryReader br = new BinaryReader(fs); byte[] imagebytes = br.ReadBytes((int)fs.Length); //将流读入到字节数组中 fs.Close(); br.Close(); if (imagebytes.Length > 0) { agentErrorCode.errorImg = imagebytes; } } agentErrorCode.solution = dgErrorCode[5, i].Value.ToString(); agentErrorCode.contactName = dgErrorCode[6, i].Value.ToString(); // agentErrorCode.comment = dgErrorCode[5, i].Value.ToString(); agentErrorCode.module = dgErrorCode[1, i].Value.ToString(); if (agentErrorCodeDao.GetByKey(agentErrorCode.keyword) != null) { agentErrorCodeDao.Update(agentErrorCode); } else { //agentErrorCodeDao.Delete(agentErrorCode.keyword); agentErrorCodeDao.Add(agentErrorCode); } } worker.ReportProgress(2, "导入错误代码完成...\r\n"); //MessageBox.Show("数据上传完毕"); }