public static MpNewsArticle CreateArticle(string title, string content, int appId, string path) { TkDebug.AssertArgumentNullOrEmpty(path, "path", null); string secret = WeixinSettings.Current.GetCorpSecret(appId); MediaId media = WeCorpUtil.UploadFile(secret, MediaType.Image, path); return(new MpNewsArticle(title, media.Id, content)); }
public MediaId GetWeCorpMediaId(string secret, MediaType type, string path) { DataRow row = TrySelectRowWithKeys(type.ToString(), path); if (row == null) { SetCommands(AdapterCommand.Insert); MediaId mediaId = WeCorpUtil.UploadFile(secret, type, path); row = NewRow(); row.BeginEdit(); row["MediaType"] = type.ToString(); row["MediaKey"] = path; SetMediaRow(row, mediaId); row["CorpSecret"] = secret; row.EndEdit(); UpdateDatabase(); return(mediaId); } else { DateTime validDate = row["ValidDate"].Value <DateTime>(); if (validDate > DateTime.Now) { return(new MediaId(row["MediaId"].ToString())); } else { SetCommands(AdapterCommand.Update); MediaId mediaId = WeCorpUtil.UploadFile(secret, type, path); row.BeginEdit(); SetMediaRow(row, mediaId); row.EndEdit(); UpdateDatabase(); return(mediaId); } } }