web微信

1.扫码获取头像

当你打开web微信的时候,因为http是无状态的,web微信如何实时的获取用户的扫码动作?

那么这里用到的是长轮询的方式。

from flask import Flask,request,redirect,render_template,session,jsonify
import time
import requests
import re
from bs4 import BeautifulSoup
import json


app =Flask(__name__)
app.secret_key='adfa12da'

@app.route('/login',methods=['GET',"POST"])
def login():
    '''
    扫码获取头像
    :return: 
    '''
    if request.method=='GET':
        ctime = str(int(time.time()*1000))
        qcode_url = 'https://login.wx.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_={0}'.format(ctime)
        ret = requests.get(qcode_url)
        qcode = re.findall('uuid = "(.*)";',ret.text)[0]
        session['qcode'] = qcode
        session['login_cookies'] = ret.cookies.get_dict()
        return render_template('login.html',qcode=qcode)

    else:
        pass


####Html#########
<img id="img" src="https://login.weixin.qq.com/qrcode/{{qcode}}">
获取web微信头像

相关文章:

  • 2022-12-23
  • 2021-08-13
  • 2021-04-25
  • 2022-12-23
  • 2021-09-08
  • 2021-05-26
  • 2022-02-21
  • 2021-12-18
猜你喜欢
  • 2021-11-23
  • 2021-07-16
  • 2021-11-15
  • 2021-10-23
  • 2021-12-14
  • 2021-11-25
相关资源
相似解决方案