Beispiel #1
0
 def get(self, code, *args, **kwargs):
     grant_type = 'authorization_code'
     args = '?appid={0}&secret={1}&code={2}&grant_type={3}'.format(
         APPID, APPSECRET, code, grant_type)
     url = 'https://api.weixin.qq.com/sns/oauth2/access_token' + args
     resp = HttpRpcClient().fetch_async(url=url)
     resp = resp.body
     logger.debug('resp = %r', resp)
     resp = ujson.loads(resp)
     #get wechat user info
     token = resp.get('access_token')
     openid = resp.get('openid')
     userinfo_args = '?access_token={0}&openid={1}&lang=zh_CN'.format(
         token, openid)
     userinfo_url = 'https://api.weixin.qq.com/sns/userinfo' + userinfo_args
     user_resp = HttpRpcClient().fetch_async(url=userinfo_url)
     str_user_resp = user_resp.body
     logger.debug('user_resp = %r', str_user_resp)
     user_resp = ujson.loads(str_user_resp)
     self.render('wechat_add_device.html', payload=user_resp)
Beispiel #2
0
 def get(self, code):
     grant_type = 'authorization_code'
     args = '?appid={0}&secret={1}&code={2}&grant_type={3}'.format(
         APPID, APPSECRET, code, grant_type)
     url = 'https://api.weixin.qq.com/sns/oauth2/access_token' + args
     resp = HttpRpcClient().fetch_async(url=url)
     resp = resp.body
     logger.debug('resp = %r', resp)
     resp = ujson.loads(resp)
     #get wechat user info
     token = resp.get('access_token')
     openid = resp.get('openid')
     if openid:
         username = '******' + openid
         dev_set = GDevRdsInts.send_cmd(*getall_wechat_devs(username))
         dev_list = [{
             'gid': dev[0],
             'nickname': dev[1]
         } for dev in dev_set.iteritems()]
         logger.debug('dev_list = %r, username = %r', dev_list, username)
         self.render('wechat_manage_dev.html',
                     dev_list=dev_list,
                     username=username)
     return
Beispiel #3
0
        content_type = img.headers.get('Content-Type')
        logger.debug(u'content_type = %s' % content_type)
        if content_type.split('/')[0] == 'image':
            file_type = '1'

    logger.debug(u'from_user_name=%s, fn=%s', from_user_name, fn)
    ul = 0
    by_app = 0
    tk = gen_file_tk(from_user_name, fn, ul, by_app)
    logger.debug(u'save wechat file. tk = %r' % tk)
    up_args = {
        'tk': tk,
        'src': file_type,
        'by': from_user_name,
        'usage': 'share'
    }
    for _ in xrange(3):
        logger.debug(u'save wechat file. up_url = %s' %
                     (BEIQI_FILE_UP_URL + urllib.urlencode(up_args)))
        resp = HttpRpcClient().fetch_async(url=BEIQI_FILE_UP_URL +
                                           urllib.urlencode(up_args),
                                           body=img.body)
        if resp.code == 200:
            break
    if resp.code != 200:
        logger.error(u'file up resp.code = %r', resp.code)
        return None
    logger.debug(u'file up resp.code = %r', resp.code)
    resp = ujson.loads(resp.body)
    return fn, tk, resp.get('r')