/// <inheritdoc /> public async Task <ImageResponse> GetImagesAsync(IDownloaderClient client) { if (PostUrl.ToString().IsImagePath()) { return(ImageResponse.FromUrl(PostUrl)); } if (client.Gatherers.SingleOrDefault(x => x.IsFromWebsite(PostUrl)) is IImageGatherer gatherer) { return(await gatherer.FindImagesAsync(client, PostUrl).CAF()); } var result = await client.GetHtmlAsync(() => client.GenerateReq(PostUrl)).CAF(); if (result.IsSuccess) { var img = result.Value.DocumentNode.Descendants("img"); var src = img .Select(x => x.GetAttributeValue("src", null)) .Select(x => { if (Uri.TryCreate(x, UriKind.Absolute, out var uri) || Uri.TryCreate($"https://{PostUrl.Host}{x}", UriKind.Absolute, out uri)) { return(uri); } //How to check if relative to something other than just the host? return(null); }) .Where(x => x != null); if (src.Any()) { return(ImageResponse.FromImages(src)); } } return(ImageResponse.FromNotFound(PostUrl)); }
/// <summary> /// 推送消息 /// </summary> /// <param name="msg"></param> /// <param name="openId"></param> /// <returns></returns> public string SendWeChatMsg(string name, string openId) { var json = "{\"touser\":\"" + openId + "\"," + "\"template_id\":\"b0-aVm0y5Urmbup-cnCykHlYWHiuaGYy9DabB-ePetU\"," + "\"url\":\"http://jifenweixin.shinho.net.cn/#/component/recommendstart\"," + "\"data\":{" + "\"first\": {" + "\"value\":\"您推荐的" + name + "已注册成功,并成功为您增加20积分,点击我的账户可查看积分明细。\"," + "\"color\":\"#173177\"" + "}," + "\"keyword1\":{" + "\"value\":\"推荐同行注册\"," + "\"color\":\"#173177\"" + "}," + "\"keyword2\":{" + "\"value\":\"" + DateTime.Now + "\"," + "\"color\":\"#173177\"" + "}," + "\"remark\":{" + "\"value\":\"点击详情,分享给同行好友一起来赚积分吧\"," + "\"color\":\"#173177\"" + "}" + "}" + "}"; PostUrl.PostJson("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + BasicApi.GetAccessToken(), json); return("success"); }
public async Task <IActionResult> OnGet() { Post = await _blogService.GetPostAsync(PostUrl.GetDate(), PostUrl.Slug); if (Post == null) { return(NotFound()); } Comments = await _blogService.GetCommentsAsync(Post.FileName); await BuildSeeAlsoAsync(Post); return(Page()); }
public string GetRecommendPic(int MemberId = 0) { if (MemberId <= 0) { return("-1"); } string appid = ConfigurationManager.AppSettings["WeiXinAppid"]; string secret = ConfigurationManager.AppSettings["WeiXinSecret"]; string postData = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"A" + MemberId.ToString() + "\"}}}"; string ret = PostUrl.PostJson("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + BasicApi.GetAccessToken(), postData); var result = JsonHelper.JsonToObject <QRcode>(ret); return(result.ticket); }
public void Normalize() { if (PostIntervalMsecs <= 0) { PostIntervalMsecs = CoresConfig.StatMan.DefaultPostIntervalMsecs; } if (SaveIntervalMsecs <= 0) { SaveIntervalMsecs = CoresConfig.StatMan.DefaultSaveIntervalMsecs; } StatFileName = StatFileName._FilledOrDefault(CoresConfig.StatMan.DefaultStatFileName); SystemName = SystemName._FilledOrDefault(CoresConfig.StatMan.DefaultSystemName); LogName = LogName._FilledOrDefault(CoresConfig.StatMan.DefaultLogName); PostUrl = PostUrl._FilledOrDefault(CoresConfig.StatMan.DefaultUrl); }
public string CreateCode_Simple(int activityId = 0) { if (activityId <= 0) { return("-1"); } string appid = System.Configuration.ConfigurationManager.AppSettings["WeiXinAppid"]; string secret = System.Configuration.ConfigurationManager.AppSettings["WeiXinSecret"]; string postData = "{\"action_name\": \"QR_LIMIT_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + activityId + "}}}"; string ret = PostUrl.PostJson("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + BasicApi.GetAccessToken(), postData); var result = JsonHelper.JsonToObject <QRcode>(ret); return(result.ticket); }
public async Task <IActionResult> OnPost() { // Can't use authorization filters on single methods if (User.Identity?.IsAuthenticated != true) { return(Challenge()); } Post = await _blogService.GetPostAsync(PostUrl.GetDate(), PostUrl.Slug); if (Post == null) { return(NotFound()); } if (ModelState.IsValid) { var form = CommentForm; Debug.Assert(form != null, "Model can not be valid with null form"); var id = await _blogService.CreateCommentAsync( Post.FileName, form.ParentId, AuthorName, AuthorEmail, form.Markdown); if (id != null) { CommentForm = null; return(RedirectToPage(nameof(Post), null, null, $"c{id}")); } else { ModelState.AddModelError(string.Empty, "Unable to save comment."); } } // If we got to here, the input is wrong. Comments = await _blogService.GetCommentsAsync(Post.FileName); await BuildSeeAlsoAsync(Post); return(Page()); }
private string ValidateUrl(string defaultValue) { if (string.IsNullOrWhiteSpace(PostUrl)) { return("Post Url must not be empty."); } bool validUrl = Uri.TryCreate(PostUrl, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttps); if (!validUrl) { return("Invalid Url"); } if (!PostUrl.Contains("facebook.com")) { return("Please enter a Facebook post's url"); } return(defaultValue); }
private async Task GetData() { Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); Post = await _postAppService.GetForReadingAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl.Replace("%2F", "/") }); CommentsWithReplies = await _commentAppService.GetHierarchicalListOfPostAsync(Post.Id); CountComments(); }
/// <summary> /// Returns the post url. /// </summary> /// <returns></returns> public override string ToString() => PostUrl.ToString();