Selaa lähdekoodia

Merge branch 'develop'

wzq 5 vuotta sitten
vanhempi
commit
9354ddad06

+ 1 - 0
app/Http/Controllers/ConfigController.php

@@ -33,6 +33,7 @@ class ConfigController extends Controller
             'find_friend_img' => config('customer.find_friend_img'),
             'suggest_img' => config('customer.suggest_img'),
             'share_post_bean' => (int) config('customer.share_post_bean'),
+            'share_invite_bean' => (int) config('customer.share_invite_bean'),
         ];
         return $this->jsonSuccess($data, '成功');
     }

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

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use App\Services\WechatService;
+use Illuminate\Support\Facades\Validator;
+
+class WechatController extends Controller
+{
+    public function __construct(WechatService $wechatService)
+    {
+        $this->wechatService = $wechatService;
+    }
+
+    /**
+     * 公众号分享
+     */
+    public function share(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'url' => 'required|string',
+        ]);
+        if ($validator->fails()) {
+            return jsonError($validator->errors()->first());
+        }
+        $res = $this->wechatService->share($request->all());
+        return jsonSuccess(json_decode($res,true));
+    }
+}

+ 30 - 0
app/Services/WechatService.php

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

+ 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) {