From dfeb6a3180c59f73de9ce185d9154988b0409d46 Mon Sep 17 00:00:00 2001 From: liapples Date: Thu, 26 Aug 2021 18:08:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=B8=E9=94=80=E4=BA=8C?= =?UTF-8?q?=E7=BB=B4=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/VerificationController.php | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/VerificationController.php b/app/Http/Controllers/Api/VerificationController.php index 677516b..f46f1c0 100644 --- a/app/Http/Controllers/Api/VerificationController.php +++ b/app/Http/Controllers/Api/VerificationController.php @@ -2,9 +2,12 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; +use App\Models\Agent; use App\Models\Order; use App\Models\User; use App\Common\OrderStatus; +use EasyWeChat\Factory; +use Illuminate\Support\Facades\Storage; class VerificationController extends Controller { @@ -15,7 +18,7 @@ class VerificationController extends Controller $code_arr = explode('-', $input_verify_code); if (count($code_arr) != 2) { - $this->error('参数错误'); + return $this->error('参数错误'); } list($id, $verify_code) = $code_arr; @@ -37,4 +40,37 @@ class VerificationController extends Controller return $this->success(); } + + public function qrcode() + { + $id = request()->input('id'); //订单ID + + $order = Order::where(['agent_id' => $this->agent_id, 'user_id' => $this->user_id])->find($id); + if (!$order) { + return $this->error('订单不存在!'); + } else if (!in_array($order->status, [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::REFUSED_REFUND])) { + return $this->error('当前订单状态不允许核销!'); + } else if (!$order->verify_code) { + $order->verify_code = uniqid(); + $order->save(); + } + + $verify_code = $order->id . '-' . $order->verify_code; + + $agent = Agent::find($this->agent_id); + $config = [ + 'app_id' => $agent->appid, + 'secret' => $agent->appsecret, + ]; + $app = Factory::miniProgram($config); + + $response = $app->app_code->getUnlimit('verify_code='.$verify_code); + + if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) { + $filename = $response->saveAs(storage_path('app/public/verify_code'), $verify_code); + } + + $prefix = Storage::disk('public')->url('verify_code/'); + return $this->success(['qrcode' => $prefix . $filename]); + } }