seven 6 天之前
父节点
当前提交
d8f3e4f944
共有 3 个文件被更改,包括 70 次插入1 次删除
  1. 1 1
      app/Http/Controllers/admin/Wallet.php
  2. 66 0
      app/Services/BaseService.php
  3. 3 0
      app/Services/PaymentOrderService.php

+ 1 - 1
app/Http/Controllers/admin/Wallet.php

@@ -294,7 +294,7 @@ class Wallet extends Controller
         // $order_no = SanJinService::createOrderNo();
         // $result = SanJinService::pay(10000,$order_no);
         $result = PaymentOrderService::createPay($memberId,200,'test');
-        PaymentOrderService::sendMessage($result['chat_id'],$result['text']);
+        PaymentOrderService::sendMessage($result['chat_id'],$result['text'],[],$result['image']??'');
         echo "<pre>";
         var_dump($result);
     }

+ 66 - 0
app/Services/BaseService.php

@@ -424,4 +424,70 @@ class BaseService
         return $prefix . $timePart . $randomPart . $memberSuffix;
     }
 
+
+    /**
+     * @description: 生成支付二维码
+     * @param {*} $address 支付地址
+     * @return {*}
+     */
+    public static function createPaymentQrCode($address = '')
+    {
+        $content = $address;
+        $qrSize = 300;
+        $font = 4;
+        $textHeight = 20;
+        $padding = 10;
+
+        // 生成二维码图像对象
+        $result = Builder::create()
+            ->writer(new PngWriter())
+            ->data($content)
+            ->size($qrSize)
+            ->margin(0)
+            ->build();
+
+        $qrImage = imagecreatefromstring($result->getString());
+
+        // 创建画布(加上下方文字区和边距)
+        $canvasWidth = $qrSize + $padding * 2;
+        $canvasHeight = $qrSize + $textHeight + $padding * 2;
+        $image = imagecreatetruecolor($canvasWidth, $canvasHeight);
+
+        // 背景白色
+        $white = imagecolorallocate($image, 255, 255, 255);
+        imagefill($image, 0, 0, $white);
+
+        // 黑色字体
+        $black = imagecolorallocate($image, 0, 0, 0);
+
+        // 合并二维码图像
+        imagecopy($image, $qrImage, $padding, $padding, 0, 0, $qrSize, $qrSize);
+
+        // 写文字
+        $textWidth = imagefontwidth($font) * strlen($content);
+        $x = ($canvasWidth - $textWidth) / 2;
+        $y = $qrSize + $padding + 5;
+        imagestring($image, $font, $x, $y, $content, $black);
+
+        $address_name = self::generateRandomString(20).time();
+
+        // 生成文件名
+        $filename = $address_name. '.png';
+        $relativePath = 'payment/' . $filename;
+        $storagePath = storage_path('app/public/' . $relativePath);
+
+        // 确保目录存在
+        @mkdir(dirname($storagePath), 0777, true);
+
+        // 保存图片到文件
+        imagepng($image, $storagePath);
+
+        // 清理
+        imagedestroy($qrImage);
+        imagedestroy($image);
+
+        // 返回 public 存储路径(可用于 URL)
+        return 'storage/'.$relativePath; // 或返回 Storage::url($relativePath);
+    }
+
 }

+ 3 - 0
app/Services/PaymentOrderService.php

@@ -210,6 +210,9 @@ class PaymentOrderService extends BaseService
         $ret = SanJinService::pay(($amount*100), $order_no, $channel);
         if($ret['code'] == 0){
             var_dump($ret);
+
+            $qrCode = asset(self::createPaymentQrCode($ret['data']['payUrl']));
+            $result['image'] = $qrCode;
             $item = $ret['data'];
             $data['status'] = self::STATUS_PROCESS;
             $data['pay_no'] = $item['tradeNo'];