Skip to content

Instantly share code, notes, and snippets.

@qichunren
Created April 23, 2025 11:38
Show Gist options
  • Save qichunren/bf68a5bd4f2f6285e3611935f0fce4a5 to your computer and use it in GitHub Desktop.
Save qichunren/bf68a5bd4f2f6285e3611935f0fce4a5 to your computer and use it in GitHub Desktop.
Frontend Javascript Generate QRCode
import QRCode from 'qrcode'
document.addEventListener('DOMContentLoaded', function() {
console.log("DOMContentLoaded");
const baseUrl = "https://open.weixin.qq.com/connect/oauth2/authorize";
const params = new URLSearchParams({
appid: "wx49e1457a970ee840",
redirect_uri: "https://qiwangtech.com/weixin/wechat/verify",
response_type: "code",
scope: "snsapi_base",
state: "STATE"
});
const wechatAuthUrl = `${baseUrl}?${params.toString()}#wechat_redirect`;
QRCode.toCanvas(document.getElementById('qrcode'), wechatAuthUrl, function (error) {
if (error) console.error(error)
console.log('success!');
})
});
@qichunren
Copy link
Author

<!-- QR Code Test Section -->
<div class="bg-white py-16 px-4 sm:px-6 lg:px-8">
  <div class="max-w-7xl mx-auto">
    <div class="text-center">
      <h2 class="text-3xl font-extrabold text-gray-900">
        微信授权测试
      </h2>
      <p class="mt-4 text-lg text-gray-500">
        扫描下方二维码进行微信授权测试
      </p>
    </div>
    <div class="mt-8 flex justify-center">
      <canvas id="qrcode"></canvas>
    </div>
  </div>
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment