User-Profile-Image
hankin
  • 5
  • 首页
  • 留言
  • 仓库
  • 云端
  • 分类
    • 随笔
    • 安卓逆向
    • php
    • node.js
    • C#
  • 页面
    • 个人技术栈
    • 留言
  • 友链
    • 沉沦云API
    • 沉沦云端
    • SinKingMusic
    • 美和易思刷课
    • 神奇的七云
    • khaos编程小站
    • 小九实验室
    • 一叶三秋
    • 青年的故事
    • :李白云博客
    • 噜阿噜-资源站
    • 小k
Help?

Please contact us on our email for need any support

Support
    首页   ›   C#   ›   正文
C#

c#模拟QQ空间访问

2020-05-08 21:53:06
207302  1109 19

这是在开发QQ访客加速软件写的核心操作功能类,现在贡献出来,并且也为以后的开发提供示例!以下是核心协议及功能代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Collections.Specialized;
using System.Text.RegularExpressions;

namespace QzoneSpeed
{
    class Qzone
    {
        private string uin;

        private string skey;

        private string pskey;

        private string cookie;
        public Qzone() { 
        }
        public Qzone(string uin, string skey, string pskey)
        {
            this.uin = uin;
            this.skey = skey;
            this.pskey = pskey;
            this.cookie = this.cookies();
        }
        //获取cookie
        private string cookies()
        {
            string res;
            if (this.pskey == "")
            {
                res = "pt2gguin=o" + this.uin + "; uin=o0" + this.uin + "; skey=" + this.skey + ";";
            }
            else
            {
                res = "pt2gguin=o" + this.uin + "; uin=o" + this.uin + "; skey=" + this.skey + ";p_skey=" + this.pskey + "; p_uin=o" + this.uin + ";";
            }
            return res.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
        }
        //获取gtk
        public string GetGTK(string sKey)
        {
            if (skey=="")
            {
                return "";
            }
            var hash = 5381;
            for (int i = 0, len = sKey.Length; i < len; ++i)
            {
                hash += (hash << 5) + sKey[i];
            }
            return (hash & 0x7fffffff).ToString();
        }
        //设置header
        public static void SetHeaderValue(WebHeaderCollection header, string name, string value)
        {
            var property = typeof(WebHeaderCollection).GetProperty("InnerCollection",
                System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            if (property != null)
            {
                var collection = property.GetValue(header, null) as NameValueCollection;
                collection[name] = value;
            }
        }
        //发送HTTP请求
        public string http(string url, string post = "", string referer = "1", string cookie = "0", string header = "0", string ua = "0", string nobaody = "0")
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                if (!header.Equals("0"))
                {
                    string[] headers = header.Split('|');
                    for (int i = 0; i < headers.Length; i++)
                    {
                        SetHeaderValue(request.Headers, headers[i].Split(':')[0], headers[i].Split(':')[1]);
                    }
                }

                if (!post.Equals(""))
                {
                    request.Method = "POST";
                }
                else
                {
                    request.Method = "GET";
                    request.Proxy = null;
                    request.KeepAlive = false;
                    request.AutomaticDecompression = DecompressionMethods.GZip;
                }

                if (!referer.Equals("1"))
                {
                    request.Referer = referer;
                }
                else
                {
                    request.Referer = "http://h5.qzone.qq.com/mqzone/index";
                }
                if (ua.Equals("0"))
                {
                    request.UserAgent = "Mozilla/5.0 (Linux; U; Android 4.4.1; zh-cn) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.5 Mobile Safari/533.1";
                }
                else
                {
                    request.UserAgent = ua;
                }
                if (!cookie.Equals("0"))
                {
                    request.Headers.Add("Cookie", cookie);
                }
                if (!post.Equals(""))
                {
                    byte[] data = Encoding.UTF8.GetBytes(post);
                    request.ContentLength = data.Length;
                    Stream newStream = request.GetRequestStream();
                    newStream.Write(data, 0, data.Length);
                    newStream.Close();
                }
                request.Accept = "application/json";
                SetHeaderValue(request.Headers, "Accept-Encoding", "gzip,deflate,sdch");
                SetHeaderValue(request.Headers, "Accept-Language", "zh-CN,zh;q=0.8");
                SetHeaderValue(request.Headers, "Connection", "close");
                HttpWebResponse myResponse = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
                string content = reader.ReadToEnd();
                return content;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        //获取字符串间内容
        public string GetText(string t, string k, string j)
        {
            try //异常捕捉
            {
                var kn = t.IndexOf(k, StringComparison.Ordinal) + k.Length;
                var jn = t.IndexOf(j, kn, StringComparison.Ordinal);
                return t.Substring(kn, jn - kn);
            }
            catch
            {
                return "fail"; //返回错误
            }
        }
        //访客加速操作(mobile)
        public bool Visitor(string qq)
        {
            string url = "https://h5.qzone.qq.com/webapp/json/friendSetting/reportSpaceVisitor?qzonetoken=qzonetoken&g_tk=" + this.GetGTK(this.pskey) + "&uin=" + qq + "&visitUin=" + this.uin;
            string post = "g_tk=" + this.GetGTK(this.pskey) + "&uin=" + qq + "&visitUin=" + this.uin;
            string res = this.http(url, post, "1", this.cookie);
            return res == "{\"ret\":0,\"msg\":\"\",\"data\":{\"retCode\":0}}";
        }
        //获取今日访客数
        public string TodayVisitorCount(string qq)
        {
            string url = "https://mobile.qzone.qq.com/mqz_get_visitor?g_tk=" + this.GetGTK(this.skey) + "&res_mode=0&res_uin=" + qq + "&offset=0&count=1&page=1&format=json&t=1562141624588";
            string res = this.http(url, "", "1", this.cookie);
            res = GetText(res, ",\"todaycount\":", ",\"totalcount\"");
            string nums = res == "fail" ? "0" : res;
            return nums;
        }
        //获取qzonetoken
        public string GetQzoneToken()
        {
            string url = "https://h5.qzone.qq.com/mqzone/index";
            string ua = "Mozilla/5.0 (Linux; U; Android 4.4.1; zh-cn) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.5 Mobile Safari/533.1";
            string res = this.http(url, "", "1", this.cookie, "0", ua);
            res = GetText(res, "(function(){ try{return \"", "\";}");
            return res;
        }
    }
}

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
  101. 101
  102. 102
  103. 103
  104. 104
  105. 105
  106. 106
  107. 107
  108. 108
  109. 109
  110. 110
  111. 111
  112. 112
  113. 113
  114. 114
  115. 115
  116. 116
  117. 117
  118. 118
  119. 119
  120. 120
  121. 121
  122. 122
  123. 123
  124. 124
  125. 125
  126. 126
  127. 127
  128. 128
  129. 129
  130. 130
  131. 131
  132. 132
  133. 133
  134. 134
  135. 135
  136. 136
  137. 137
  138. 138
  139. 139
  140. 140
  141. 141
  142. 142
  143. 143
  144. 144
  145. 145
  146. 146
  147. 147
  148. 148
  149. 149
  150. 150
  151. 151
  152. 152
  153. 153
  154. 154
  155. 155
  156. 156
  157. 157
  158. 158
  159. 159
  160. 160
  161. 161
  162. 162
  163. 163
  164. 164
  165. 165
  166. 166
  167. 167
  168. 168
  169. 169
  170. 170
  171. 171
  172. 172
  173. 173
  174. 174
  175. 175
  176. 176
  177. 177
  178. 178
  179. 179
  180. 180
  181. 181

如本文“对您有用”,欢迎随意打赏作者,让我们坚持创作!

19 打赏
评论 (4,721)

回复给 点击这里取消回复。

欢迎您 游客  

