Esempio n. 1
0
def sendSinaWeibo(self,text,imgno=None):
    userAccessToken=UserAccessToken.all().fetch(1)
    if userAccessToken and userAccessToken[0].sinaisright:
        useracc=userAccessToken[0]
    else:
        return True
    self.auth= weibo.APIClient(webSetting.xlconsumer_key, webSetting.xlconsumer_secret,webSetting.WEIBOURL+'/Admin/login_check?website=sina')
    self.auth.set_access_token(useracc.sinaSecret, int(useracc.sinaExpires))




    try:
        if imgno:
#                image = urlfetch.fetch(
#                    url =imgno,
#                    payload = {},
#                    method = urlfetch.GET,
#                    headers = {'Content-Type':'application/x-www-form-urlencoded',
#                               'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6'},
#                    follow_redirects = True,deadline=10)
#                if image.status_code==200:
#                    bf=db.Blob(image.content)
                    result=self.auth.statuses.upload.post(pic=imgno,status=text.encode('utf-8'))
#                else:
#                    result=self.api.update_status(status=text[:139].encode('utf-8'))
        else:
            result=self.auth.statuses.update.post(status=text.encode('utf-8'))
    except Exception,e:
        logging.info('sina'+str(e))
        return False
Esempio n. 2
0
def sendWangYiWeibo(self,text,imgno=None):
    userAccessToken=UserAccessToken.all().fetch(1)
    if userAccessToken and userAccessToken[0].wyisright:
        useracc=userAccessToken[0]
    else:
        return True
    t = TBlog(webSetting.wyconsumer_key,  webSetting.wyconsumer_secret)
    t._request_handler.access_token = OAuthToken(useracc.wyToken,useracc.wySecret)
    try:
        imgdata=''
#        if imgno:
#                image = urlfetch.fetch(url=setting[0].dbphotoWebSite+'/s/'+imgno,deadline=10)
#
#                if image.status_code == 200:
#                    logging.info(setting[0].dbphotoWebSite+'/s/'+imgno)
#                    bf=db.Blob(image.content)
        if imgno:
            imgulr=json.read(t.statuses_upload(imgno))
            upload_image_url=imgulr['upload_image_url']
            text=upload_image_url+' '+text

        result=t.statuses_update({'status':text.encode('utf-8')})
    except Exception,e:
        logging.info('wy:'+str(e))
#        logging.info('wy'+str(result))
#        if str(result).find('40025')==-1:
        self.error(500)
        return False
Esempio n. 3
0
 def get(self):
     self.response.out.write("00242beb80964cb2c1ed6bd3b7593944")
     u=UserAccessToken()
     u.qqSecret = '5846415b2c341c23e9154008025393f7'
     u.qqToken = '151df8254b824f0fb3bc48ed8f7d03c3'
     u.qqisright = True
     u.sinaExpires = '1522066881'
     u.sinaSecret = '2.00HGNhqCdb1iQBb8eed27af80MRd2r'
     u.sinaToken = '7860a0f91f4ddf79f4c0f019c7a5d866'
     u.sinaisright = True
     u.sinauserid = '2610933591'
     u.wyisright = True
     u.wySecret = '2d213529803ab28090f822b896b9b29e'
     u.wyToken = '1c63afb34efb5d7a424c9c9b44b335fe'
     u.put()
Esempio n. 4
0
  def get(self):
    website=self.request.get('website')
    userAccessToken=UserAccessToken().all().fetch(1)
    if userAccessToken:
        userAccessToken=userAccessToken[0]
    else:
        userAccessToken=UserAccessToken()
    if 'sina'==website:
        """用户成功登录授权后,会回调此方法,获取access_token,完成授权"""
        # http://mk2.com/?oauth_token=c30fa6d693ae9c23dd0982dae6a1c5f9&oauth_verifier=603896
#        verifier = self.request.get('oauth_verifier', None)
#        auth_client = _oauth()
#        # 设置之前保存在session的request_token
#    #    request_token = request.session['oauth_request_token']
#        request_token=memcache.Client().get(website+"_request_token1")
#        if not request_token:
#            return
#        memcache.Client().delete(website+"_request_token1")
#    #    del request.session['oauth_request_token']
#
#        auth_client.set_request_token(request_token.key, request_token.secret)
#        access_token = auth_client.get_access_token(verifier)
        code=self.request.get('code')
        logging.info('code:'+code)
        client = weibo.APIClient(webSetting.xlconsumer_key, webSetting.xlconsumer_secret,webSetting.WEIBOURL+'/Admin/login_check?website=sina')
        r = client.request_access_token(code)

        access_token, expires_in, uid = r.access_token, r.expires_in, r.uid
        client.set_access_token(access_token, expires_in)
        logging.info('access token: %s' % sysjson.dumps(access_token))
        u = client.users.show.get(uid=uid)
        # 保存access_token,以后访问只需使用access_token即可
        userAccessToken.sinaSecret=access_token
#        userAccessToken.sinaToken=access_token.key
        userAccessToken.sinaExpires=str(expires_in)
        userAccessToken.sinauserid=uid
        userAccessToken.sinaisright=True
        userAccessToken.put()
    elif 'wy'==website:
#        t = TBlog(weboSetting.wyconsumer_key, weboSetting.wyconsumer_secret)
        request_token=memcache.Client().get(website+"_request_token3")
        if not request_token:
            return
        memcache.Client().delete(website+"_request_token3")
#        t._request_handler.request_token=request_token
#        request_token.get_auth_url()
#        pin=self.request.get('pin', None)
        pin=self.request.get('oauth_token', None)
        s=request_token.get_access_token(pin)
        userAccessToken.wySecret=s.secret
        userAccessToken.wyToken=s.key
        userAccessToken.wyisright=True
        userAccessToken.put()
    elif 'teng'==website:
        request_token=memcache.Client().get(website+"_request_token4")
        if not request_token:
            return
        memcache.Client().delete(website+"_request_token4")
        verifier = self.request.get('oauth_verifier', None)
        access_token = request_token.get_access_token(verifier)
        userAccessToken.qqSecret=access_token.secret
        userAccessToken.qqToken=access_token.key
        #userAccessToken.qquserid=auth_client.user_id
        userAccessToken.qqisright=True
        userAccessToken.put()

    return self.redirect('/Admin')