wzq před 5 roky
rodič
revize
936c10d73a

+ 27 - 0
app/Http/Controllers/WechatController.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Repositories\PosterRepository;
+use App\Traits\UserTrait;
+use Illuminate\Support\Facades\Redis;
+use Illuminate\Support\Facades\Validator;
+use Illuminate\Http\Request;
+use App\Services\WechatService;
+
+class WechatController extends Controller
+{
+    public function __construct(WechatService $wechatService)
+    {
+        $this->wechatService = $wechatService;
+    }
+
+    /**
+     * 公众号分享
+     */
+    public function share(Request $request)
+    {
+        $res = $this->wechatService->share();
+        return jsonSuccess($res);
+    }
+}

+ 23 - 0
app/Services/WechatService.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Services;
+
+use EasyWeChat\Factory;
+
+class WechatService
+{
+
+    public function __construct()
+    {
+        $config = [
+            'app_id'    => config('customer.wechat_id'),
+            'secret'    => config('customer.wechat_id'),
+        ];
+        $this->app = Factory::officialAccount($config);
+    }
+
+    public function share()
+    {
+        return $this->app->jssdk->buildConfig(['updateAppMessageShareData', 'updateTimelineShareData'], true);
+    }
+}

+ 3 - 2
composer.json

@@ -8,6 +8,7 @@
         "php": ">=7.1.3",
         "dingo/api": "^2.2",
         "doctrine/dbal": "^2.9",
+        "guzzlehttp/guzzle": "^6.3",
         "hhxsv5/laravel-s": "~3.4.0",
         "illuminate/redis": "^5.8",
         "intervention/image": "^2.4",
@@ -16,10 +17,10 @@
         "laravel/lumen-framework": "5.8.*",
         "league/fractal": "^0.17.0",
         "multilinguals/apollo-client": "^0.1.2",
+        "overtrue/wechat": "~4.0",
         "predis/predis": "^1.1",
-        "tymon/jwt-auth": "1.0.0-rc.4.1",
-        "guzzlehttp/guzzle": "^6.3",
         "simplesoftwareio/simple-qrcode": "^2.0",
+        "tymon/jwt-auth": "1.0.0-rc.4.1",
         "vlucas/phpdotenv": "^3.3"
     },
     "require-dev": {

+ 2 - 0
config/customer.tpl

@@ -16,4 +16,6 @@ return [
     'find_friend_img' => '{find_friend_img}',
     'suggest_img' => '{suggest_img}',
     'app_upgrade_info' => '{app_upgrade_info}',
+    'wechat_id' => '{wechat_id}',
+    'wechat_secret' => '{wechat_secret}',
 ];

+ 2 - 0
routes/api.php

@@ -36,6 +36,8 @@ $api->version('v1', [
     });
     //公共配置
     $api->get('/config', 'ConfigController@index');
+    //公众号分享
+    $api->get('wechat/share', 'WechatController@share');
 
     //仅验签
     $api->group(['middleware' => 'chxq_sign'], function ($api) {