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
207330  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)

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

欢迎您 游客  

  • http://piter.bbcity.ru/viewtopic.php?id=10613#p27864

    1年前
    回复
  • https://taksafonchik.borda.ru/?1-3-0-00013803-000-0-0-1704628453

    1年前
    回复
  • https://vikmarkovci.7bb.ru/viewtopic.php?id=3419#p32341

    1年前
    回复
  • https://sovpl.forum24.ru/?1-9-0-00001812-000-0-0-1706616745

    1年前
    回复
  • https://iftah.spidi.sch.id/index.php/Mp3gid.co

    1年前
    回复
  • https://owlpedia.org/index.php/User:ReginaLoch8658

    1年前
    回复
  • https://vikmarkovci.7bb.ru/viewtopic.php?id=3419#p32341

    1年前
    回复
  • https://andreieusebiu.net/gallery/image/14-%D0%B8%D1%81%D1%82%D0%BE%D1%80%D0%B8%D1%8F-%D0%B0%D1%83%D0%B4%D0%B8%D0%BE%D1%84%D0%BE%D1%80%D0%BC%D0%B0%D1%82%D0%BE%D0%B2-%D0%BE%D1%82-%D0%B2%D0%B8%D0%BD%D0%B8%D0%BB%D0%B0-%D0%B4%D0%BE-%D1%81%D1%82%D1%80%D0%B8%D0%BC%D0%B8%D0%BD%D0%B3%D0%B0/?context=new

    1年前
    回复
  • http://tumgerl.rolbb.me/viewtopic.php?id=11595#p17854

    1年前
    回复
  • https://wiki.hrw-fablab.de/index.php?title=Mp3gid.co

    1年前
    回复
  • http://forum.omnicomm.pro/index.php/topic,16215.0.html

    1年前
    回复
  • https://ai-db.science/wiki/Mp3bit.pw_3

    1年前
    回复
  • http://tr.clanfm.ru/viewtopic.php?f=33&t=8922

    1年前
    回复
  • http://rabotaref.forum-top.ru/viewtopic.php?id=3273#p6737

    1年前
    回复
  • http://forummsk.getbb.ru/viewtopic.php?f=13&t=805

    1年前
    回复
  • https://1wum.ru/forum/?PAGE_NAME=profile_view&UID=35941&MUL_MODE=

    1年前
    回复
  • http://www.tvoidom.galaxyhost.org/forums.php?m=posts&q=31142&n=last#bottom

    1年前
    回复
  • https://incardio.cuas.at/wiki/index.php/Mp3bit.pw

    1年前
    回复
  • Modern Talking был немецким дуэтом, сформированным в 1984 году. Он стал одним из самых ярких представителей евродиско и популярен благодаря своему неповторимому звучанию. Лучшие песни включают “You’re My Heart, You’re My Soul”, “Brother Louie”, “Cheri, Cheri Lady” и “Geronimo’s Cadillac”. Их музыка оставила неизгладимый след в истории поп-музыки, захватывая слушателей своими заразительными мелодиями и запоминающимися текстами. Modern Talking продолжает быть популярным и в наши дни, оставаясь одним из символов эпохи диско. Музыка 2024 года слушать онлайн и скачать бесплатно mp3.

    1年前
    回复
  • https://nowyiforum.listbb.ru/viewtopic.php?f=45&t=8597

    1年前
    回复
  • http://earnmoney.7bb.ru/viewtopic.php?id=6231#p15645

    1年前
    回复
  • http://prosat.ru/modules.html?name=Journal&file=display&jid=18682

    1年前
    回复
  • https://www.buyfags.moe/User:Caroline2230

    1年前
    回复
  • https://www.club4x4.ru/forum/viewtopic.php?f=19&t=95279

    1年前
    回复
  • https://marvelvsdc.faith/wiki/User:BMPMohamed

    1年前
    回复
  • https://nn.7bb.ru/viewtopic.php?id=1156#p6240

    1年前
    回复
  • http://forumsgl.getbb.ru/viewtopic.php?f=23&t=264

    1年前
    回复
  • https://mymoscow.forum24.ru/?1-6-0-00017036-000-0-0-1706615739

    1年前
    回复
  • Мадонна, икона поп-музыки и культурного влияния, продолжает вдохновлять и поражать своей музыкой и стилем. Её карьера олицетворяет смелость, инновации и постоянное стремление к самовыражению. Среди её лучших песен можно выделить “Like a Prayer”, “Vogue”, “Material Girl”, “Into the Groove” и “Hung Up”. Эти треки не только доминировали на музыкальных чартах, но и оставили неизгладимый след в культурной и исторической панораме музыки. Мадонна не только певица, но и икона стиля, актриса и предприниматель, чье влияние простирается далеко за рамки музыкальной индустрии. Скачать mp3 музыку 2024 года и слушать онлайн бесплатно.

    1年前
    回复
  • Mad Hatter

    考屁娃

    5年前
    回复
1 2 3 … 158
流逝中沉沦
12文章 50951评论 1470点赞 4377981浏览

随机文章
c#通过句柄进行模拟操作
5年前
归来仍是少年
5年前
QQWeb登陆P值算法
5年前
SinKingPHP个人MVC框架
5年前
YY模拟操作
5年前
最新评论
+376
网站留言
Copyright © 2025 网站备案号: 皖ICP备18022767号-3
沉沦云网络. SinKingCloud
主页
页面
  • 个人技术栈
  • 留言
博主
流逝中沉沦
流逝中沉沦 管理员
一个热爱生活热爱技术的00后少年
12 文章 50951 评论 4377981 浏览
测试
测试

主题风格 设置选项


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

“扫一扫”分享到微信

赞赏作者

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

感谢您对作者的支持!

 支付宝 微信支付