• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

asp.net MVC 抓取微信文章数据(正文) - 野码

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

asp.net MVC 抓取微信文章数据(正文)

1.抓微信的正文主要是调用第三方的接口(https://market.aliyun.com/products/56928004/cmapi012134.html)

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace QBSqlServer.GSDataAPIs.GetHtml
{
    public class WeChatPublicNumberQueryAPI
    {
        private const String host = "https://ali-weixin.showapi.com";
        private const String path = "/582-9";
        private const String method = "GET";
        private const String appcode = "你自己的appcode";

        public static Root GetWeChathtml(string title)
        {
            string outhtml = string.Empty;
            string t = System.Web.HttpUtility.UrlEncode(title);
            //String querys = "needComment=0&needContent=1&url=url";
            String querys = "needContent=1&url=" + t;
            String bodys = "";
            String url = host + path;
            HttpWebRequest httpRequest = null;
            HttpWebResponse httpResponse = null;

            if (0 < querys.Length)
            {
                url = url + "?" + querys;
            }

            if (host.Contains("https://"))
            {
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
            }
            else
            {
                httpRequest = (HttpWebRequest)WebRequest.Create(url);
            }
            httpRequest.Method = method;
            httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
            if (0 < bodys.Length)
            {
                byte[] data = Encoding.UTF8.GetBytes(bodys);
                using (Stream stream = httpRequest.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }
            }
            try
            {
                httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            }
            catch (WebException ex)
            {
                httpResponse = (HttpWebResponse)ex.Response;
            }

            Console.WriteLine(httpResponse.StatusCode);
            Console.WriteLine(httpResponse.Method);
            Console.WriteLine(httpResponse.Headers);
            Stream st = httpResponse.GetResponseStream();
            StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
            string strResult = reader.ReadToEnd();
            Root jobInfoList = JsonConvert.DeserializeObject<Root>(strResult);
            Console.WriteLine(reader.ReadToEnd());
            Console.WriteLine("\n");
            return jobInfoList;
        }

        public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            return true;
        }
    }

    public class Showapi_res_body
    {
        /// <summary>
        /// 
        /// </summary>
        public string newUrl { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string date { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string weixinNum { get; set; }
        /// <summary>
        /// 这是正文的html
        /// </summary>
        public string content { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string ret_code { get; set; }
        /// <summary>
        /// 秀场|中国品牌ELLASSAY米兰时装周首秀!
        /// </summary>
        public string title { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string contentImg { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string userLogo { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string oldUrl { get; set; }
        /// <summary>
        /// 徐峰立
        /// </summary>
        public string userName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string read_num { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string like_num { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string userLogo_code { get; set; }
    }

    public class Root
    {
        /// <summary>
        /// 
        /// </summary>
        public string showapi_res_code { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string showapi_res_error { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Showapi_res_body showapi_res_body { get; set; }
    }
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
调试 ASP.NET Core 2.0 源代码发布时间:2022-07-10
下一篇:
ASP.NET MVC 重点教程一周年版 第十回 请求Controller发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap