Browse Source

feat: 快手相关

xiansin 2 năm trước cách đây
mục cha
commit
78006db6c3

+ 8 - 1
mini/api/user/index.js

xqd
@@ -24,8 +24,15 @@ export async function login() {
       success: loginRes => {
         console.log('-->data', loginRes)
         uni.hideLoading()
+        // #ifdef  MP-KUAISHOU
+        const url = '/auth/kuaishou'
+        // #endif
+        // #ifdef  MP-TOUTIAO
+        const url = '/auth/bytedance'
+        // #endif
+
         return request.post(
-          '/auth/bytedance',
+          url,
           { code: loginRes.code, anonymousCode: loginRes.anonymousCode }
         ).then(res => {
           resolve(res)

+ 1 - 0
mini/pages/login.vue

xqd
@@ -18,6 +18,7 @@ export default {
         const { token, user_info } = res.data
         await this.$store.dispatch('user/token', token)
         await this.$store.dispatch('user/info', user_info)
+        console.log('-->data', this.path)
         uni.reLaunch({
           url: this.path
         })

+ 1 - 1
mini/pages/trace/index.vue

xqd
@@ -38,7 +38,7 @@
           :key="episodeIndex"
           :episode="episode"
           :custom-style="{
-            marginRight: ((index+1) % 3 !== 0 ? '10rpx' :''),
+            marginRight: ((episodeIndex + 1) % 3 !== 0 ? '10rpx' :''),
             width: ((700 - 80) / 3 )+'rpx'
           }"
           :image-style="{

+ 2 - 2
server/app/Admin/Controllers/Episode/EpisodeController.php

xqd
@@ -21,8 +21,8 @@ class EpisodeController extends AdminController
     protected function grid()
     {
         return Grid::make(Episode::with(['category','userEpisodesRecords']), function (Grid $grid) {
-            $grid->model()->orderByDesc('id');
-            $grid->model()->orderByDesc('sort');
+            //$grid->model()->orderByDesc('id');
+            $grid->model()->orderBy('sort');
             $grid->column('id')->sortable();
             $grid->column('sort')->editable()->sortable();
             $grid->column('category.name','分类');

+ 12 - 0
server/app/Admin/Controllers/Setting/PayConfigController.php

xqd xqd
@@ -24,6 +24,12 @@ class PayConfigController extends AdminController
             $grid->column('douyin_app_secret')->display('*****');
             $grid->column('douyin_salt')->display('*****');
             $grid->column('douyin_token')->display('*****');
+
+            $grid->column('kuaishou_app_id')->editable();
+            $grid->column('kuaishou_app_secret')->display('*****');
+            $grid->column('kuaishou_salt')->display('*****');
+            $grid->column('kuaishou_token')->display('*****');
+
             $grid->column('setting.is_watch_auto_pay',trans('setting.fields.is_watch_auto_pay'))->switch();
 
 
@@ -47,6 +53,12 @@ class PayConfigController extends AdminController
             $form->text('douyin_app_secret')->required();
             $form->text('douyin_salt')->required();
             $form->text('douyin_token')->required();
+
+            $form->text('kuaishou_app_id')->required();
+            $form->text('kuaishou_app_secret')->required();
+            $form->text('kuaishou_salt')->required();
+            $form->text('kuaishou_token')->required();
+
             $form->switch('setting.is_watch_auto_pay',trans('setting.fields.is_watch_auto_pay'))->default(0);
 
             $form->disableViewButton();

+ 51 - 167
server/app/Helper/ByteDance.php

xqd xqd xqd xqd xqd
@@ -2,9 +2,8 @@
 
 namespace App\Helper;
 
-use App\Helper\Bytedance\ByteDanceAPI;
-use App\Models\Pay;
-use Carbon\Carbon;
+use App\Helper\UniPlatform\BaseAPI;
+use App\Helper\UniPlatform\BaseUniPlatform;
 use GuzzleHttp\Client;
 use GuzzleHttp\Exception\GuzzleException;
 
@@ -21,107 +20,21 @@ use GuzzleHttp\Exception\GuzzleException;
  * @property-read  string $noticeUrl
  * @property-read  string $validTimestamp
  */
-class ByteDance
+class ByteDance extends BaseUniPlatform
 {
-    private $appId = null;
-    private $secret = null;
-    private $slat = null;
-    private $token = null;
 
-
-    private $accessTokenFile = null;
-    private $accessToken = null;
-    private $noticeUrl = null;
-    //订单过期时间(秒);
-    private $validTimestamp = 24 * 60 * 60;
-
-    /**
-     * @param array $config
-     * @return $this
-     */
-    public function factory($config = [])
-    {
-        $this->appId = $config['app_id'];
-        $this->secret = $config['app_secret'];
-        $this->slat = $config['slat'];
-        $this->token = $config['token'];
-        $this->accessTokenFile = storage_path('app/bytedance/bytedance_access_token.json');
-        $this->accessToken = $this->checkAccessToken();
-
-        $this->noticeUrl = env('APP_URL').'/api/pay/bytedance/notify';
-        return $this;
-    }
-
-    /**
-     * @param string $code
-     * @return array|mixed
-     * @throws \Exception
-     */
-    public function login($code = '')
+    public function __construct(BaseAPI $api)
     {
-        return $this->post(ByteDanceAPI::LOGIN, [
-            'appid'      => $this->appId,
-            'secret'     => $this->secret,
-            'code'       => $code,
-        ]);
-    }
-
-    /**
-     * @param string $sessionKey
-     * @param string $iv
-     * @param string $encrypted
-     * @return array
-     * @throws \Exception
-     */
-    public function decryptData(string $sessionKey, string $iv, string $encrypted): array
-    {
-        $decrypted =  openssl_decrypt(
-            base64_decode($encrypted,true),
-            'AES-128-CBC',
-            base64_decode($sessionKey),
-            OPENSSL_RAW_DATA,
-            base64_decode($iv)
-        );
-        $decrypted = json_decode($decrypted,true);
-        if(empty($decrypted)){
-            throw new \Exception('解密数据错误');
-        }
-
-        return $decrypted;
+        $this->API  = $api;
     }
 
-    /**
-     * 校验access token 是否过期
-     * @return mixed
-     */
-    private function checkAccessToken() : string
-    {
-        try {
-            $dir = storage_path('app/bytedance');
-            if (!is_dir($dir)) mkdir($dir, 0755);
-            if (!is_file($this->accessTokenFile)) touch($this->accessTokenFile);
-
-            $accessToken = file_get_contents($this->accessTokenFile);
-            $accessToken = $accessToken ? json_decode($accessToken,true) : null;
-            if (empty($accessToken) || $accessToken['expires_at'] < time()) {
-                $accessToken = $this->getAccessToken();
-            }else{
-                $accessToken = $accessToken['access_token'];
-            }
-            return $accessToken;
-        } catch (\Exception $e) {
-
-        }
-    }
-
-
     /**
      * 获取 access token
      * @throws \Exception
      */
-    private function getAccessToken() : string
+    protected function getAccessToken() : string
     {
-        $res = $this->post(ByteDanceAPI::ACCESS_TOKEN, [
+        $res = $this->post($this->API::ACCESS_TOKEN, [
             'grant_type' => 'client_credential',
             'appid'      => $this->appId,
             'secret'     => $this->secret,
@@ -138,44 +51,13 @@ class ByteDance
         return $res['access_token'];
     }
 
-    /**
-     * 接口请求
-     *
-     * @param string $uri
-     * @param array  $data
-     * @return array|mixed
-     * @throws \Exception
-     */
-    private function post($uri = '', $data = []) : array
-    {
-        try {
-            $client = new Client();
-            $res = $client->post($uri, [
-                'verify'  => false,
-                'headers' => ['Content-Type' => 'application/json'],
-                'body'    => json_encode($data)
-            ]);
-            $stringBody = (string)$res->getBody();
-            $res = json_decode($stringBody, true);
-
-            if(!empty($res['err_no'])){
-                throw new \Exception("请求字节跳动API接口错误,错误码:{$res['err_no']},错误信息:{$res['err_tips']}");
-            }
-            return $res['data'];
-        } catch (GuzzleException $e) {
-            \Log::error($e->getMessage());
-            throw new \Exception($e->getMessage());
-        }
-    }
-
-
     /**
      * @param $outOrderNo
      * @param $totalAmount
      * @return array|mixed
      * @throws \Exception
      */
-    public function createOrder($outOrderNo, $totalAmount)
+    public function createOrder($outOrderNo, $totalAmount): array
     {
         $data = [
             'app_id'       => $this->appId,
@@ -191,7 +73,7 @@ class ByteDance
         $data['sign'] = $this->getSign($data);
 
         return $this->post(
-            ByteDanceAPI::CREATE_ORDER,
+            $this->API::CREATE_ORDER,
             $data
         );
     }
@@ -245,56 +127,58 @@ class ByteDance
         return sha1(trim(implode('', $filtered)));
     }
 
+
     /**
-     * @param \Closure $closure
-     * @return \Illuminate\Http\JsonResponse
+     * @param string $code
+     * @return array|mixed
      * @throws \Exception
      */
-    public function payNotify(\Closure $closure)
+    public function login($code = ''): array
     {
-        call_user_func($closure, $this->getNoticeData());
-
-        return response()->json($data);
-
-        if ($notify['msg_signature'] !== $this->getNotifySign($notify)) {
-            \Log::error('回调验证错误');
-            $data = [
-                'err_no' => 1,
-                'err_tips' => 'fail'
-            ];
-        } else {
-            $order = json_decode($notify['msg'], true);
-            //处理订单
-            $payId = $order['cp_orderno'];
-
-            $pay = Pay::find($payId);
-            $pay->pay_type = $order['way'];
-            $pay->serial_number = $order['channel_no'];
-            $pay->status = $order['status'] == 'SUCCESS';
-            $pay->pay_dt = Carbon::now()->toDateString();
-            $pay->save();
+        return $this->post($this->API::LOGIN, [
+            'appid'      => $this->appId,
+            'secret'     => $this->secret,
+            'code'       => $code,
+        ]);
+    }
 
+    /**
+     * 接口请求
+     *
+     * @param string $uri
+     * @param array  $data
+     * @return array|mixed
+     * @throws \Exception
+     */
+    protected function post($uri = '', $data = []) : array
+    {
+        try {
+            $client = new Client();
+            $res = $client->post($uri, [
+                'verify'  => false,
+                'headers' => ['Content-Type' => 'application/json'],
+                'body'    => json_encode($data)
+            ]);
+            $stringBody = (string)$res->getBody();
+            $res = json_decode($stringBody, true);
 
-            $data = [
-                'err_no'    => 0,
-                'err_tips'  => 'success'
-            ];
+            if(!empty($res['err_no'])){
+                throw new \Exception("请求字节跳动API接口错误,错误码:{$res['err_no']},错误信息:{$res['err_tips']}");
+            }
+            return $res['data'];
+        } catch (GuzzleException $e) {
+            \Log::error($e->getMessage());
+            throw new \Exception($e->getMessage());
         }
-        return response()->json($data);
     }
 
-    private function getNoticeData()
+    protected function setAccessFileDir(): void
     {
-        $notify = \request()->all();
-        $notify = '{"msg":"{\"appid\":\"tt5b312d8cc40f46b701\",\"cp_orderno\":\"10022082800824490007\",\"cp_extra\":\"\",\"way\":\"2\",\"channel_no\":\"2022082822001477591433078541\",\"channel_gateway_no\":\"\",\"payment_order_no\":\"PCP2022082822540531221069106962\",\"out_channel_order_no\":\"2022082822001477591433078541\",\"total_amount\":1,\"status\":\"SUCCESS\",\"seller_uid\":\"71227862181355706950\",\"extra\":\"\",\"item_id\":\"\",\"paid_at\":1661698458,\"message\":\"\",\"order_id\":\"7136939355201063205\",\"trade_item_list\":null,\"ec_pay_trade_no\":\"NEP2022082822540409483061846962\"}","msg_signature":"804a60e48936b14a739230cef21fe6204427732e","nonce":"78","timestamp":"1661698459","type":"payment"}';
-        //获取订单信息
-        $notify = json_decode($notify,true);
-        \Log::info('抖音支付回调==>'.json_encode($notify,JSON_UNESCAPED_SLASHES));
-
-        if($notify['msg_signature'] !== $this->getNotifySign($notify)){
-            throw new \Exception('签名验证错误');
-        }
+        $this->accessTokenDir = storage_path('app/bytedance');
+    }
 
-        return json_decode($notify['msg'], true);
+    protected function setAccessFilePath(): void
+    {
+        $this->accessTokenFile = storage_path('app/bytedance/bytedance_access_token.json');
     }
 }

+ 106 - 0
server/app/Helper/Kuaishou.php

xqd
@@ -0,0 +1,106 @@
+<?php
+namespace App\Helper;
+use App\Helper\UniPlatform\BaseAPI;
+use App\Helper\UniPlatform\BaseUniPlatform;
+use Carbon\Carbon;
+use GuzzleHttp\Client;
+use GuzzleHttp\Exception\GuzzleException;
+
+/**
+ * Class Kuaishou
+ *
+ * @package App\Helper
+ * @property-read  string $appId
+ * @property-read  string $slat
+ * @property-read  string $secret
+ * @property-read  string $token
+ * @property-read  string $accessTokenFile
+ * @property-read  string $accessToken
+ * @property-read  string $noticeUrl
+ * @property-read  string $validTimestamp
+ */
+class Kuaishou extends BaseUniPlatform
+{
+    public function __construct(BaseAPI $api)
+    {
+        $this->API  = $api;
+    }
+
+    /**
+     * @param string $code
+     * @return array|mixed
+     * @throws \Exception
+     */
+    public function login($code = ''): array
+    {
+        return $this->post($this->API::LOGIN, [
+            'app_id'       => $this->appId,
+            'app_secret'   => $this->secret,
+            'js_code'      => $code,
+        ]);
+    }
+
+
+    protected function createOrder($outOrderNo, $totalAmount): array
+    {
+        // TODO: Implement createOrder() method.
+    }
+
+
+    protected function getAccessToken(): string
+    {
+        $res = $this->post($this->API::ACCESS_TOKEN, [
+            'app_id'      => $this->appId,
+            'app_secret'  => $this->secret,
+            'grant_type'  => 'client_credentials',
+        ]);
+        if (!isset($res['result']) || $res['result'] != 1) {
+            throw new \Exception('获取access token 错误');
+        }
+
+        file_put_contents($this->accessTokenFile, json_encode([
+            'access_token' => $res['access_token'],
+            'expires_at'   => Carbon::now()->timestamp + $res['expires_in']
+        ]));
+
+        return $res['access_token'];
+    }
+
+    protected function setAccessFileDir(): void
+    {
+        $this->accessTokenDir = storage_path('app/kuaishou');
+    }
+
+    protected function setAccessFilePath(): void
+    {
+        $this->accessTokenFile = storage_path('app/kuaishou/kuaishou_access_token.json');
+    }
+
+    /**
+     * @param string $uri
+     * @param array  $data
+     * @return array
+     * @throws \Exception
+     */
+    protected function post($uri = '', $data = []): array
+    {
+        try {
+            $client = new Client();
+            $url = $uri.'?'.http_build_query($data);
+            $res = $client->post($url, [
+                'verify'  => false,
+                'headers' => ['Content-Type' => 'x-www-form-urlencoded'],
+            ]);
+            $stringBody = (string)$res->getBody();
+            $res = json_decode($stringBody, true);
+
+            if(!isset($res['result']) || $res['result'] != 1){
+                throw new \Exception("请求快手API接口错误,错误码:{$res['result']},错误信息:{$res['error_msg']}");
+            }
+            return $res;
+        } catch (GuzzleException $e) {
+            \Log::error($e->getMessage());
+            throw new \Exception($e->getMessage());
+        }
+    }
+}

+ 9 - 0
server/app/Helper/UniPlatform/BaseAPI.php

xqd
@@ -0,0 +1,9 @@
+<?php
+namespace App\Helper\UniPlatform;
+
+abstract class BaseAPI
+{
+    const ACCESS_TOKEN = '';
+    const LOGIN = '';
+    const CREATE_ORDER = '';
+}

+ 146 - 0
server/app/Helper/UniPlatform/BaseUniPlatform.php

xqd
@@ -0,0 +1,146 @@
+<?php
+namespace App\Helper\UniPlatform;
+
+/**
+ * Class ByteDance
+ *
+ * @package App\Helper
+ * @property-read  string $appId
+ * @property-read  string $slat
+ * @property-read  string $secret
+ * @property-read  string $token
+ * @property-read  string $accessTokenDir
+ * @property-read  string $accessTokenFile
+ * @property-read  string $accessToken
+ * @property-read  string $noticeUrl
+ * @property-read  string $validTimestamp
+ * @property-read  BaseAPI $API
+ */
+abstract class BaseUniPlatform
+{
+    protected $appId = null;
+    protected $secret = null;
+    protected $slat = null;
+    protected $token = null;
+
+
+    protected $accessTokenDir = null;
+    protected $accessTokenFile = null;
+    protected $accessToken = null;
+    protected $noticeUrl = null;
+    //订单过期时间(秒);
+    protected $validTimestamp = 24 * 60 * 60;
+
+    protected $API;
+
+    /**
+     * @param array $config
+     * @return $this
+     */
+    public function factory($config = [])
+    {
+        $this->appId = $config['app_id'];
+        $this->secret = $config['app_secret'];
+        $this->slat = $config['slat'];
+        $this->token = $config['token'];
+
+        $this->setAccessFileDir();
+        $this->setAccessFilePath();
+        $this->accessToken = $this->checkAccessToken();
+
+        $this->noticeUrl = env('APP_URL').'/api/pay/bytedance/notify';
+        return $this;
+    }
+
+
+    /**
+     * @param string $sessionKey
+     * @param string $iv
+     * @param string $encrypted
+     * @return array
+     * @throws \Exception
+     */
+    public function decryptData(string $sessionKey, string $iv, string $encrypted): array
+    {
+        $decrypted =  openssl_decrypt(
+            base64_decode($encrypted,true),
+            'AES-128-CBC',
+            base64_decode($sessionKey),
+            OPENSSL_RAW_DATA,
+            base64_decode($iv)
+        );
+        $decrypted = json_decode($decrypted,true);
+        if(empty($decrypted)){
+            throw new \Exception('解密数据错误');
+        }
+
+        return $decrypted;
+    }
+
+
+
+    /**
+     * 校验access token 是否过期
+     * @return mixed
+     */
+    protected function checkAccessToken()
+    {
+        try {
+            $dir = $this->accessTokenDir;
+            if (!is_dir($dir)) mkdir($dir, 0755);
+            if (!is_file($this->accessTokenFile)) touch($this->accessTokenFile);
+
+            $accessToken = file_get_contents($this->accessTokenFile);
+            $accessToken = $accessToken ? json_decode($accessToken,true) : null;
+            if (empty($accessToken) || $accessToken['expires_at'] < time()) {
+                $accessToken = $this->getAccessToken();
+            }else{
+                $accessToken = $accessToken['access_token'];
+            }
+            return $accessToken;
+        } catch (\Exception $e) {
+
+        }
+    }
+
+
+    /**
+     * 登陆
+     * @param $code
+     * @return array
+     */
+    protected abstract function login($code): array ;
+
+    /**
+     * 接口请求
+     * @param string $uri
+     * @param array  $data
+     * @return array
+     */
+    protected abstract function post($uri = '', $data = []): array ;
+
+    /**
+     * 获取Access token
+     * @return string
+     */
+    protected abstract function getAccessToken(): string ;
+
+
+    /**
+     * 创建支付订单
+     * @param $outOrderNo
+     * @param $totalAmount
+     * @return array
+     */
+    protected abstract function createOrder($outOrderNo, $totalAmount): array ;
+
+    /**
+     * 设置 access token 目录
+     */
+    protected abstract function setAccessFileDir(): void;
+
+    /**
+     * 设置 access token路径
+     */
+    protected abstract function setAccessFilePath(): void;
+}

+ 4 - 2
server/app/Helper/Bytedance/ByteDanceAPI.php → server/app/Helper/UniPlatform/Bytedance/ByteDanceAPI.php

xqd
@@ -1,9 +1,11 @@
 <?php
-namespace App\Helper\Bytedance;
+namespace App\Helper\UniPlatform\Bytedance;
+
+use App\Helper\UniPlatform\BaseAPI;
 
 define('BASE_URL','https://developer.toutiao.com/api/apps/v2');
 define('PAY_URL','https://developer.toutiao.com/api/apps');
-final class ByteDanceAPI
+final class ByteDanceAPI extends BaseAPI
 {
 
 

+ 1 - 1
server/app/Helper/Bytedance/Payment.php → server/app/Helper/UniPlatform/Bytedance/Payment.php

xqd
@@ -1,6 +1,6 @@
 <?php
 
-namespace App\Helper\Bytedance;
+namespace App\Helper\UniPlatform\Bytedance;
 
 use App\Helper\ByteDance;
 use App\Models\Pay;

+ 29 - 0
server/app/Helper/UniPlatform/Kuaishou/KuaishouAPI.php

xqd
@@ -0,0 +1,29 @@
+<?php
+namespace App\Helper\UniPlatform\Kuaishou;
+
+use App\Helper\UniPlatform\BaseAPI;
+define('BASE_URL','https://open.kuaishou.com/oauth2');
+define('PAY_URL','https://open.kuaishou.com/openapi/mp/developer');
+
+final class KuaishouAPI extends BaseAPI
+{
+
+
+    /**
+     * 获取 ACCESS_TOKEN
+     * @url https://mp.kuaishou.com/docs/develop/server/getAccessToken.html
+     */
+    const ACCESS_TOKEN = BASE_URL.'/access_token';
+
+    /**
+     * 登陆
+     * @url https://mp.kuaishou.com/docs/develop/server/code2Session.html
+     */
+    const LOGIN = BASE_URL.'/mp/code2session';
+
+    /**
+     * 支付下单
+     * @url https://mp.kuaishou.com/docs/develop/server/epay/interfaceDefinition.html
+     */
+    const CREATE_ORDER = PAY_URL.'/epay/create_order';
+}

+ 42 - 1
server/app/Http/Controllers/V1/AuthController.php

xqd xqd
@@ -163,7 +163,7 @@ class AuthController extends Controller
     {
         try {
             $code = $request->input('code');
-            $app = $this->getByteDanceFactory();
+            $app = $this->getUniFactory();
             $res = $app->login($code);
 
             $openId = $res['openid'];
@@ -200,6 +200,47 @@ class AuthController extends Controller
         }
     }
 
+    // 快手登陆 code
+    public function kuaishou(Request $request)
+    {
+        try {
+            $code = $request->input('code');
+            $app = $this->getUniFactory(2);
+            $res = $app->login($code);
+
+            $openId = $res['open_id'];
+            $user = User::where('open_id', $openId)->first();
+            if (!$user) {
+                $user = new User();
+                $user->open_id = $openId;
+                $user->union_id = ''; // 没有 union_id
+                $user->remember_token = $res['session_key'];
+                $user->save();
+
+                $info = new UserInfo();
+                $info->user_id = $user->id;
+                $info->platform = 2;
+                $info->save();
+
+                $user = User::where('id', $user->id)->first();
+            }else{
+                $user->remember_token = $res['session_key'];
+                $user->save();
+            }
+
+            $token = Auth::guard('api')->fromUser($user);
+            $user = User::with(['info'])->where('id', $user->id)->first();
+            $data = [
+                'token' => "Bearer " . $token,
+                'user_info' => $user,
+            ];
+            return $this->success($data);
+        } catch (\Exception $e) {
+            ErrorMsgServive::write($e, \request()->url());
+            return $this->error('快手授权登陆出错');
+        }
+    }
+
     //执行登录
     public function doLogin($user, $jpush_reg_id = null)
     {

+ 28 - 1
server/app/Http/Controllers/V1/Controller.php

xqd xqd xqd
@@ -3,6 +3,9 @@
 namespace App\Http\Controllers\V1;
 
 use App\Helper\ByteDance;
+use App\Helper\Kuaishou;
+use App\Helper\UniPlatform\Bytedance\ByteDanceAPI;
+use App\Helper\UniPlatform\Kuaishou\KuaishouAPI;
 use App\Models\PayConfig;
 use Dingo\Api\Routing\Helpers;
 use Illuminate\Foundation\Bus\DispatchesJobs;
@@ -59,10 +62,23 @@ class Controller extends BaseController
         return response()->json($result);
     }
 
+    /**
+     * @param int $platform
+     * @return ByteDance|Kuaishou
+     */
+    protected function getUniFactory($platform = 1)
+    {
+        if($platform == 1){
+            return $this->getByteDanceFactory();
+        }
+
+        return $this->getKuishouFactory();
+    }
+
     protected function getByteDanceFactory()
     {
         $setting = PayConfig::first();
-        return (new ByteDance())->factory([
+        return (new ByteDance(app(ByteDanceAPI::class)))->factory([
             'app_id'     => $setting->douyin_app_id,
             'app_secret' => $setting->douyin_app_secret,
             'slat'       => $setting->douyin_salt,
@@ -70,4 +86,15 @@ class Controller extends BaseController
         ]);
     }
 
+    protected function getKuishouFactory()
+    {
+        $setting = PayConfig::first();
+        return (new Kuaishou(app(KuaishouAPI::class)))->factory([
+            'app_id'     => $setting->kuaishou_app_id,
+            'app_secret' => $setting->kuaishou_app_secret,
+            'slat'       => $setting->kuaishou_salt,
+            'token'      => $setting->kuaishou_token,
+        ]);
+    }
+
 }

+ 0 - 1
server/app/Http/Controllers/V1/EpisodeController.php

xqd
@@ -128,7 +128,6 @@ class EpisodeController extends Controller
         $offset = ($page - 1) * $limit;
         $episodes = Episode::withCount(['lists'])
             ->where('is_opend', 1)
-            ->where('sort', '<>',0)
             ->where('platform', \user()->info->platform)
             //->inRandomOrder()
             ->orderBy('sort')

+ 0 - 4
server/app/Http/Controllers/V1/PayController.php

xqd
@@ -7,10 +7,6 @@ use App\Models\Pay;
 
 class PayController extends Controller
 {
-    public function bytedance()
-    {
-        $app = $this->getByteDanceFactory();
-    }
 
     public function query($payId)
     {

+ 7 - 2
server/app/Http/Controllers/V1/PayNoticeController.php

xqd xqd xqd
@@ -3,7 +3,7 @@
 namespace App\Http\Controllers\V1;
 
 
-use App\Helper\Bytedance\Payment;
+use App\Helper\UniPlatform\Bytedance\Payment as BytedancePayment;
 use App\Models\Pay;
 use App\Models\UserConsumeRecord;
 use App\Models\UserInfo;
@@ -15,7 +15,7 @@ class PayNoticeController extends Controller
 {
     public function bytedance()
     {
-        $app = new Payment($this->getByteDanceFactory());
+        $app = new BytedancePayment($this->getUniFactory());
         return $app->payNotify(function ($data, $fail) {
             //处理支付订单
             try {
@@ -46,6 +46,11 @@ class PayNoticeController extends Controller
         });
     }
 
+    public function kuaishou()
+    {
+
+    }
+
     private function recharge($payId)
     {
         /* @var UserRechargeRecord $record */

+ 1 - 1
server/app/Http/Controllers/V1/User/RechargeController.php

xqd
@@ -38,7 +38,7 @@ class RechargeController extends Controller
         try {
             \DB::beginTransaction();
             $comboId = \request()->input('id');
-            $app = $this->getByteDanceFactory();
+            $app = $this->getUniFactory(\user()->info->platform);
             $combo = RechargeCombo::find($comboId);
 
             // 避免重复创建订单

+ 1 - 1
server/app/Http/Controllers/V1/User/VipController.php

xqd
@@ -30,7 +30,7 @@ class VipController extends Controller
         try {
             \DB::beginTransaction();
             $comboId = \request()->input('id');
-            $app = $this->getByteDanceFactory();
+            $app = $this->getUniFactory(\user()->info->platform);
             $combo = VipCombo::find($comboId);
 
             // 避免重复创建订单

+ 1 - 1
server/app/Http/Controllers/V1/UserController.php

xqd
@@ -93,7 +93,7 @@ class UserController extends Controller
         try
         {
             $req = $request->all();
-            $app = $this->getByteDanceFactory();
+            $app = $this->getUniFactory(\user()->info->platform);
 
             $res = $app->login($req['code']);
 

+ 8 - 0
server/app/Models/PayConfig.php

xqd
@@ -55,6 +55,14 @@ use Illuminate\Database\Eloquent\Model;
  * @property string|null $douyin_token 抖音TOKEN
  * @method static \Illuminate\Database\Eloquent\Builder|PayConfig whereDouyinSalt($value)
  * @method static \Illuminate\Database\Eloquent\Builder|PayConfig whereDouyinToken($value)
+ * @property string $kuaishou_app_id 快手_APP_ID
+ * @property string|null $kuaishou_app_secret 快手_应用私钥
+ * @property string|null $kuaishou_salt 快手SALT
+ * @property string|null $kuaishou_token 快手TOKEN
+ * @method static \Illuminate\Database\Eloquent\Builder|PayConfig whereKuaishouAppId($value)
+ * @method static \Illuminate\Database\Eloquent\Builder|PayConfig whereKuaishouAppSecret($value)
+ * @method static \Illuminate\Database\Eloquent\Builder|PayConfig whereKuaishouSalt($value)
+ * @method static \Illuminate\Database\Eloquent\Builder|PayConfig whereKuaishouToken($value)
  */
 class PayConfig extends Model
 {

+ 5 - 0
server/resources/lang/zh/pay-config.php

xqd
@@ -20,6 +20,11 @@ return [
         'douyin_app_secret' => '抖音 SECRET',
         'douyin_salt' => '抖音SALT',
         'douyin_token' => '抖音TOKEN',
+        'kuaishou_app_id' => '快手 APPID',
+        'kuaishou_app_key' => '快手 APPKEY',
+        'kuaishou_app_secret' => '快手 SECRET',
+        'kuaishou_salt' => '快手SALT',
+        'kuaishou_token' => '快手TOKEN',
     ],
     'options' => [
     ],

+ 2 - 1
server/routes/api.php

xqd
@@ -39,7 +39,8 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api)
         $api->post('h5_oauth', 'AuthController@h5Oauth'); //H5授权登录
         $api->post('mini_program', 'AuthController@miniProgram'); //微信小程序登录(微信)
         $api->get('mini_code', 'AuthController@miniCode'); //获取微信小程序 code
-        $api->post('bytedance', 'AuthController@bytedance'); //获取微信小程序 code
+        $api->post('bytedance', 'AuthController@bytedance'); //获取字节跳动小程序 code
+        $api->post('kuaishou', 'AuthController@kuaishou'); //获取快手小程序 code
 
     });