首页 > 解决方案 > Google Charts API(QR 码)返回 HTTP 错误 502

问题描述

您是否还有问题,您的二维码不再加载?这是因为 Google Charts 不再有效。谷歌在过去几天禁用了这项服务!因此,如果您正在苦苦挣扎,这就是原因:

https://groups.google.com/forum/#!topic/Google-chart-api/rZtHTyYgyXI

为此,您需要使用新的 Google 图表工具:

https://developers.google.com/chart/

我会弄清楚如何替换生成 QR 码的旧实现,并告诉你如何做到这一点。

标签: qr-code

解决方案


几个月前我遇到了这个问题,所以我只是做了我自己的二维码生成器,我使用 Laravel 框架(PHP)来解决这个问题:

首先我使用了这个库:

simplesoftwareio/simple-qrcode

这当然适用于 PHP

像这样的东西:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Str;
use SimpleSoftwareIO\QrCode\Facades\QrCode;

class QrCodeController extends BaseController
{
    /**
    * @param $uuid
     * @return mixed
     */
    public function generate($parameter) {
        $fileName = $parameter.'.png';
        $file = storage_path()."/".$this->app_directory."/".$fileName;
        QrCode::format('png')->size(1000)->generate($parameter, $file);

        return Response::download($file, $fileName)->deleteFileAfterSend(true);
    }
}

然后我只是添加到路由文件:

Route::get('qr/{parameter}', 'QrCodeController@generate');

这只是关于我解决这个问题的方式的一个想法。


推荐阅读