HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot//my.esfyn.top/Modules/Mp/Http/Controllers/Admin/MpCodeController.php
<?php

namespace Modules\Mp\Http\Controllers\Admin;


use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

class MpCodeController extends MpController
{
    public $view = 'admin.mp_code.';

    public $model = 'Modules\Mp\Models\MpCodeModel';

    public $request = 'Modules\Mp\Http\Requests\MpCodeRequest';

    public $with = ['mp'];


    public function afterStore($id)
    {
        $code = $this->getModel()->where('id', $id)->first();

        $mp = $this->service->getMpObject($code->mp_id, 'id');

        if ($code->code_type == 'forever') {
            $result = $mp->qrcode->forever($id);
        } else {
            $result = $mp->qrcode->temporary($id, 30 * 24 * 3600);
        }

        $url = $mp->qrcode->url($result['ticket']);

        $date = date('Ym/d');
        $disk = system_config('site_upload_disk');
        $path = 'public/uploads/codes/' . $date . '/' . Str::random(40) . ".png";

        Storage::disk($disk)
            ->put($path, file_get_contents($url));

        if ($code->reply_type == 'image' && $code->reply_image) {
            $code->reply_media_id = $this->service->uploadImage($code->reply_image, $code->mp_id);
        }

        $code->code_image = system_image_url($path);
        $code->save();
    }


    /**
     * @throws InvalidArgumentException
     * @throws GuzzleException
     * @throws InvalidConfigException
     */
    public function afterUpdate($id)
    {
        $code = $this->getModel()::find($id);

        if ($code->reply_type == 'image' && $code->reply_image) {

            if ($code->reply_media_id) {
                $this->service->uploadImage($code->mp_id, $code->reply_media_id);
            }

            $code->reply_media_id = $this->service->uploadImage($code->reply_image, $code->mp_id);
            $code->save();
        }
    }
}