• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

python发腾讯微博代码分享

PHP admin 11个月前 (05-31) 9次浏览 0个评论
复制代码 代码如下:

import urllib.parse,os.path,time,sys,re,urllib.request
from http.client import HTTPSConnection
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKitWidgets import *
from PyQt5.QtNetwork import *

#path
ospath=sys.path[0]
if len(ospath)!=3:
ospath+=’\’
ospath=ospath.replace(‘\’,’/’)

#api
class Api:
def getOpenid(self,token):
url=”https://graph.qq.com/oauth2.0/me?access_token=%s” % token
u=urllib.request.urlopen(url)
data=u.read()
try:
data=data.decode(‘utf-8’)
except:
data=data.decode(‘gbk’)
openid=re.findall(‘”openid”:”(.+?)”‘,data)[0]
return openid
def qq(self,token,status,pic):
fSize=os.path.getsize(pic)
BOUNDARY=”$-img-lufei-goodboy-$”
CRLF=’rn’
data=[
‘–‘+BOUNDARY,
‘Content-Disposition: form-data; name=”access_token”‘,
”,
token,
‘–‘+BOUNDARY,
‘Content-Disposition: form-data; name=”openid”‘,
”,
self.getOpenid(token),
‘–‘+BOUNDARY,
‘Content-Disposition: form-data; name=”oauth_consumer_key”‘,
”,
‘100451446’,
#status
‘–‘+BOUNDARY,
‘Content-Disposition: form-data; name=”content”‘,
”,
status,
#pic