private static WeChatAppMessage PrepareMessage(string argument) { string[] parts = argument.Split(' '); WeChatAppMessage result = new WeChatAppMessage(); result.Title = GetArgumentByIndex(parts, 0); string fileInfo = GetArgumentByIndex(parts, 1); int fileID = 0; if (int.TryParse(fileInfo, out fileID)) { result.FileID = fileID; } else { result.FileID = WeChatHelper.UploadFile(fileInfo, WeChatRequestContext.Current.LoginInfo).Content; } result.Content = GetArgumentByIndex(parts, 2); result.Author = GetArgumentByIndex(parts, 3); return(result); }
public WeChatUpdateAppMessageExecutor(WeChatAppMessage message, WeChatLoginInfo loginInfo) : base(loginInfo) { message.NullCheck("message"); this.Message = message; }
public override void Execute(string argument) { WeChatAppMessage message = PrepareMessage(argument); WeChatAppMessage responseMessage = WeChatHelper.UpdateAppMessage(message, WeChatRequestContext.Current.LoginInfo); Console.WriteLine(responseMessage.ToString()); }
public static WeChatAppMessage UpdateAppMessage(WeChatAppMessage message, WeChatLoginInfo loginInfo) { WeChatUpdateAppMessageExecutor executor = new WeChatUpdateAppMessageExecutor(message, loginInfo); executor.Execute(); return(executor.ResponseMessage); }
public static WeChatAppMessage UpdateAppMessage(WeChatAppMessage message, WeChatLoginInfo loginInfo) { WeChatUpdateAppMessageExecutor executor = new WeChatUpdateAppMessageExecutor(message, loginInfo); executor.Execute(); return executor.ResponseMessage; }
public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); WeChatAppMessage data = (WeChatAppMessage)obj; dictionary.AddNonDefaultValue("app_id", data.AppMessageID); dictionary.AddNonDefaultValue("file_id", data.FileID); dictionary.AddNonDefaultValue("title", data.Title); dictionary.AddNonDefaultValue("digest", data.Digest); dictionary.AddNonDefaultValue("author", data.Author); dictionary.AddNonDefaultValue("content_url", data.ContentUrl); dictionary.AddNonDefaultValue("img_url", data.ImageUrl); dictionary.AddNonDefaultValue("create_time", data.CreateTime.ToJavascriptDateNumber() / 1000); dictionary.AddNonDefaultValue("show_cover_pic", data.ShowCover ? 1 : 0); return(dictionary); }
protected override void ProcessResponseText(string responseText) { WeChatSendMessageRetInfo result = JSONSerializerExecute.Deserialize <WeChatSendMessageRetInfo>(responseText); if (result.ret != 0) { throw new ApplicationException(result.msg); } if (this.Message.AppMessageID <= 0) { this.ResponseMessage = WeChatHelper.GetAppMessages(this.Message.MessageType, this.LoginInfo).FirstOrDefault(); (this.ResponseMessage != null).FalseThrow("不能找到新保存的素材"); } else { this.ResponseMessage = this.Message; } }
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer) { WeChatAppMessage data = new WeChatAppMessage(); data.AppMessageID = dictionary.GetValue("app_id", 0); data.FileID = dictionary.GetValue("file_id", 0); data.Title = dictionary.GetValue("title", string.Empty); data.Digest = dictionary.GetValue("digest", string.Empty); data.Author = dictionary.GetValue("author", string.Empty); data.ContentUrl = dictionary.GetValue("content_url", string.Empty); data.ImageUrl = dictionary.GetValue("img_url", string.Empty); long createTimeValue = dictionary.GetValue("create_time", 0L) * 1000; data.CreateTime = createTimeValue.JavascriptDateNumberToDateTime().ToLocalTime(); int showCoverValue = dictionary.GetValue("show_cover_pic", 0); data.ShowCover = showCoverValue != 0 ? true : false; return data; }
private static WeChatAppMessage PrepareMessage(string argument) { string[] parts = argument.Split(' '); WeChatAppMessage result = new WeChatAppMessage(); result.Title = GetArgumentByIndex(parts, 0); string fileInfo = GetArgumentByIndex(parts, 1); int fileID = 0; if (int.TryParse(fileInfo, out fileID)) result.FileID = fileID; else result.FileID = WeChatHelper.UploadFile(fileInfo, WeChatRequestContext.Current.LoginInfo).Content; result.Content = GetArgumentByIndex(parts, 2); result.Author = GetArgumentByIndex(parts, 3); return result; }
public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer) { WeChatAppMessage data = new WeChatAppMessage(); data.AppMessageID = dictionary.GetValue("app_id", 0); data.FileID = dictionary.GetValue("file_id", 0); data.Title = dictionary.GetValue("title", string.Empty); data.Digest = dictionary.GetValue("digest", string.Empty); data.Author = dictionary.GetValue("author", string.Empty); data.ContentUrl = dictionary.GetValue("content_url", string.Empty); data.ImageUrl = dictionary.GetValue("img_url", string.Empty); long createTimeValue = dictionary.GetValue("create_time", 0L) * 1000; data.CreateTime = createTimeValue.JavascriptDateNumberToDateTime().ToLocalTime(); int showCoverValue = dictionary.GetValue("show_cover_pic", 0); data.ShowCover = showCoverValue != 0 ? true : false; return(data); }
protected override void ProcessResponseText(string responseText) { WeChatSendMessageRetInfo result = JSONSerializerExecute.Deserialize<WeChatSendMessageRetInfo>(responseText); if (result.ret != 0) throw new ApplicationException(result.msg); if (this.Message.AppMessageID <= 0) { this.ResponseMessage = WeChatHelper.GetAppMessages(this.Message.MessageType, this.LoginInfo).FirstOrDefault(); (this.ResponseMessage != null).FalseThrow("不能找到新保存的素材"); } else this.ResponseMessage = this.Message; }
private void Send() { ProcessProgress.Current.RegisterResponser(SubmitButtonProgressResponser.Instance); if (VerifyInput()) { try { if (ddlAccount.SelectedIndex == 0) { WeChatAppMessage appMessage = null; ProcessProgress.Current.MaxStep = ddlAccount.Items.Count - 1; ProcessProgress.Current.CurrentStep = 0; ProcessProgress.Current.StatusText = ""; ProcessProgress.Current.Response(); foreach (ListItem accountItem in ddlAccount.Items) { try { if (accountItem.Value == "-1") { continue; } appMessage = SendOne(accountItem.Value, ddlGroups.SelectedItem); ProcessProgress.Current.StatusText = string.Format("对帐号 {0} 发送成功!", accountItem.Text); ProcessProgress.Current.Response(); Thread.Sleep(1000); } catch (Exception ex) { //WebUtility.ResponseShowClientErrorScriptBlock(ex); ProcessProgress.Current.StatusText = string.Format("对帐号 {0} 发送失败,原因:{1}", accountItem.Text, ex.Message); ProcessProgress.Current.Response(); Thread.Sleep(2000); } finally { ProcessProgress.Current.Increment(); ProcessProgress.Current.Response(); } } if (appMessage != null) { WeChatAppMessageAdapter.Instance.Update(appMessage); } ProcessProgress.Current.CurrentStep = 0; ProcessProgress.Current.StatusText = ""; ProcessProgress.Current.Response(); } else { ProcessProgress.Current.MaxStep = 1; ProcessProgress.Current.CurrentStep = 0; ProcessProgress.Current.StatusText = ""; ProcessProgress.Current.Response(); var appMessage = SendOne(ddlAccount.SelectedValue, ddlGroups.SelectedItem); WeChatAppMessageAdapter.Instance.Update(appMessage); ProcessProgress.Current.Increment(); ProcessProgress.Current.Response(); } //ClientScript.RegisterStartupScript(this.GetType(), "sendComplete", "alert('发送完毕!');", true); } catch (Exception ex) { WebUtility.ResponseShowClientErrorScriptBlock(ex); } finally { this.Response.Write(SubmitButton.GetResetAllParentButtonsScript(true)); this.Response.End(); } } else { this.Response.Write(SubmitButton.GetResetAllParentButtonsScript(true)); } }
private WeChatAppMessage SendOne(string accountID, ListItem item) { WeChatAppMessage result = null; if (item.Value == "-1") { var account = AccountInfoAdapter.Instance.Load(p => p.AppendItem("AccountID", accountID)).FirstOrDefault(); var loginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password); Thread.Sleep(1000); var uploadedImg = WeChatHelper.UploadFile(imgUploader.ImgProp.FilePath.Decrypt(), loginInfo); //上传图片 Thread.Sleep(1000); WeChatAppMessage message = new WeChatAppMessage(); message.Title = txtTitle.Text; message.Author = txtAuthor.Text; message.Digest = txtDigest.Value; message.FileID = uploadedImg.Content; message.ShowCover = chkShowInContent.Checked; message.Content = editor.InitialData; message.SourceUrl = txtSourceUrl.Text; result = WeChatHelper.UpdateAppMessage(message, loginInfo); //新增图文消息 Thread.Sleep(1000); WeChatHelper.MassSendAppMessage(-1, result.AppMessageID.ToString(), loginInfo); //发送,一天一个帐号只能发送一次 result.Title = message.Title; result.Author = message.Author; result.Digest = message.Digest; result.FileID = message.FileID; result.ShowCover = message.ShowCover; result.Content = message.Content; result.SourceUrl = message.SourceUrl; } else { var weChatGroup = WeChatGroupAdapter.Instance.Load(p => { p.AppendItem("AccountID", accountID); p.AppendItem("Name", item.Text); }).FirstOrDefault(); if (weChatGroup != null) { var account = AccountInfoAdapter.Instance.Load(p => p.AppendItem("AccountID", accountID)).FirstOrDefault(); var loginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password); Thread.Sleep(1000); var uploadedImg = WeChatHelper.UploadFile(imgUploader.ImgProp.FilePath.Decrypt(), loginInfo); //上传图片 Thread.Sleep(1000); WeChatAppMessage message = new WeChatAppMessage(); message.Title = txtTitle.Text; message.Author = txtAuthor.Text; message.Digest = txtDigest.Value; message.FileID = uploadedImg.Content; message.ShowCover = chkShowInContent.Checked; message.Content = editor.InitialData; message.SourceUrl = txtSourceUrl.Text; result = WeChatHelper.UpdateAppMessage(message, loginInfo); //新增图文消息 Thread.Sleep(1000); WeChatHelper.MassSendAppMessage(weChatGroup.GroupID, result.AppMessageID.ToString(), loginInfo); //发送,一天一个帐号只能发送一次 result.Title = message.Title; result.Author = message.Author; result.Digest = message.Digest; result.FileID = message.FileID; result.ShowCover = message.ShowCover; result.Content = message.Content; result.SourceUrl = message.SourceUrl; } } return(result); }