Code Monkey home page Code Monkey logo

Comments (5)

x1ah avatar x1ah commented on July 26, 2024 1

找到问题在哪了,获取 ptwebqq 必须通过请求确定登录状态的接口返回的链接再从 cookies里面取,不能直接不请求就直接 cookies 里面取,很感谢,给的博客资料很详细。THX!

from qqbot.

pandolia avatar pandolia commented on July 26, 2024

您好,关于 smartQQ 协议的细节,您可以参考下 ScienJus 的博客,写的非常深入细致:

http://www.scienjus.com/webqq-analysis-1/

关于 retcode 的含义,参考 ScienJus 的分析:

  1. 保证请求头中包含正常的User-Agent、Referer、Cookie等信息,如果是Post请求需要额外加上Origin
    在大部分情况下(除了获取二维码和确认二维码状态),返回内容均为JSON,其中retcode为请求结果(0为成功),response为返回数据
  2. 不过还有个特例是发送消息的接口,成功时返回的字段是errCode,失败时才是retcode
  3. 请求失败后,返回的错误码如果是1000000或1000001,几乎可以认为是缺少了第一条中的某个数据
  4. 如果请求参数中有t,当前版本不会检验它的值,所以我统一设为0.1,但是实际上它的值一般情况下均为当前时间的unix timestamp
  5. 如果返回的返回的错误码为1000003,很有可能是你的请求频率过于频繁

你这里返回的是 100000 ,有可能是请求的 header 缺少了 User-Agent、Referer、Cookie 或 Origin 等信息,也有可能是请求的 url 没写对。你可以把你的代码也发一下。

from qqbot.

x1ah avatar x1ah commented on July 26, 2024

感谢回复。
这是请求的地址,头信息,和返回的 retcode。

下面这是 cookies,

t参数是用random.random()生成,请求直接main.session.get(url, headers=headers)上面提到的headers都添加了,但是还是不太清楚为什么。
THX。

from qqbot.

pandolia avatar pandolia commented on July 26, 2024

好像没什么问题,你改成下面这个试试:

main.session.headers.update(**headers)
main.session.get(url)

from qqbot.

pandolia avatar pandolia commented on July 26, 2024

或者改成:

main.session.headers.update({
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:27.0) Gecko/20100101 Firefox/27.0',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Referer': 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1',
    'Origin': 'http://s.web2.qq.com'
})

resp = main.session.get(
    'http://s.web2.qq.com/api/getvfwebqq?ptwebqq=%s&clientid=%s&psessionid=&t=%s' % (ptwebqq, clientid, repr(random.random())
)

from qqbot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.