安裝套件
使用 EasyWeChat 套件處理授權。
1
   | composer install overtrue/wechat
   | 
 
使用 simplesoftwareio/simple-qrcode 套件生成二維條碼。
1
   | composer install simplesoftwareio/simple-qrcode
   | 
 
引入第三方套件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
   | require __DIR__ . '/vendor/autoload.php';
  $app = \EasyWeChat\Factory::officialAccount([     'app_id' => $config['app_id'],     'secret' => $config['secret'],     'token' => $config['token'],     'oauth' => [         'scopes'   => explode(',', $config['oauth']['scopes']),         'callback' => $config['oauth']['callback'],     ],     'log' => [         'level' => $config['log']['level'],         'file' => __DIR__ . '/' . $config['log']['file'],     ], ]);
   | 
 
生成登入條碼:
1 2 3
   | $link = 'login.php' 
  echo (new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator)->size(500)->generate($link);
   | 
 
登入:
1
   | $app->oauth->redirect()->send(); 
   | 
 
回調:
1
   | var_dump($app->oauth->user()); 
   |