Selaa lähdekoodia

修改排课表接口

jun 6 kuukautta sitten
vanhempi
sitoutus
4639132dd4

+ 27 - 0
app/Facades/Servers/WechatMini/MiniPay.php

@@ -0,0 +1,27 @@
+<?php namespace App\Facades\Servers\WechatMini;
+
+use Illuminate\Support\Facades\Facade;
+
+/**
+ * 对象存储
+ * 
+ * @method static string unifiedOrder($request)     下单
+ * 
+ * 
+ * @see \App\Servers\WechatMini\Mini
+ * 
+ */
+class MiniPay extends Facade
+{
+    /**
+     * Get the registered name of the component.
+     *
+     * @return string
+     */
+    protected static function getFacadeAccessor()
+    {
+        return '\App\Servers\WechatMini\MiniPay';
+    }
+}
+
+?>

+ 3 - 1
app/Http/Controllers/Api/Course.php

@@ -212,7 +212,9 @@ class Course extends Api{
         foreach ($data as &$dataItem) {
             $dataItem['course_image']	        = path_compat($dataItem['course_image']);
             //按老师分组
-            $list[$dataItem['teacher_id']][]	= $dataItem;
+            $list[$dataItem['teacher_id']]['teacher_id']	= $dataItem['teacher_id'];
+            $list[$dataItem['teacher_id']]['teacher_name']	= $dataItem['teacher_name'];
+            $list[$dataItem['teacher_id']]['list']	= $dataItem;
         }
         $list = array_values($list);
         // 返回结果

+ 63 - 0
app/Http/Controllers/Api/WechatPay.php

@@ -0,0 +1,63 @@
+<?php namespace App\Http\Controllers\Api;
+
+use App\Http\Controllers\Api\Api;
+use App\Models\Custom;
+use App\Models\Orders;
+use App\Facades\Servers\WechatMini\MiniPay;
+use EasyWeChat\Factory;
+use Illuminate\Http\Request;
+
+/**
+ * 微信接口
+ * 
+ * @author 刘相欣
+ * 
+ * */
+class WechatPay extends Api{
+    /**
+     * 小程序微信支付下单				/api/wechat_pay/unifiedorder
+     *
+     * */
+    public function unifiedorder($request)
+    {
+        $data = [];
+        $result = MiniPay::unifiedOrder($data);
+        return $result;
+    }
+	
+	/**
+	 * 小程序微信支付回调				/api/wechat_pay/notify
+	 * 
+	 * */
+    public function notify($request)
+    {
+        $app				= Factory::payment(config('wechat.mini_pay'));
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            // 支付成功的处理逻辑
+            $order = Orders::query()->where('out_trade_no','=',$message['out_trade_no'])->first();
+            // 如果订单不存在
+            if (!$order) {
+                return true;
+            }
+            $data = [];
+            if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                // 用户是否支付成功
+                if ($message['result_code'] === 'SUCCESS') {
+                    $order->paid_at = time(); // 更新支付时间为当前时间
+                    $order->status = 'paid';
+
+                    // 用户支付失败
+                } elseif ($message['result_code']=== 'FAIL') {
+                    $order->status = 'paid_fail';
+                }
+            } else {
+                return $fail('通信失败,请稍后再通知我');
+            }
+            $fail('Order not exists.');
+            return true; // 返回 true 表示处理成功
+        });
+        return $response;
+    }
+
+
+}

+ 1 - 1
app/Servers/WechatMini/Mini.php

@@ -82,5 +82,5 @@ class Mini
 		// 获取不包含区号的手机号(因为绑定手机号字段会有国际区号)
 		return                                  ['error'=>$result['errcode'].'=>'.$result['errmsg']];
     }
-    
+
 }

+ 39 - 0
app/Servers/WechatMini/MiniPay.php

