zoukankan      html  css  js  c++  java
  • 移植二维码实现登录功能

    简单粗暴

    上代码

    import re
    import time
    import requests
    import json
    
    CURRENT_TIME = None
    QCODE = None
    LOGIN_COOKIE_DICT = {}
    TICKET_COOKIE_DICT = {}
    TIPS = 1
    
    
    def log(request):
        base_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}'
        global CURRENT_TIME
        CURRENT_TIME = str(time.time())
        q_code_url = base_qcode_url.format(CURRENT_TIME)
        response = requests.get(q_code_url)
        print(response.text)
        # code代表二维码后缀
        code = re.findall('uuid = "(.*)";', response.text)[0]
        global QCODE
        QCODE = code
        return render(request, "log.html", {'code': code})
    
    
    def long_polling(request):
        ret = {'status': 408, 'data': None}
        try:
            global TIPS
            base_login_url = 'https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid={0}&tip={1}&r=-1359574064&_={2}'
            login_url = base_login_url.format(QCODE, TIPS, CURRENT_TIME)
            response_login = requests.get(login_url)
            if "window.code=201" in response_login.text:
                TIPS = 0
                avatar = re.findall("userAvatar = '(.*)';", response_login.text)[0]
                ret['data'] = avatar
                ret['status'] = 201
            elif "window.code=200" in response_login.text:
                LOGIN_COOKIE_DICT.update(response_login.cookies.get_dict())
                redirect_uri = re.findall('redirect_uri="(.*)";', response_login.text)[0]
                redirect_uri += '&fun=new&version=v2&lang=ch_CN'
                response_ticket = requests.get(redirect_uri, cookies=LOGIN_COOKIE_DICT)
                TICKET_COOKIE_DICT.update(response_ticket.cookies.get_dict())
    
                # from bs4 import BeautifulSoup
                # print(ret.text)
                ret['status'] = 200
                print(response_login.text)
        except Exception as e:
            print(e)
          
        return HttpResponse(json.dumps(ret))

    前端代码

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <div style=" 300px;margin: 0 auto;">
        <img id="qcode"  style=" 300px;height: 300px;" src="https://login.weixin.qq.com/qrcode/{{ code }}">
    </div>
    <script src="../static/js/jquery-2.2.3.min.js"></script>
    <script>
        $(function () {
                polling();
            });
        function polling() {
    
            {#console.log(1);#}
            {#polling();#}
            $.ajax({
                url:'/polling/',
                type:'GET',
                dataType:'json',
                success: function (arg) {
                    if (arg.status==408) {
                        polling();
                    }else if (arg.status==201) {
                       // 获取图片接着发
                        $('#qcode').attr('src',arg.data);  //将获得的图片地址赋值给data
                        polling();
                    }else {
                        location.href='/inde/'
                    }
    
    
                }
    
            })
        }
    </script>
    </body>
    </html>

    看就完事了

  • 相关阅读:
    IntelliJ IDEA 最新注册码
    tidyverse|数据分析常规操作-分组汇总(sumamrise+group_by)
    ComplexHeatmap|根据excel表绘制突变景观图(oncoplot)
    Tidyverse| XX_join :多个数据表(文件)之间的各种连接
    LDheatmap | SNP连锁不平衡图(LD)可视化,自己数据实现版!
    Tidyverse|数据列的分分合合,爱恨情仇
    R-ggpmisc|回归曲线添加回归方程,R2,方差表,香不香?
    R-rbind.fill|列数不一致的多个数据集“智能”合并,Get!
    R|tableone 快速绘制文章“表一”-基线特征三线表
    R|生存分析
  • 原文地址:https://www.cnblogs.com/ssxblog/p/10626740.html
Copyright © 2011-2022 走看看