/// <summary> /// 异步 开始事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void worker_DoWork(object sender, DoWorkEventArgs e) { //需要执行的代码 worker.ReportProgress(1, "开始导入代理商佣金...\r\n"); worker.ReportProgress(3, "开始导入代理商...\r\n"); //导入代理商 AgentDao agentDao = new AgentDao(); for (int i = 0; i < dgAgent.RowCount; i++) { Agent agent = new Agent(); agent.agentNo = dgAgent[0, i].Value.ToString(); agent.agentName = dgAgent[1, i].Value.ToString(); agent.contactEmail = dgAgent[2, i].Value.ToString(); agent.contactName = dgAgent[3, i].Value.ToString(); agent.contactTel = dgAgent[4, i].Value.ToString(); agent.contactWechatAccount = dgAgent[5, i].Value.ToString(); agent.status = dgAgent[6, i].Value.ToString(); agentDao.Delete(agent.agentNo); agentDao.Add(agent); } worker.ReportProgress(4, "导入代理商完成...\r\n"); //MessageBox.Show("数据上传完毕"); }
/// <summary> /// 异步 开始事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void worker_DoWork(object sender, DoWorkEventArgs e) { //需要执行的代码 worker.ReportProgress(3, "开始导入支付记录...\r\n"); //导入代理商 InvoicePaymentDao agentInvoicePaymentDao = new InvoicePaymentDao(); AgentDao agentDao = new AgentDao(); WechatAction wechatAction = new WechatAction(); for (int i = 0; i < dgInvoicePayment.RowCount; i++) { InvoicePayment agentInvoicePayment = new InvoicePayment(); agentInvoicePayment.month = dgInvoicePayment[0, i].Value.ToString(); agentInvoicePayment.receivedTime = dgInvoicePayment[1, i].Value.ToString(); agentInvoicePayment.processTime = dgInvoicePayment[2, i].Value.ToString(); agentInvoicePayment.agentNo = dgInvoicePayment[3, i].Value.ToString(); agentInvoicePayment.agentName = dgInvoicePayment[4, i].Value.ToString(); agentInvoicePayment.content = dgInvoicePayment[5, i].Value.ToString(); agentInvoicePayment.invoiceFee = dgInvoicePayment[6, i].Value.ToString(); agentInvoicePayment.invoiceType = dgInvoicePayment[7, i].Value.ToString(); agentInvoicePayment.invoiceNo = dgInvoicePayment[8, i].Value.ToString(); agentInvoicePayment.payStatus = dgInvoicePayment[9, i].Value.ToString(); agentInvoicePaymentDao.Delete(agentInvoicePayment); agentInvoicePaymentDao.Add(agentInvoicePayment); dgInvoicePayment["result", i].Value = "导入成功"; } worker.ReportProgress(4, "导入支付记录完成...\r\n"); wechatAction.sendTextMessageToWechat("@all", "结算支付信息已发布,请通过底部菜单查询结算支付详情", Settings.Default.Wechat_Secret, MyConstant.APP_Payment); //MessageBox.Show("数据上传完毕"); }
/// <summary> /// 处理企业号的信息 /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { logger.Info(context.Request.Url.AbsoluteUri); string sToken = "BusinessPolicyHandler"; string sCorpID = Properties.Settings.Default.Wechat_CorpId;// "wx4fe8b74e01fffcbb"; string sEncodingAESKey = "3jJb1Xr7z6fF7LJPCESk8wX8XFf8E6mK4MYIbiOY8yt";// "omiSDTqK4GjKmsQ6eCJSWpOtmqPcz6A3B41RBcg6Ey9"; // string sToken = Properties.Settings.Default.Wechat_AgentFee_Token;//"AgentFee"; // string sCorpID = Properties.Settings.Default.Wechat_CorpId;// "wx31204de5a3ae758e"; // string sEncodingAESKey = Properties.Settings.Default.Wechat_AgentFee_EncodingAESKey;// "he8dYrZ5gLbDrDhfHVJkea1AfmHgRZQJq47kuKpQrSO"; 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); // 需要发送的明文 String actionType = wechatMessage.EventKey; 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_Notice; 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 { } } // string sRespData = "<MsgId>1234567890123456</MsgId>"; logger.Info("EventKey: " + wechatMessage.EventKey); String agentNo = wechatMessage.FromUserName; AgentDao agentDao = new AgentDao(); Agent agent = agentDao.Get(agentNo); if (agent != null && !String.IsNullOrEmpty(agent.status) && agent.status.Equals("Y")) { sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "对不起,你的账号已被停用,请联系联通工作人员!\n\n"); } else { PolicyDao policyDao = new ChinaUnion_DataAccess.PolicyDao(); switch (actionType) { case "LatestPolicy": case "HistoryPolicy": case "LatestNotice": case "HistoryNotice": IList<Policy> policyList =null; if (actionType.Equals("LatestNotice")) { policyList = policyDao.GetAllList(""); } else { policyList = policyDao.GetAllList(""); } if (policyList != null && policyList.Count > 0) { sb.Append(this.createNewsMessages(wechatMessage.FromUserName, policyList)); } else { sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "没有公告发布!\n\n"); } break; default: break; } } // 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); }
/// <summary> /// 异步 开始事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void worker_DoWork(object sender, DoWorkEventArgs e) { //需要执行的代码 worker.ReportProgress(3, "开始导入发票信息...\r\n"); //导入代理商 WechatAction wechatAction = new WechatAction(); AgentInvoiceDao agentInvoiceDao = new AgentInvoiceDao(); AgentDao agentDao = new AgentDao(); for (int i = 0; i < dgInvoice.RowCount; i++) { AgentInvoice agentInvoice = new AgentInvoice(); agentInvoice.invoiceMonth = dgInvoice[0, i].Value.ToString(); agentInvoice.invoiceDate = DateTime.Parse( dgInvoice[1, i].Value.ToString()).ToString("yyyy-MM-dd"); agentInvoice.agentNo = dgInvoice[2, i].Value.ToString(); agentInvoice.agentName = dgInvoice[3, i].Value.ToString(); agentInvoice.invoiceContent = dgInvoice[4, i].Value.ToString(); agentInvoice.invoiceFee = dgInvoice[5, i].Value.ToString(); agentInvoice.invoiceType = dgInvoice[6, i].Value.ToString(); agentInvoice.invoiceNo = dgInvoice[7, i].Value.ToString(); agentInvoice.comment = dgInvoice[8, i].Value.ToString(); Agent agent = agentDao.Get(agentInvoice.agentNo); if (agent != null && !String.IsNullOrEmpty(agent.agentName)) { agentInvoiceDao.Delete(agentInvoice); agentInvoiceDao.Add(agentInvoice); dgInvoice["result", i].Value = "导入成功"; String message = String.Format(Settings.Default.Invoice_Wechat_Message, agentInvoice.invoiceDate, agentInvoice.invoiceContent, agentInvoice.invoiceFee, agentInvoice.invoiceType, agentInvoice.invoiceNo,agentInvoice.comment); wechatAction.sendTextMessageToWechat(agentInvoice.agentNo, message, Settings.Default.Wechat_Secret, Settings.Default.Wechar_Invoice_AppId); } else { dgInvoice["result", i].Value = "导入失败,代理商编号:" + agentInvoice.agentNo+"不存在,请先导入代理商."; } } //dgInvoice.AutoResizeColumns(); worker.ReportProgress(4, "导入发票信息完成...\r\n"); //MessageBox.Show("数据上传完毕"); }
private void prepareGrid(string agentNo) { this.Cursor = Cursors.WaitCursor; AgentDao agentDao = new AgentDao(); Agent agent = null; IList<Agent> agentList = new List<Agent>(); if (!string.IsNullOrEmpty(agentNo)) { agent = agentDao.Get(agentNo); if (agent != null) { agentList.Add(agent); } } else { agentList = agentDao.GetList(); } if (agentList != null && agentList.Count > 0) { this.grpAgentList.Text = "代理商列表(" + agentList.Count+")"; dgAgent.Rows.Clear(); dgAgent.Columns.Clear(); dgAgent.Columns.Add("代理商编号", "代理商编号"); dgAgent.Columns.Add("代理商名称", "代理商名称"); dgAgent.Columns.Add("联系人邮箱", "联系人邮箱"); dgAgent.Columns.Add("联系人电话", "联系人电话"); dgAgent.Columns.Add("联系人微信", "联系人微信"); dgAgent.Columns.Add("账号禁用", "账号禁用"); dgAgent.Columns.Add("微信同步备注", "微信同步备注"); for (int i = 0; i < agentList.Count; i++) { dgAgent.Rows.Add(); DataGridViewRow row = dgAgent.Rows[i]; row.Cells[0].Value = agentList[i].agentNo; row.Cells[1].Value = agentList[i].agentName; row.Cells[2].Value = agentList[i].contactEmail; row.Cells[3].Value = agentList[i].contactTel; row.Cells[4].Value = agentList[i].contactWechatAccount; if (!String.IsNullOrEmpty(agentList[i].status) && agentList[i].status.ToUpper().Equals("Y")) { row.Cells[5].Value = "账号已经停用"; } else { row.Cells[5].Value = ""; } row.Cells[6].Value = ""; } dgAgent.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dgAgent.AutoResizeColumns(); } this.Cursor = Cursors.Default; }
/// <summary> /// 异步 开始事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void worker_DoWork(object sender, DoWorkEventArgs e) { //需要执行的代码 worker.ReportProgress(3, "开始导入支付记录...\r\n"); //导入代理商 AgentInvoicePaymentDao agentInvoicePaymentDao = new AgentInvoicePaymentDao(); AgentDao agentDao = new AgentDao(); WechatAction wechatAction = new WechatAction(); for (int i = 0; i < dgInvoicePayment.RowCount; i++) { AgentInvoicePayment agentInvoicePayment = new AgentInvoicePayment(); agentInvoicePayment.agentNo = dgInvoicePayment[0, i].Value.ToString(); agentInvoicePayment.agentName = dgInvoicePayment[1, i].Value.ToString(); agentInvoicePayment.processTime = dgInvoicePayment[2, i].Value.ToString(); agentInvoicePayment.invoiceFee = dgInvoicePayment[3, i].Value.ToString(); agentInvoicePayment.payFee = dgInvoicePayment[4, i].Value.ToString(); agentInvoicePayment.summary = dgInvoicePayment[5, i].Value.ToString(); agentInvoicePayment.payStatus = dgInvoicePayment[6, i].Value.ToString(); Agent agent = agentDao.Get(agentInvoicePayment.agentNo); if (agent != null && !String.IsNullOrEmpty(agent.agentName)) { agentInvoicePaymentDao.Delete(agentInvoicePayment); agentInvoicePaymentDao.Add(agentInvoicePayment); dgInvoicePayment["result", i].Value = "导入成功"; String message = String.Format(Settings.Default.InvoicePayment_Wechat_Message, agentInvoicePayment.processTime, agentInvoicePayment.invoiceFee, agentInvoicePayment.payFee, agentInvoicePayment.summary, agentInvoicePayment.payStatus); wechatAction.sendTextMessageToWechat(agentInvoicePayment.agentNo, message, Settings.Default.Wechat_Secret, Settings.Default.Wechar_Invoice_AppId); } else { dgInvoicePayment["result", i].Value = "导入失败,代理商编号:" + agentInvoicePayment.agentNo + "不存在,请先导入代理商."; } } worker.ReportProgress(4, "导入支付记录完成...\r\n"); //MessageBox.Show("数据上传完毕"); }