EasyWechat 小程序获取二维码
1.
composer require overtrue/wechat:~4.0 -vvv
2.
<?php
namespace App\Services;
use EasyWeChat\Factory;
use Illuminate\Support\Facades\Storage;
class WechatService
{
public function index($path,$width)
{
$config = [
'app_id' => env('DEFAULT_APPID'),
'secret' => env('APPSECRET'),
'response_type' => 'array',
'log' => [
'level' => 'debug',
'file' => __DIR__.'/wechat.log',
],
];
$app = Factory::miniProgram($config);
$response = $app->app_code->getQrCode($path,$width);
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
$contents = $response->getBody()->getContents();
$qrcode_url = '/' . env('FILE_DIR') . '/qrcode/' . date('Ymd') . '/' . str_random(32) . uniqid() . '.jpg';
if (Storage::put($qrcode_url, $contents)) {
return env('FILE_CUSTOM_DOMAIN') . $qrcode_url;
}
return false;
}
return false;
}
}