@@ -0,0 +1,39 @@
+<?php namespace App\Servers\WechatMini;
+
+use EasyWeChat\Factory;
+use Ixudra\Curl\Facades\Curl;
+/**
+ * 微信小程序
+ * 
+ */
+class MiniPay
+{
+    protected $payment;
+
+    public function __construct(Factory $factory)
+    {
+        $this->payment = $factory->payment(config('wechat.mini_pay',[]));
+    }
+    /**
+     * 微信小程序支付下单
+     *
+     */
+    public function unifiedOrder($request)
+    {
+        $result = $this->payment->order->unify([
+            'body' => $request->get('body'), // 商品描述
+            'out_trade_no' => $request->get('out_trade_no'), // 商户订单号
+            'total_fee' => $request->get('total_fee'), // 订单金额
+            'notify_url' => $request->get('notify_url'), // 支付结果通知地址
+        ]);
+
+        if ($result['return_code'] === 'SUCCESS' && !isset($result['err_code'])) {
+            $prepayId = $result['prepay_id'];
+            $json = $this->payment->jssdk->sdkConfig($prepayId);
+            return response()->json($json);
+        } else {
+            return response()->json(['error' => '创建订单失败'], 500);
+        }
+    }
+
+}

+ 2 - 1
composer.json

@@ -20,7 +20,8 @@
         "tencentcloud/sms": "^3.0",
         "vinkla/hashids": "^9.1",
         "w7corp/easywechat": "^5.35",
-        "wantp/snowflake": "^1.2"
+        "wantp/snowflake": "^1.2",
+        "wechatpay/wechatpay": "^1.4"
     },
     "require-dev": {
         "facade/ignition": "^2.5",

+ 155 - 2
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "ed42257c340ab4839682e5b545073cf6",
+    "content-hash": "96a63dd17e9e451d6b3fa27d2502abc0",
     "packages": [
         {
             "name": "asm89/stack-cors",
@@ -1413,6 +1413,92 @@
             ],
             "time": "2023-12-03T20:05:35+00:00"
         },
+        {
+            "name": "guzzlehttp/uri-template",
+            "version": "v1.0.3",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/guzzle/uri-template.git",
+                "reference": "ecea8feef63bd4fef1f037ecb288386999ecc11c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/guzzle/uri-template/zipball/ecea8feef63bd4fef1f037ecb288386999ecc11c",
+                "reference": "ecea8feef63bd4fef1f037ecb288386999ecc11c",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^7.2.5 || ^8.0",
+                "symfony/polyfill-php80": "^1.24"
+            },
+            "require-dev": {
+                "bamarni/composer-bin-plugin": "^1.8.2",
+                "phpunit/phpunit": "^8.5.36 || ^9.6.15",
+                "uri-template/tests": "1.0.0"
+            },
+            "type": "library",
+            "extra": {
+                "bamarni-bin": {
+                    "bin-links": true,
+                    "forward-command": false
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "GuzzleHttp\\UriTemplate\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Graham Campbell",
+                    "email": "hello@gjcampbell.co.uk",
+                    "homepage": "https://github.com/GrahamCampbell"
+                },
+                {
+                    "name": "Michael Dowling",
+                    "email": "mtdowling@gmail.com",
+                    "homepage": "https://github.com/mtdowling"
+                },
+                {
+                    "name": "George Mponos",
+                    "email": "gmponos@gmail.com",
+                    "homepage": "https://github.com/gmponos"
+                },
+                {
+                    "name": "Tobias Nyholm",
+                    "email": "tobias.nyholm@gmail.com",
+                    "homepage": "https://github.com/Nyholm"
+                }
+            ],
+            "description": "A polyfill class for uri_template of PHP",
+            "keywords": [
+                "guzzlehttp",
+                "uri-template"
+            ],
+            "support": {
+                "issues": "https://github.com/guzzle/uri-template/issues",
+                "source": "https://github.com/guzzle/uri-template/tree/v1.0.3"
+            },
+            "funding": [
+                {
+                    "url": "https://github.com/GrahamCampbell",
+                    "type": "github"
+                },
+                {
+                    "url": "https://github.com/Nyholm",
+                    "type": "github"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/uri-template",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2023-12-03T19:50:20+00:00"
+        },
         {
             "name": "hashids/hashids",
             "version": "4.1.0",
@@ -7737,6 +7823,73 @@
                 "source": "https://github.com/webmozarts/assert/tree/1.11.0"
             },
             "time": "2022-06-03T18:03:27+00:00"
+        },
+        {
+            "name": "wechatpay/wechatpay",
+            "version": "1.4.10",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/wechatpay-apiv3/wechatpay-php.git",
+                "reference": "9c364872bd2063bf3f10efc3765e96e3e1b20e2e"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/wechatpay-apiv3/wechatpay-php/zipball/9c364872bd2063bf3f10efc3765e96e3e1b20e2e",
+                "reference": "9c364872bd2063bf3f10efc3765e96e3e1b20e2e",
+                "shasum": ""
+            },
+            "require": {
+                "ext-curl": "*",
+                "ext-libxml": "*",
+                "ext-openssl": "*",
+                "ext-simplexml": "*",
+                "guzzlehttp/guzzle": "^6.5 || ^7.0",
+                "guzzlehttp/uri-template": "^0.2 || ^1.0",
+                "php": ">=7.1.2"
+            },
+            "require-dev": {
+                "phpstan/phpstan": "^0.12.89 || ^1.0",
+                "phpunit/phpunit": "^7.5 || ^8.5.16 || ^9.3.5"
+            },
+            "bin": [
+                "bin/CertificateDownloader.php"
+            ],
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "WeChatPay\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "Apache-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "James ZHANG",
+                    "homepage": "https://github.com/TheNorthMemory"
+                },
+                {
+                    "name": "WeChatPay Community",
+                    "homepage": "https://developers.weixin.qq.com/community/pay"
+                }
+            ],
+            "description": "[A]Sync Chainable WeChatPay v2&v3's OpenAPI SDK for PHP",
+            "homepage": "https://pay.weixin.qq.com/",
+            "keywords": [
+                "AES-GCM",
+                "aes-ecb",
+                "openapi-chainable",
+                "rsa-oaep",
+                "wechatpay",
+                "xml-builder",
+                "xml-parser"
+            ],
+            "support": {
+                "issues": "https://github.com/wechatpay-apiv3/wechatpay-php/issues",
+                "source": "https://github.com/wechatpay-apiv3/wechatpay-php/tree/v1.4.10"
+            },
+            "time": "2024-09-19T04:22:06+00:00"
         }
     ],
     "packages-dev": [
@@ -10260,5 +10413,5 @@
         "php": "^7.3|^8.0"
     },
     "platform-dev": [],