  • https://honda-fit.ru/forums/index.php?autocom=gallery&req=si&img=7075

    1个月前
    回复
  • http://wish-club.ru/forums/index.php?autocom=gallery&req=si&img=5247

    1个月前
    回复
  • https://honda-fit.ru/forums/index.php?autocom=gallery&req=si&img=7054

    1个月前
    回复
  • https://myteana.ru/forums/index.php?autocom=gallery&req=si&img=6630

    1个月前
    回复
  • https://hrv-club.ru/forums/index.php?autocom=gallery&req=si&img=6890

    1个月前
    回复
  • http://toyota-porte.ru/forums/index.php?autocom=gallery&req=si&img=3238

    1个月前
    回复
  • https://hrv-club.ru/forums/index.php?autocom=gallery&req=si&img=6884

    1个月前
    回复
  • http://terios2.ru/forums/index.php?autocom=gallery&req=si&img=4549

    1个月前
    回复
  • https://vitz.ru/forums/index.php?autocom=gallery&req=si&img=4813

    1个月前
    回复
  • http://toyota-porte.ru/forums/index.php?autocom=gallery&req=si&img=3402

    1个月前
    回复
  • http://fabnews.ru/blog/8434.html

    1个月前
    回复
  • https://cr-v.su/forums/index.php?autocom=gallery&req=si&img=4017

