• <label id="pxtpz"><meter id="pxtpz"></meter></label>
      1. <span id="pxtpz"><optgroup id="pxtpz"></optgroup></span>

        當前位置:雨林木風下載站 > 應用軟件教程 > 詳細頁面

        微信小程序中用Python生成二維碼的2種方式

        微信小程序中用Python生成二維碼的2種方式

        更新時間:2025-09-20 文章作者:未知 信息來源:網絡 閱讀次數:

        微信小程序,簡稱小程序,英文名Mini Program,是一種不需要下載安裝即可使用的應用,它實現了應用“觸手可及”的夢想,用戶掃一掃或搜一下即可打開應用。小程序是一種不用下載就能使用的應用,也是一...
        微信小程序,簡稱小程序,英文名Mini Program,是一種不需要下載安裝即可使用的應用,它實現了應用“觸手可及”的夢想,用戶掃一掃或搜一下即可打開應用。小程序是一種不用下載就能使用的應用,也是一項門檻非常高的創新,經過將近兩年的發展,已經構造了新的小程序開發環境和開發者生態。

        本篇文章給大家帶來的內容是關于微信小程序中用Python生成二維碼的兩種方式 ,有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。

        微信小程序生成二維碼:

        所用語言python,有兩種方式:

        1: 后端傳一段字符串給前端, 前端顯示

        2: 后端直接生成圖片

        1: 后端傳一段字符串給前端, 前端顯示

        def get_wxCode(Request, UserInfo):
            try:
                scene = Request["scene"]
                access_token = get_wxCode_token()
                if not access_token:
                    return False
                textmod = {"scene": scene, "page": "pages/index/main", "width": 430, "auto_color": True, "is_hyaline": False}
                textmod = json.dumps(textmod).encode(encoding='utf-8')
                header_dict = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko',
                               "Content-Type": "application/json"}
                url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + access_token
                req = request.Request(url=url, data=textmod, headers=header_dict)
                res = request.urlopen(req)
                res = res.read()
                b64str = base64.b64encode(res)
                return b64str
            except Exception as e:
                print(e)
                return False
        var getWXcode2 = function(hostname){  //獲取管理端小程序碼
        
            //動態獲取域名,若為本地環境,則默認攜帶參數為wx-test
            //示例:londex.i-plc.cn
            var hostname1 =  window.location.host;
            hostname1 = hostname1.split('.')[0];
            if(hostname1 == '127' || hostname1 == 'localhost'){
                hostname1 = hostname;
            }
            if(window.localStorage.getItem('wxcode2')){
                $('#wxcodeImg2').attr('src','data:image/png;base64,'+ window.localStorage.getItem('wxcode2'));
                $('#wxCodeModal2').modal('show');
                return;
            }
            var params = {
                "scene":hostname1,
            };
            $.ajax({
                type:'post',
                url:'/request?rname=i_plc.Page.wechat_api.wechat.get_wxCode',
                data:params,
                success:function (res) {
                    console.log(res)
        
                    if(res === false){
                        $.MessageBox.notify('warn', '獲取失敗,請稍后再試!');
                    }else{
                        console.log(res)
                        $('#wxcodeImg2').attr('src','data:image/png;base64,'+res);
                        $('#wxCodeModal2').modal('show');
                        window.localStorage.setItem('wxcode2',res)
                    }
        
                }
            });
        };

        2: 后端直接生成圖片

        def get_wxCode(Request, UserInfo):
            """
                生成小程序二維碼
            :param Request:
            :param UserInfo:
            :return:
            """
            result = {"success": False}
            try:
                # scene = Request["scene"]
                access_token = get_wxCode_token()
                if not access_token:
                    raise Exception("access_token")
                compid = Request["compid"]
                sql = "select compIndex from company where operationFlag=9 and compID=%s" % compid
                Result = SqlRun(sql)
                if Result["Data"] and Result["Data"][0] and Result["Data"][0][0]:
                    scene = Result["Data"][0][0]
        
                    textmod = {"scene": scene, "page": "pages/index/main", "width": 430, "auto_color": True, "is_hyaline": False}
                    textmod = json.dumps(textmod).encode(encoding='utf-8')
                    header_dict = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko',
                                   "Content-Type": "application/json"}
                    url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + access_token
                    req = request.Request(url=url, data=textmod, headers=header_dict)
                    res = request.urlopen(req)
                    res = res.read()
                    b64str = base64.b64encode(res)
                    imgdata=base64.b64decode(b64str)
        
                    path = "static/tmpfiles/scan_%s.png" % file_name
                    file = open(os.path.join(settings.BASE_DIR, path,), 'wb+')
                    file.write(imgdata)
                    file.close()
        
                    result["code_url"] = path
                    result["success"] = True
            except Exception as e:
                result["error_msg"] = str(e)
            return json.dumps(result)
        
        
        def get_wxCode_token():
            try:
                textmod = {"grant_type": "client_credential",
                    "appid": "wx44a452fb08b0a990",
                    "secret": "9aedb0a274027bdd09612fbde3298129"
                }
                textmod = parse.urlencode(textmod)
                header_dict = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'}
                url = 'https://api.weixin.qq.com/cgi-bin/token'
                req = request.Request(url='%s%s%s' % (url, '?', textmod), headers=header_dict)
                res = request.urlopen(req)
                res = res.read().decode(encoding='utf-8')
                res = json.loads(res)
                access_token = res["access_token"]
                return access_token
            except Exception as e:
                print(e)
                return False

        相關推薦:

        微信小程序PHP生成帶參數二維碼

        微信小程序用戶點擊按鈕生成帶參二維碼的示例代碼

        以上就是微信小程序中用Python生成二維碼的兩種方式的詳細內容,更多請關注php中文網其它相關文章!


        小程序是一種不需要下載安裝即可使用的應用,它實現了應用“觸手可及”的夢想,用戶掃一掃或者搜一下即可打開應用。

        溫馨提示:喜歡本站的話,請收藏一下本站!

        本類教程下載

        系統下載排行

        主站蜘蛛池模板: 亚洲成在人线aⅴ免费毛片| 日韩精品一区二区亚洲AV观看| 中中文字幕亚洲无线码| 麻豆国产精品免费视频| 亚洲理论在线观看| 亚洲国产精品免费在线观看| 久久久国产精品亚洲一区| 国产黄色免费网站| 97se亚洲国产综合自在线| 好爽又高潮了毛片免费下载| 毛片亚洲AV无码精品国产午夜| 国产一级淫片免费播放| 少妇亚洲免费精品| 久久亚洲国产成人亚| 国产va免费精品观看精品| 亚洲精品国产综合久久久久紧| 国产精品酒店视频免费看| 又长又大又粗又硬3p免费视频| 亚洲精品乱码久久久久久中文字幕| 久久久久免费精品国产| 亚洲欧洲国产精品久久| 免费黄色网址入口| WWW国产成人免费观看视频| 久久久久久亚洲精品| 美女被免费喷白浆视频| 噜噜噜亚洲色成人网站| 亚洲色精品aⅴ一区区三区| 亚洲视频免费观看| 亚洲最大在线视频| 国产人妖ts在线观看免费视频| 国产免费伦精品一区二区三区| 亚洲av永久无码精品网站 | 最近免费中文字幕大全免费| 中国亚洲呦女专区| 久久久久国产成人精品亚洲午夜| 日本免费污片中国特一级| 成人区精品一区二区不卡亚洲| 亚洲性久久久影院| 丁香花免费完整高清观看| 亚欧乱色国产精品免费视频| 91久久亚洲国产成人精品性色|