Scan the WeChat code to follow the official account login function PHP practical sharing

1. Install easywechat

Developed based on the easywechat framework, first download and install easywechat

composer require overtrue/wechat

2. Public account configuration

First go to the basic configuration of the official account background/fill in the server configuration configuration interface. It needs to be an address that can correctly receive WeChat push messages online. If you follow, scan QR codes, receive messages and other events, they will be pushed to this address.

Scan the WeChat code to follow the official account login function PHP practical sharing

Screenshot of public account configuration method

3. Create QR code

First create a temporary QR code and save the ticket.

use EasyWeChat\Foundation\Application;
// 生成随机数
$unique = md5(password_hash(uniqid(true), PASSWORD_BCRYPT));
// 二维码有效期600秒
$expiry = 600;
$app = new Application($options);
$qrcode = $app->qrcode;
$data = $qrcode->temporary($unique, $expiry);
// 这个值保存下来,待会查询扫码状态可以用到
$ticket = $data->ticket;
// 二维码的地址
$url = $qrcode->url($ticket);

Guess you like

Origin blog.csdn.net/mo3408/article/details/133358823