    1个月前
    回复
  • https://mazda-demio.ru/forums/index.php?autocom=gallery&req=si&img=6620

    1个月前
    回复
  • https://myteana.ru/forums/index.php?autocom=gallery&req=si&img=6875

    1个月前
    回复
  • https://myteana.ru/forums/index.php?autocom=gallery&req=si&img=6913

    1个月前
    回复
  • https://myteana.ru/forums/index.php?autocom=gallery&req=si&img=6915

    1个月前
    回复
  • https://hrv-club.ru/forums/index.php?autocom=gallery&req=si&img=7170

    1个月前
    回复
  • http://passo.su/forums/index.php?autocom=gallery&req=si&img=4330

    1个月前
    回复
  • https://hrv-club.ru/forums/index.php?autocom=gallery&req=si&img=7150

    1个月前
    回复
  • http://wish-club.ru/forums/index.php?autocom=gallery&req=si&img=5499

    1个月前
    回复
  • http://terios2.ru/forums/index.php?autocom=gallery&req=si&img=4819

    1个月前
    回复
  • http://wish-club.ru/forums/index.php?autocom=gallery&req=si&img=5485

    1个月前
    回复
  • https://hrv-club.ru/forums/index.php?autocom=gallery&req=si&img=7164

    1个月前
    回复
  • http://toyota-porte.ru/forums/index.php?autocom=gallery&req=si&img=3383

    1个月前
    回复
  • https://myteana.ru/forums/index.php?autocom=gallery&req=si&img=6863

    1个月前
    回复
  • https://honda-fit.ru/forums/index.php?autocom=gallery&req=si&img=7251

    1个月前
    回复
  • https://vitz.ru/forums/index.php?autocom=gallery&req=si&img=5054

    1个月前
    回复
  • https://honda-fit.ru/forums/index.php?autocom=gallery&req=si&img=7268

    1个月前
    回复
  • http://terios2.ru/forums/index.php?autocom=gallery&req=si&img=4793

    1个月前
    回复
  • https://myteana.ru/forums/index.php?autocom=gallery&req=si&img=6854

    1个月前
    回复
1 … 147 148 149 150 151 … 158
流逝中沉沦
12文章 50951评论 1470点赞 4375059浏览

随机文章
YY模拟操作
5年前
QQ全套扫码加速
5年前
c#音乐解析组件(dll)
5年前
SinKingMusic免费开放使用
5年前
QQWeb登陆P值算法
5年前
最新评论
+376
网站留言
Copyright © 2025 网站备案号: 皖ICP备18022767号-3
沉沦云网络. SinKingCloud
主页
页面
  • 个人技术栈
  • 留言
博主
流逝中沉沦
流逝中沉沦 管理员
一个热爱生活热爱技术的00后少年
12 文章 50951 评论 4375059 浏览
测试
测试

主题风格 设置选项


布局
背景颜色
背景渐变
背景图片
微信 QQ空间 QQ好友 新浪微博

“扫一扫”分享到微信

赞赏作者

请通过微信、支付宝 APP 扫一扫

感谢您对作者的支持!

 支付宝 微信支付