123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace App\Handlers;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Support\Str;
- class ImageUploadHandler
- {
- protected $allowed_ext = ["png", "jpg", "gif", 'jpeg'];
- public function save($file, $folder, $disk, $file_prefix = '')
- {
-
- $extension = strtolower($file->getClientOriginalExtension()) ?: 'png';
-
-
- if ($file_prefix) {
- $filename = $file_prefix . '_' . time() . '_' . Str::random(10) . '.' . $extension;
- } else {
- $filename = time() . '_' . Str::random(10) . '.' . $extension;
- }
-
- if (!in_array($extension, $this->allowed_ext)) {
- return false;
- }
-
- $path = Storage::disk($disk)->putFileAs($folder, $file, $filename);
- return $path;
- }
-
- public function createWechatQrcode($folder,$user_id,$endfilename){
-
- $easyWechat = app('wechat.mini_program');
- $response = $easyWechat->app_code->getUnlimit($user_id, [
- 'page' => 'pages/index/index',
- 'width' => 340,
- ]);
- if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
-
- $response->saveAs($folder, $user_id . $endfilename);
- return true;
- } else {
- Log::error('微信生成二维码失败' . $response);
- return false;
- }
- }
- }
|