-    "plugin-api-version": "2.6.0"
+    "plugin-api-version": "2.3.0"
 }

+ 7 - 1
config/wechat.php

@@ -20,5 +20,11 @@ return [
         // server config
         'token' => env('WECHAT_WORK_TOKEN', 'Efd61RPH3GzEwfEATRwdJVKhi'),
         'aes_key' => env('WECHAT_WORK_ENCODING_AES_KEY', 'XL1brptJzQeDMwp5nvuojb8YEDx9GXy9kxaQ8JQl2Zu'),
-    ]
+    ],
+    'mini_pay'=>[
+        'app_id' => 'wxfa381386497cd3b9',
+        'mch_id'             => 'your-mch-id',
+        'key'                => 'key-for-signature',   // API v2 密钥 (注意: 是v2密钥 是v2密钥 是v2密钥)
+        'notify_url'         => '默认的订单回调地址',
+    ],
 ];

+ 1 - 1
public/static/Admin/css/components.css

@@ -2477,7 +2477,7 @@ Chart tooltips
 }
 
 /***
-Mini chart containers
+WxPay chart containers
 ***/
 .bar-chart,
 .line-chart {

+ 4 - 1
routes/api.php

@@ -121,4 +121,7 @@ Route::any('course/get_schedule_list',[\App\Http\Controllers\Api\course::class,'
 //我的预约列表
 Route::any('course/reservation_list',[\App\Http\Controllers\Api\course::class,'reservation_list']);
 //取消预约
-Route::any('course/cancel_reservation',[\App\Http\Controllers\Api\course::class,'cancel_reservation']);
+Route::any('course/cancel_reservation',[\App\Http\Controllers\Api\course::class,'cancel_reservation']);
+
+// 微信支付回调
+Route::any('wechat_pay/notify',[\App\Http\Controllers\Api\WechatPay::class,'notify']);