WeixinBot icon indicating copy to clipboard operation
WeixinBot copied to clipboard

请教下在同步信息的里面,rr取反时间戳取出来的不是负数吗?

Open fakerrr opened this issue 9 years ago • 18 comments

image 我~int(time.time())取到的是-的时间戳,但是我现在看到我这边网页上提交的payload里是rr: 1731091250这个,请问这1731091250怎么来的?

fakerrr avatar Mar 21 '16 11:03 fakerrr

同问,有无高手解答啊?

taskj avatar Oct 10 '16 06:10 taskj

确实是负数,有些区域的微信服务器上那个rr的值是正的,但是如果你给他一个负数他返回给你的response也是正常的,不影响

[email protected]

发件人: taskj 发送时间: 2016-10-10 14:49 收件人: Urinx/WeixinBot 抄送: fakerrr; Author 主题: Re: [Urinx/WeixinBot] 请教下在同步信息的里面,rr取反时间戳取出来的不是负数吗? (#36) 同问,有无高手解答啊? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

fakerrr avatar Oct 10 '16 07:10 fakerrr

感谢回答,发送了sid,skey,也POST了'BaseRequest',SyncKey,rr三个参数,但是现在还是遇到了返回的json数据里面 ret="1"的问题,目前都不知道是哪里出了问题,高手可以帮帮忙吗?万分感谢

taskj avatar Oct 10 '16 07:10 taskj

可能是需要发送的参数不完整,建议多观察,我搞这个也是很久之前弄的了- - 现在都忘记了,我记得有好几个参数要从他返回的参数里面取的

[email protected]

发件人: taskj 发送时间: 2016-10-10 15:10 收件人: Urinx/WeixinBot 抄送: fakerrr; Author 主题: Re: [Urinx/WeixinBot] 请教下在同步信息的里面,rr取反时间戳取出来的不是负数吗? (#36) 感谢回答,发送了sid,skey,也POST了'BaseRequest',SyncKey,rr三个参数,但是现在还是遇到了返回的json数据里面 ret="1"的问题,目前都不知道是哪里出了问题,高手可以帮帮忙吗?万分感谢 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

fakerrr avatar Oct 10 '16 07:10 fakerrr

都是从里面取得的参数都可以用,都print过出来确认过了,真是奇怪。。。感谢回答

taskj avatar Oct 10 '16 07:10 taskj

你是在请求哪一步数据的时候出现的问题,有链接吗

[email protected]

发件人: taskj 发送时间: 2016-10-10 15:23 收件人: Urinx/WeixinBot 抄送: fakerrr; Author 主题: Re: [Urinx/WeixinBot] 请教下在同步信息的里面,rr取反时间戳取出来的不是负数吗? (#36) 都是从里面取得的参数都可以用,都print过出来确认过了,真是奇怪。。。感谢回答 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

fakerrr avatar Oct 10 '16 07:10 fakerrr

def syncmess(): #请求消息的地址 url = 'https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=%s&skey=%s&lang=zh_CN' % (sid,skey) #需要post的参数 params = { 'BaseRequest':base_request, 'SyncKey': info['SyncKey'], 'rr': ~int(time.time()), } #post请求服务器 response = session.post(url,data=json.dumps(params),timeout=60) data = response.content.decode('utf-8') # { # "BaseResponse": { # "Ret": 0, # "ErrMsg": "" # } print(params)

taskj avatar Oct 10 '16 07:10 taskj

请求的是webwxsync获取新的消息这部的问题,url里面的参数和post的参数都是正确的,但是就是不知道为什么会返回ret=1给我。

taskj avatar Oct 10 '16 07:10 taskj

def getmsg(): global msg_data, skey, wxsid, deviceId, pass_ticket, synck, msgif, BaseRequest, jsondata, toulan params = { 'sid': wxsid, 'skey': skey, 'lang': 'zh_CN', 'pass_ticket': pass_ticket } url = 'https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=%s&skey=%s&pass_ticket=%s&lang=zh_CN' % ( wxsid, skey, pass_ticket) post = { 'BaseRequest': BaseRequest, 'SyncKey': jsondata, 'rr': ~int(time.time()) } # print post request = urllib2.Request(url=url, data=json.dumps(post)) response = urllib2.urlopen(request) msg_data = response.read() # print data jsondata = json.loads(msg_data)['SyncKey'] # print jsondata # print type(jsondata) datalist = jsondata[u'List'] datalist2 = [] for i in datalist: # print i[u'Val'] datalist2.append(i[u'Val']) print datalist2 print len(datalist2) if len(datalist2) < 7: synck = ('1_%s|' + '2_%s|' + '3_%s|' + '11_%s|' + '13_%s|' + '1000_%s|') % (datalist2[0], datalist2[1], datalist2[2], datalist2[3], datalist2[4], datalist2[5]) else: synck = ('1_%s|' + '2_%s|' + '3_%s|' + '11_%s|' + '13_%s|' + '201_%s|' '1000_%s|') % (datalist2[0], datalist2[1], datalist2[2], datalist2[3], datalist2[4], datalist2[5], datalist2[6])

这是我写的这部分的东西,会不会是在请求url上缺了pass_ticket这个参数

[email protected]

发件人: taskj 发送时间: 2016-10-10 15:32 收件人: Urinx/WeixinBot 抄送: fakerrr; Author 主题: Re: [Urinx/WeixinBot] 请教下在同步信息的里面,rr取反时间戳取出来的不是负数吗? (#36) 请求的是webwxsync获取新的消息这部的问题,url里面的参数和post的参数都是正确的,但是就是不知道为什么会返回ret=1给我。 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

fakerrr avatar Oct 10 '16 07:10 fakerrr

刚才很莫名其妙地返回成功了,真是诡异,用firebug看了url参数只需要提交sid skey两个参数,有时候又提交了lang这个参数,不需要pass_ticket,终于成功了,谢谢大神

taskj avatar Oct 10 '16 07:10 taskj

这种事情真的是很诡异的,有时候也要看RP= =,你是打算做一个自己的微信机器人?

[email protected]

发件人: taskj 发送时间: 2016-10-10 15:41 收件人: Urinx/WeixinBot 抄送: fakerrr; Author 主题: Re: [Urinx/WeixinBot] 请教下在同步信息的里面,rr取反时间戳取出来的不是负数吗? (#36) 刚才很莫名其妙地返回成功了,真是诡异,用firebug看了url参数只需要提交sid skey两个参数,有时候又提交了lang这个参数,不需要pass_ticket,终于成功了,谢谢大神 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

fakerrr avatar Oct 10 '16 07:10 fakerrr

是的,最近在学习python的爬虫

taskj avatar Oct 10 '16 07:10 taskj

练习微信这个项目应该很有帮助,加油

[email protected]

发件人: taskj 发送时间: 2016-10-10 15:44 收件人: Urinx/WeixinBot 抄送: fakerrr; Author 主题: Re: [Urinx/WeixinBot] 请教下在同步信息的里面,rr取反时间戳取出来的不是负数吗? (#36) 是的,最近在学习python的爬虫 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

fakerrr avatar Oct 10 '16 07:10 fakerrr

谢谢大神

taskj avatar Oct 10 '16 08:10 taskj

并不是大神QAQ,以后共同学习共同进步。

[email protected]

发件人: taskj 发送时间: 2016-10-10 16:05 收件人: Urinx/WeixinBot 抄送: fakerrr; Author 主题: Re: [Urinx/WeixinBot] 请教下在同步信息的里面,rr取反时间戳取出来的不是负数吗? (#36) 谢谢大神 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

fakerrr avatar Oct 10 '16 08:10 fakerrr

官方js里参数生成是通过 ~ new Date 由于js的位操作都是针对32位有符号整数,所以会把Date返回的毫秒为单位的大整数先去掉超过32位的高位部分再处理

你使用的语言一般是按照64位存储整数和位运算 所以得到的结果不一致

hexsum avatar Oct 11 '16 11:10 hexsum

强势回答一波,rr并不是时间戳取反,而是时间的hashcode值取反,java里是~new date().hashcode

Servtime avatar May 23 '18 02:05 Servtime

贴一下 python代码

from time import *
~(int(round(time() * 1000)))& 0xFFFFFFFF

ghost avatar May 14 '19 11:05 ghost