private void Button3_Click(object sender, EventArgs e) { string toUser = textBox3.Text; string toMsg = textBox2.Text; MsgData data = new MsgData(); BaseRequest baseRequest = new BaseRequest(); baseRequest.Sid = wxsid; baseRequest.Uin = wxuin; baseRequest.Skey = skey; data.BaseRequest = baseRequest; string at = textBox5.Text; Msg _msg = new Msg(); _msg.Type = 1; _msg.Content = (string.IsNullOrEmpty(at)?"":at + " ") + toMsg; _msg.FromUserName = user_name; _msg.ToUserName = toUser; data.Msg = _msg; int times = int.Parse(textBox4.Text); Task task = Task.Run(() => { int i = 0; while (i < times) { i++; if (checkBox1.Checked) { int _d = DateTime.Now.Millisecond; Random r = new Random(_d); data.Msg.Content = (string.IsNullOrEmpty(at) ? "" : at + " ") + keyValuePairs[r.Next(1, keyValuePairs.Count)]; } if (checkBox2.Checked) { i = 0; } WechatHttpClient <MsgResponse, MsgRequest> wechatHttpClient = new WechatHttpClient <MsgResponse, MsgRequest>(new MsgRequest(pass_ticket, data)); MsgResponse response = wechatHttpClient.DoPost(); BeginInvoke(new update_textbox(update_text), JsonConvert.SerializeObject(response)); BeginInvoke(new update_textbox(lable_text), i.ToString()); Thread.Sleep(500); } }); }
static void postQueryJson(QueryViewModel viewModel, string url, string type) { InvoiceQuery query = new InvoiceQuery(); query.invoiceReqSerialNo = viewModel.InvoiceReqSerialNo; query.taxpayerNum = viewModel.TaxpayerNum; string content = JsonHelper.Object2String <InvoiceQuery>(query).Replace("\\", ""); mLogger.Info("查询发票业务内容JSON串"); Task.Factory.StartNew(() => { MsgResponse rsp = mApi.PostQueryJson(url, content); Console.WriteLine(rsp.msg); if (OnHttpPost != null) { OnHttpPost(type + "发票查询" + rsp.msg); } //if (OnQueryHttpPost != null) //{ // OnQueryHttpPost(type + "发票查询", rsp.code); //} if (rsp.code == "0000") { viewModel.Code = rsp.QueryContent.code == "0000" ? "开票成功" : rsp.QueryContent.code == "9999" ? "开票中" : "失败"; viewModel.InvoiceDate = rsp.QueryContent.invoiceDate; viewModel.InvoiceType = rsp.QueryContent.invoiceType == "1" ? "蓝票" : "红票"; viewModel.TradeNo = rsp.QueryContent.tradeNo; viewModel.InvoiceNo = rsp.QueryContent.invoiceNo; viewModel.DownloadUrl = rsp.QueryContent.downloadUrl; } else { viewModel.Code = "空"; viewModel.InvoiceDate = "0000-00-00"; viewModel.InvoiceType = "空"; viewModel.TradeNo = "空"; viewModel.InvoiceNo = "空"; viewModel.DownloadUrl = "空"; } }); }
public async Task <MsgResponse> SendToGroup(MessageVM message) { MainLibrary core = new MainLibrary(); DomainLibrary.Models.MessageDataModel m = new DomainLibrary.Models.MessageDataModel { SenderName = message.SenderName, GroupName = message.GroupName, Content = message.Content, MessageDT = DateTime.Now, id = message.GroupName + DateTime.Now.ToString("yyyyMMddhhMIss") }; var msg = await core.SendMessageToGroupAsync(_repo, m); var response = new MsgResponse { Message = msg }; return(response); }
public void DownLoadFile(string fileNo) { Msg request = new Msg { RequestType = 5, FileNo = fileNo }; MsgResponse response = WeChatHelper.PostService <Msg, MsgResponse>("Msg", request); if (response.DownFile.Length != 0) { Response.Clear(); Response.Buffer = true; string strTemp = HttpUtility.UrlEncode(response.FileName, System.Text.Encoding.UTF8); Response.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", strTemp)); Response.AppendHeader("Content-Length", response.DownFile.Length.ToString(CultureInfo.InvariantCulture)); Response.BinaryWrite(response.DownFile); Response.Flush(); Response.End(); } }
public JsonResult Delete(string ids) { var result = new MsgResponse(); try { var idArr = ids.Split(','); bll.RemoveByIds(idArr); result.Status = true; result.Message = "删除成功"; } catch (Exception ex) { result.Status = false; result.Message = "删除失败 " + ex.Message; } var json = new JsonResult { Data = result }; return(json); }
public IActionResult Post([FromBody] Entrust entrust) { MsgResponse msgResponse = new MsgResponse(); if (entrust != null) { if (entrust.message != "" && entrust.to != "" && entrust.from != "" && entrust.timeToLifeSec > 0) { msgResponse.message = "Hello " + entrust.to + " your message will be send"; return(new OkObjectResult(msgResponse)); } else { msgResponse.message = "Datos Incompletos, Request ERROR "; return(new OkObjectResult(msgResponse)); } } else { var run = " ERROR "; return(new OkObjectResult(run)); } }
public ActionResult Save(GroupModel model) { var result = new MsgResponse(); try { var oldModel = bll.FindOne(p => p.Id == model.Id); if (oldModel != null) { oldModel.Name = model.Name; oldModel.Description = model.Description; bll.Update(oldModel); result.Message = "修改成功"; } else { oldModel = new Group { Id = Guid.NewGuid().ToString(), Name = model.Name, Description = model.Description }; bll.Add(oldModel); result.Message = "保存成功"; } result.Status = true; } catch (Exception ex) { result.Status = false; result.Message = "操作失败 " + ex.Message; } JsonResult json = new JsonResult(); json.Data = result; return(json); }
static void postRedJson(RedViewModel viewModel, string url, string type) { InvoiceRed invoice = new InvoiceRed(); invoice.taxpayerNum = viewModel.TaxpayerNum; invoice.invoiceReqSerialNo = SerialNoHelper.GetInvoiceReqSerialNo(mcPrefix); invoice.amount = viewModel.Amount; invoice.invoiceCode = viewModel.InvoiceCode; invoice.invoiceNo = viewModel.InvoiceNo; invoice.redReason = viewModel.RedReason; string content = JsonHelper.Object2String <InvoiceRed>(invoice).Replace("\\", ""); mLogger.Info("红票业务内容JSON串"); Task.Factory.StartNew(() => { MsgResponse rsp = mApi.PostJson(url, content); if (OnHttpPost != null) { OnHttpPost(type + "红票开票" + rsp.msg); } }); }
/// <summary> /// 根据请求确认是否要加密,处理出消息响应文本 /// </summary> /// <param name="request">推送过来的请求</param> /// <param name="msgResponse">消息响应对象</param> /// <returns>消息响应文本</returns> public string GetResponseText(MsgResponse msgResponse) { if (weChatConfig == null) { throw new NullReferenceException("请使用构造MessageLinkUp(idOrAppId),或初始化Initialize(idOrAppId)"); } //根据MsgResponse生成响应的xml StringBuilder responseXml = new StringBuilder(); responseXml.AppendLine("<xml>"); responseXml.AppendLine($"<ToUserName><![CDATA[{msgResponse.ToUserName}]]></ToUserName>"); responseXml.AppendLine($"<FromUserName><![CDATA[{msgResponse.FromUserName}]]></FromUserName>"); responseXml.AppendLine($"<CreateTime><![CDATA[{msgResponse.CreateTime}]]></CreateTime>"); responseXml.AppendLine($"<MsgType><![CDATA[{msgResponse.MsgType}]]></MsgType>"); msgResponse.MsgType = msgResponse.MsgType?.ToLower(); if ("text".Equals(msgResponse.MsgType) && msgResponse is ContentReplyMsg) { responseXml.AppendLine($"<Content><![CDATA[{((ContentReplyMsg)msgResponse).Content}]]></Content>"); } if ("image".Equals(msgResponse.MsgType) && msgResponse is PictureReplyMsg) { PictureReplyMsg pictureMsg = (PictureReplyMsg)msgResponse; responseXml.AppendLine("<Image>"); if (!string.IsNullOrWhiteSpace(pictureMsg.MediaId)) { responseXml.AppendLine($"<MediaId><![CDATA[{pictureMsg.MediaId}]]></MediaId>"); } else { throw new Exception("图片媒体Id不能为空"); } responseXml.AppendLine("</Image>"); } else if ("voice".Equals(msgResponse.MsgType) && msgResponse is VoiceReplyMsg) { VoiceReplyMsg voiceMsg = (VoiceReplyMsg)msgResponse; responseXml.AppendLine("<Voice>"); if (!string.IsNullOrWhiteSpace(voiceMsg.MediaId)) { responseXml.AppendLine($"<MediaId><![CDATA[{voiceMsg.MediaId}]]></MediaId>"); } else { throw new Exception("语音媒体Id不能为空"); } responseXml.AppendLine("</Voice>"); } else if ("video".Equals(msgResponse.MsgType) && msgResponse is VideoReplyMsg) { VideoReplyMsg videoMsg = (VideoReplyMsg)msgResponse; responseXml.AppendLine("<Video>"); if (!string.IsNullOrWhiteSpace(videoMsg.MediaId)) { responseXml.AppendLine($"<MediaId><![CDATA[{videoMsg.MediaId}]]></MediaId>"); } else { throw new Exception("视频媒体Id不能为空"); } responseXml.AppendLine($"<Title><![CDATA[{videoMsg.Title}]]></Title>"); responseXml.AppendLine($"<Description><![CDATA[{videoMsg.Description}]]></Description>"); responseXml.AppendLine("</Video>"); } else if ("music".Equals(msgResponse.MsgType) && msgResponse is MusicReplyMsg) { MusicReplyMsg musicMsg = (MusicReplyMsg)msgResponse; responseXml.AppendLine("<Music>"); responseXml.AppendLine($"<Title><![CDATA[{musicMsg.Title}]]></Title>"); responseXml.AppendLine($"<Description><![CDATA[{musicMsg.Description}]]></Description>"); responseXml.AppendLine($"<MusicUrl><![CDATA[{musicMsg.MusicUrl}]]></MusicUrl>"); responseXml.AppendLine($"<HQMusicUrl><![CDATA[{musicMsg.HQMusicUrl}]]></HQMusicUrl>"); if (!string.IsNullOrWhiteSpace(musicMsg.ThumbMediaId)) { responseXml.AppendLine($"<ThumbMediaId><![CDATA[{musicMsg.ThumbMediaId}]]></ThumbMediaId>"); } else { throw new Exception("音乐缩略图的媒体id不能为空"); } responseXml.AppendLine("</Music>"); } else if ("news".Equals(msgResponse.MsgType) && msgResponse is NewsReplyMsg) { NewsReplyMsg newsMsg = (NewsReplyMsg)msgResponse; responseXml.AppendLine($"<ArticleCount>{newsMsg.ArticleCount}</ArticleCount>"); responseXml.AppendLine("<Articles>"); int maxCount = Math.Min(newsMsg.ArticleCount, 8); for (int i = 0; i < maxCount; i++) { var msgArticle = newsMsg.Articles[0]; responseXml.AppendLine("<item>"); responseXml.AppendLine($"<Title><![CDATA[{msgArticle.Title}]]></Title>"); responseXml.AppendLine($"<Description><![CDATA[{msgArticle.Description}]]></Description>"); responseXml.AppendLine($"<PicUrl><![CDATA[{msgArticle.PicUrl}]]></PicUrl>"); responseXml.AppendLine($"<PicUrl><![CDATA[{msgArticle.PicUrl}]]></PicUrl>"); responseXml.AppendLine("</item>"); } responseXml.AppendLine("</Articles>"); } responseXml.AppendLine("</xml>"); string xmlText = responseXml.ToString();//消息 if (weChatConfig.EnCrypt) { //消息进行加密处理 xmlText = MessageEncrypt(xmlText); } return(xmlText); }
static void postBlueJson(BlueViewModel viewModel, string url, string type) { InvoiceBlue invoice = new InvoiceBlue(); // 纳税人识别号 invoice.taxpayerNum = viewModel.TaxPayerNum; // 发票请求流水号 invoice.invoiceReqSerialNo = SerialNoHelper.GetInvoiceReqSerialNo(mcPrefix); invoice.buyerName = viewModel.BuyerName; invoice.buyerAddress = viewModel.BuyerAddress; invoice.buyerTel = viewModel.BuyerTel; invoice.buyerBankName = viewModel.BuyerBankName; invoice.buyerBankAccount = viewModel.BuyerBankAccount; invoice.buyerTaxpayerNum = viewModel.TaxPayerNum; invoice.sellerAddress = viewModel.SellerAddress; invoice.sellerBankAccount = viewModel.SellerBankAccount; invoice.sellerBankName = viewModel.SellerBankName; invoice.sellerTel = viewModel.SellerTel; // 纸质蓝票的分机号时必填项 if (type == "纸质") { invoice.extensionNum = "1"; } List <Goods> goodsList = new List <Goods>(); foreach (BlueGoods item in viewModel.BlueGoodses) { // 只添加被选中的项目 if (!item.IsSelected) { continue; } goodsList.Add(new Goods() { goodsName = item.Description, quantity = item.Quantity.ToString(), //quantity ="1.00", unitPrice = item.Price.ToString(), //unitPrice ="56.64", invoiceAmount = item.TransactionAmount.ToString(), // invoiceAmount ="56.64", includeTaxFlag = item.IsIncludeTax?"1":"0", taxRateValue = item.TaxRate.ToString(), // 0税率处理 zeroTaxFlag = item.TaxRate == 0?"1":null, // 税额的计算 taxRateAmount = Convert.ToDouble((item.TaxRateAmount == 0? TaxHelper.GetTaxAmount(item.Quantity, item.Price, item.TaxRate):item.TaxRateAmount)).ToString(), taxClassificationCode = item.TaxClassificationCode, }); } // 项目列表 invoice.itemList = JsonHelper.Object2String <List <Goods> >(goodsList); // 过滤业务内容串 string content = JsonHelper.Object2String <InvoiceBlue>(invoice). Replace("\\", "").Replace("\"[", "[").Replace("]\"", "]"); // 记录业务报文json串到日志中 mLogger.Info("蓝票业务内容JSON串:" + content); Task.Factory.StartNew(() => { MsgResponse rsp = mApi.PostJson(url, content); if (OnHttpPost != null) { OnHttpPost(type + "蓝票开票" + rsp.msg); } }); }