この記事では、Python を使用して WeChat ミニ プログラムで QR コードを生成する 2 つの方法を紹介します。必要な方は参考にしていただければ幸いです。
WeChat アプレットは QR コードを生成します:
使用される言語は Python で、2 つの方法があります:
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
関連する推奨事項:
WeChat アプレット PHP はパラメーターを使用して QR コードを生成します
WeChat アプレット ユーザーのクリック ボタン生成のサンプル コード パラメーター付きの QR コード
以上がPython を使用して WeChat ミニ プログラムで QR コードを生成する 2 つの方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。
