首页 > 编程 > Python > 正文

python发腾讯微博代码分享

2020-02-23 05:04:13
字体:
来源:转载
供稿:网友

代码如下:
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='/r/n'
        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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表