seven 1 settimana fa
parent
commit
2b427b034c

+ 26 - 0
app/Http/Controllers/api/Pay.php

@@ -0,0 +1,26 @@
+<?php
+
+
+namespace App\Http\Controllers\api;
+
+use App\Http\Controllers\Controller;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Http\Request;
+
+class Pay extends Controller
+{
+    // 同步通知
+    public function returnHandle(Request $request)
+    {
+
+    }
+
+    // 异步通知
+    public function notifyHandle(Request $request)
+    {
+        $data = $request->all();
+        // 记录到专用支付日志
+        Log::channel('payment')->info('支付回调', $data);
+    }
+
+}

+ 47 - 1
app/Services/Payment/SanJinService.php

@@ -12,6 +12,14 @@ class SanJinService extends BaseService
     // SanJin payment service methods would go here
     const REQUEST_URL = 'https://api.qbdf13.com/';
 
+    const ALIPAY_TO_CARD = 'DF001'; // 支付宝转银行卡
+    const ALIPAY_TO_ALIPAY = 'DF002'; // 支付宝转支付宝
+
+    // 获取异步的通知地址
+    public static function getNotifyUrl()
+    {
+        return 'https://botpc28.testx2.cc/';
+    }
     
     /**
      * @description: 获取请求客户端
@@ -25,7 +33,15 @@ class SanJinService extends BaseService
         ]);
     }
 
-    // 查询商户余额
+    /**
+     * @description: 查询商户余额
+     * @return {array}
+     *         {array.success - 是否成功 true|false}
+     *         {array.msg - 返回错误消息}
+     *         {array.code - 返回状态码:200成功,其他失败}
+     *         {array.timestamp - 时间戳 13位}
+     *         {array.data - 商户余额}
+     */    
     public static function findBalance()
     {
         $merchant_id  = config('app.tree_payment_merchant_id');
@@ -43,4 +59,34 @@ class SanJinService extends BaseService
         $body = $response->getBody();
         return json_decode($body->getContents(), true);
     }
+
+    
+    public static function pay($amount, $order_no, $notify_url, $return_url)
+    {
+        $data = [];
+        $merchant_id  = config('app.tree_payment_merchant_id');
+        $secret = config('app.tree_payment_secret');
+
+        $data['merchantNum'] = $merchant_id;
+        $data['amount'] = $amount;
+        $data['orderNo'] = $order_no;
+        $data['notifyUrl'] = $notify_url;
+        $data['returnUrl'] = $return_url;
+
+        $signStr = $merchant_id .  $order_no . $amount . $secret;
+        $sign = md5($signStr);
+        $data['sign'] = $sign;
+
+        $client = self::getClient();
+        $response = $client->post('api/pay', [
+                'json' => $data,
+                'headers' => [
+                    'Content-Type' => 'application/json',
+                ]
+            ]);
+        $body = $response->getBody();
+        $result = json_decode($body->getContents(), true);
+        
+        return $result;
+    }
 }

+ 13 - 0
config/logging.php

@@ -69,6 +69,19 @@ return [
             'level' => env('LOG_LEVEL', 'debug'),
             'days' => 14,
         ],
+        'payment' => [
+            'driver' => 'daily',
+            'path' => storage_path('logs/payment/payment.log'),
+            'level' => env('LOG_LEVEL', 'debug'),
+            'days' => 30,
+            'permission' => 0664,
+        ],
+        'payment_error' => [
+            'driver' => 'daily',
+            'path' => storage_path('logs/payment/error.log'),
+            'level' => 'error',
+            'days' => 90,
+        ],
 
         'slack' => [
             'driver' => 'slack',

+ 4 - 0
routes/api.php

@@ -5,6 +5,7 @@ use App\Constants\HttpStatus;
 use App\Http\Controllers\api\TelegramWebHook;
 use App\Http\Controllers\api\Home;
 use App\Http\Controllers\api\Issue;
+use App\Http\Controllers\api\Pay;
 
 Route::post("/onMessage", [TelegramWebHook::class, 'handle']);
 Route::get("/setWebHook", [Home::class, 'setWebHook']);
@@ -28,6 +29,9 @@ Route::prefix('/issue')->group(function () {
 
 
 Route::get('/test', [Home::class, 'test']);
+Route::prefix('/pay')->group(function () {
+    Route::get("/notify", [Pay::class, 'notifyHandle']);
+});
 
 
 Route::fallback(function () {