Browse Source

社媒对接

moshaorui 2 days ago
parent
commit
cf543713a7

+ 90 - 38
app/Console/Commands/TimerSsmPost.php

@@ -36,38 +36,23 @@ class TimerSsmPost extends Command
 
     public function handle()
     {
-        // 发送社媒帖子
-        $waitPost = SmmPost::getWaitPost();
-        foreach ($waitPost as $post) {
-            //插入post_logs表
-            $accountIds = explode(',', $post->account_ids);
-            $accounts = SmmUserAccount::getAccountsByIds($accountIds);
-            foreach ($accounts as $account) {
-                //生成post_logs表数据
-                $data = [
-                    'post_id' => $post->id,
-                    'account_id' => $account->id,
-                    'account_name' => $account->name,
-                    'status' => 0,
-                    'remark' => '',
-                    'created_at' => Carbon::now(),
-                    'updated_at' => Carbon::now(),
-                    'dist_id' => $account->dist_id,
-                    'media_name' => $account->getParent->name,
-                    'response_ids'=> '',
-                    'send_time' => $post->send_time,
-                ];
-                SmmPostLog::createLog($data);
-            }
-            $post->status = 1;
-            $post->save();
-        }
+        //创建日志
+        $this->createLog();
 
-        //dd('middle');
+        //刷新access_token
+        $this->refreshAccessToken();
+        exit;
 
         //发送社媒帖子开始
-        $sendLog = SmmPostLog::getSendLog();
+        $sendLog = SmmPostLog::getSendLog(5);
+        $logIds = [];
         foreach ($sendLog as $log) {
+            if ($log->media_name == 'twitter' && SmmPostLog::twitterCanSend() == false) {
+                //15分钟内不重复发送
+                    echo 'twitter可发送时间未到,暂时无法发送,ID'.$log->post_id;
+                    continue;
+            }
+            $logIds[] = $log->id;
             //获取帖子内容
             $post = SmmPost::getPostById($log->post_id);
             $message = $post->message;
@@ -89,16 +74,7 @@ class TimerSsmPost extends Command
             } else {
                 $imageVideoUrl = CommonHelper::ossUrl($imageVideoUrl);
                 $response = $ssmService->postVideo($message, $imageVideoUrl,$accessToken);
-
-//                $response = $ssmService->postVideo([
-//                    'title' => 'Test Video',
-//                    'description' => 'This is a test video111',
-//                    'categoryId' => '22', // People & Blogs
-//                    'privacyStatus' => 'private'
-//                ], '/mnt/hgfs/wwwroot/mtb_dcatadmin_plus/1.mp4', $accessToken);
-
             }
-
             //更新post_logs表
             if ($response['status'] == true) {
                 $log->status = 1;
@@ -114,7 +90,83 @@ class TimerSsmPost extends Command
                 $log->save();
             }
         }
-        dd('发送社媒帖子完成');
+
+        $logIds = print_r($logIds);
+        dd('发送社媒帖子完成'.$logIds);
+    }
+
+    /*
+     * access_token 过期重新获取
+     * 1.Facebook 有效期60天,要手动重新获取
+     * 2.Instagram 与 Facebook 一样
+     * YouTube 有效期为 3600 秒,提前 10 分钟更新 access_token
+     * Twitter 好像是过期
+     */
+
+
+    public function refreshAccessToken()
+    {
+        $accounts = SmmUserAccount::getAllYouTubeUserAccounts();
+        foreach ($accounts as $account) {
+            try {
+                $expiresAt = Carbon::parse($account->expires_at);
+                if ($expiresAt->diffInSeconds(Carbon::now()) <= 3000) {
+                    $mediaName = $account->getParent->name;
+                    $configData = ['accountInfo' => $account->toArray()];
+
+                    $ssmService = new SmmService($mediaName, $configData);
+                    $result = $ssmService->refreshAccessToken($account->refresh_token);
+
+                    $account->update([
+                        'access_token' => $result['data']['access_token'],
+                        'expires_at' => Carbon::parse($result['data']['expires_at']->format('Y-m-d H:i:s')),
+                        'refresh_token' => $result['data']['refresh_token'],
+                    ]);
+
+                    echo 'access_token 刷新成功:'. $account->name. "\n";
+                }
+            } catch (\Exception $e) {
+                continue;
+            }
+        }
+    }
+
+    /*
+     * 生成发送帖子日志
+     */
+    public function createLog()
+    {
+        // 发送社媒帖子
+        $waitPost = SmmPost::getWaitPost();
+        foreach ($waitPost as $post) {
+            //插入post_logs表
+            $accountIds = explode(',', $post->account_ids);
+            $accounts = SmmUserAccount::getAccountsByIds($accountIds);
+            foreach ($accounts as $account) {
+                $send_time = $post->send_time;
+                // 如果是Twitter,15分钟内只能发一个帖
+                if ($account->getParent->name == 'Twitter') {
+                    $send_time = SmmPostLog::getTwitterSendTime($send_time);
+                }
+                //生成post_logs表数据
+                $data = [
+                    'post_id' => $post->id,
+                    'account_id' => $account->id,
+                    'account_name' => $account->name,
+                    'status' => 0,
+                    'remark' => '',
+                    'created_at' => Carbon::now(),
+                    'updated_at' => Carbon::now(),
+                    'dist_id' => $account->dist_id,
+                    'media_name' => $account->getParent->name,
+                    'response_ids'=> '',
+                    'send_time' => $send_time,
+                ];
+                SmmPostLog::createLog($data);
+            }
+            $post->status = 1;
+            $post->save();
+        }
     }
 
 }

+ 40 - 23
app/Distributor/Controllers/SmmPostController.php

@@ -4,6 +4,7 @@ namespace App\Distributor\Controllers;
 
 use App\Admin\Repositories\BaseProductImage;
 use App\Distributor\Repositories\SmmPost;
+use App\Distributor\Repositories\SmmPostLog;
 use App\Distributor\Repositories\SmmUserAccount;
 use App\Services\SmmService;
 use Carbon\Carbon;
@@ -17,6 +18,7 @@ use Dcat\Admin\Admin;
 use Dcat\Admin\FormStep\Form as StepForm;
 use Dcat\Admin\Traits\HasUploadedFile;
 use Dcat\Admin\Widgets\Alert;
+use App\Console\Commands\TimerSsmPost;
 
 class SmmPostController extends AdminDistController
 {
@@ -27,12 +29,8 @@ class SmmPostController extends AdminDistController
      */
     public function index(Content $content)
     {
-//        $ssmService = new SmmService('youtube');
-//        $videoCategories = $ssmService->getVideoCategories();
-//        var_dump($videoCategories['data']);
-//        exit;
         return $content
-            ->header('发报帖子')
+            ->header(admin_trans_label('send_post'))
             ->body($this->form());
     }
 
@@ -61,8 +59,9 @@ class SmmPostController extends AdminDistController
                                 ->autoUpload() // 自动上传
                                 ->uniqueName()
                                 ->limit(4)
-                                ->accept(config('admin.upload.oss_image.accept'))
-                                ->maxSize(config('admin.upload.oss_image.max_size'));
+                                ->accept('jpg,png')
+                                ->help('图片格式jpg,png,不大于3M')
+                                ->maxSize(3072);
                         })
                         ->when([1], function ($step)  {
                             $step->textarea('video_message', '<span style="color:#bd4147;">*</span> '.admin_trans_label('post_message'))->rows(3)->placeholder(' ');
@@ -70,8 +69,8 @@ class SmmPostController extends AdminDistController
                                 ->uniqueName()
                                 ->autoUpload()
                                 ->accept(config('admin.upload.oss_video.accept'))
-                                ->maxSize(config('admin.upload.oss_video.max_size'))
-                                ->chunkSize(1024);
+                                ->maxSize(120400)
+                                ->removable();
                         })
                         ->options([ 0=>admin_trans_label('images'), 1=>admin_trans_label('videos')])->default(0);
                     $this->stepLeaving($step,0);
@@ -80,7 +79,10 @@ class SmmPostController extends AdminDistController
                     $rootAccounts = SmmUserAccount::getUserAccounts();
                     $listBoxOptions = [];
                     foreach ($rootAccounts as $account) {
-                        $listBoxOptions[$account->id] = $account->name . ' ('.$account->getParent->name.')';
+                        if (SmmPostLog::getPostQuota($account->getParent->name) > 0) {
+                            //限额大于0才显示
+                            $listBoxOptions[$account->id] = $account->name . ' ('.$account->getParent->name.')';
+                        }
                     }
                     $step->listbox('account_ids', '<span style="color:#bd4147;">*</span> '.admin_trans_label('accountsSelect'))
                         ->options($listBoxOptions);
@@ -96,6 +98,12 @@ class SmmPostController extends AdminDistController
      */
     public function store() {
         $post = $_POST;
+        if (isset($post['_file_del_'])) {
+            // 删除上传的文件
+            header('Content-Type: application/json');
+            echo json_encode(['status' => true, 'data' => []]);
+            exit;
+        }
         if (isset($post['upload_column']) && ($post['upload_column'] == 'image_url' || $post['upload_column'] == 'video_url')) {
             // 上传图片或视频
             return $this->upload();
@@ -120,6 +128,9 @@ class SmmPostController extends AdminDistController
             }
             //保存数据
             SmmPost::create($post,$send_time,$image_video_url);
+            // 生成发送记录
+            $timer = new TimerSsmPost();
+            $timer->createLog();
             //最后一步
             $data = [
                 'title'       => '操作成功',
@@ -134,20 +145,25 @@ class SmmPostController extends AdminDistController
      * 上传图片到本地
      */
     public function upload() {
-        // 获取上传的文件
-        $file = $this->file();
-        $dir = 'ssm/'.getDistributorId();
-        $newName = md5(uniqid() . mt_rand()) .'.'.$file->getClientOriginalExtension();
-        //保存到本地
-        $disk = $this->disk('local');
-        $result = $disk->putFileAs($dir, $file, $newName);
+        try {
+            // 获取上传的文件
+            $file = $this->file();
+            $dir = 'ssm/'.getDistributorId();
+            $newName = md5(uniqid() . mt_rand()) .'.'.$file->getClientOriginalExtension();
+            //保存到本地
+            $disk = $this->disk('local');
+            $result = $disk->putFileAs($dir, $file, $newName);
+
+            //oss 保存
+            $disk = $this->disk('oss');
+            $result = $disk->putFileAs($dir, $file, $newName);
 
-        //oss 保存
-        $disk = $this->disk('oss');
-        $result = $disk->putFileAs($dir, $file, $newName);
-        return $result
-            ? $this->responseUploaded($result, $disk->url($result))
-            : $this->responseErrorMessage(admin_trans_label('upload_failed'));
+            return $result
+                ? $this->responseUploaded($result, $disk->url($result))
+                : $this->responseErrorMessage(admin_trans_label('upload_failed'));
+        } catch (\Exception $e) {
+            return $this->responseErrorMessage($e->getMessage());
+        }
     }
 
     /*
@@ -261,6 +277,7 @@ let intervalId = setInterval(() => {
         checkYouTubeOption(select);
     }
 }, 300);
+
 JS
         );
 

+ 25 - 58
app/Distributor/Controllers/SmmPostLogController.php

@@ -2,6 +2,7 @@
 
 namespace App\Distributor\Controllers;
 
+use App\Distributor\Repositories\RpcAlbum;
 use App\Distributor\Repositories\SmmPostLog;
 use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
@@ -18,9 +19,8 @@ class SmmPostLogController extends AdminController
     public function index(Content $content)
     {
         return $content
-            ->header('列表')
-            ->description('全部')
-            ->breadcrumb(['text'=>'列表','url'=>''])
+            ->header(admin_trans_label('post_log'))
+            ->description()
             ->body($this->grid());
     }
 
@@ -31,73 +31,40 @@ class SmmPostLogController extends AdminController
      */
     protected function grid()
     {
-        return Grid::make(new SmmPostLog(), function (Grid $grid) {
+        return Grid::make(SmmPostLog::with(['post', 'account']), function (Grid $grid) {
             $grid->column('id')->sortable();
-            $grid->column('post_id');
-            $grid->column('account_id');
-            $grid->column('status');
-            $grid->column('remark');
-            $grid->column('dist_id');
-            $grid->column('request_content');
-            $grid->column('response_content');
-            $grid->column('media_name');
-            $grid->column('response_ids');
+            $grid->column('account.name', admin_trans_label('account_name'));
+            $grid->column('media_name',admin_trans_label('media_name'));
+            $grid->column('post.message',admin_trans_label('post_message'))->width('30%');
             $grid->column('created_at');
-            $grid->column('updated_at')->sortable();
-
-            $grid->filter(function (Grid\Filter $filter) {
-                $filter->equal('id');
-
-            });
+            $grid->column('status')->using(admin_trans_array(config('dictionary.post_log_status')))->label([
+                0 => 'gray',
+                1 => 'success',
+                2 => 'orange1',
+            ]);
+            $grid->column('remark')->width('15%');
+            $grid->column('send_time', admin_trans_label('etd'))->sortable();
+            $grid->disableRowSelector();
+            $grid->disableCreateButton();
+            $grid->disableDeleteButton();
+            $grid->disableEditButton();
         });
     }
 
-    /**
-     * Make a show builder.
-     *
-     * @param mixed $id
-     *
-     * @return Show
-     */
     protected function detail($id)
     {
-        return Show::make($id, new SmmPostLog(), function (Show $show) {
+        return Show::make($id, SmmPostLog::with(['post', 'account']), function (Show $show) {
             $show->field('id');
-            $show->field('post_id');
-            $show->field('account_id');
-            $show->field('status');
+            $show->field('account.name', admin_trans_label('account_name'));
+            $show->field('media_name',admin_trans_label('media_name'));
+            $show->field('post.message',admin_trans_label('post_message'));
             $show->field('remark');
-            $show->field('dist_id');
-            $show->field('request_content');
-            $show->field('response_content');
-            $show->field('media_name');
-            $show->field('response_ids');
+            $show->field('send_time', admin_trans_label('etd'));
             $show->field('created_at');
-            $show->field('updated_at');
+            $show->field('status')->using(admin_trans_array(config('dictionary.post_log_status')));
+            $show->disableDeleteButton();
         });
     }
 
-    /**
-     * Make a form builder.
-     *
-     * @return Form
-     */
-    protected function form()
-    {
-        return Form::make(new SmmPostLog(), function (Form $form) {
-            $form->display('id');
-            $form->text('post_id');
-            $form->text('account_id');
-            $form->text('status');
-            $form->text('remark');
-            $form->text('dist_id');
-            $form->text('request_content');
-            $form->text('response_content');
-            $form->text('media_name');
-            $form->text('response_ids');
 
-            $form->display('created_at');
-            $form->display('updated_at');
-        });
-    }
 }

+ 21 - 0
app/Distributor/Controllers/SmmUserAccountController.php

@@ -3,6 +3,7 @@
 namespace App\Distributor\Controllers;
 
 use App\Distributor\Actions\SmmAddAccount;
+use App\Distributor\Repositories\SmmPostLog;
 use App\Distributor\Repositories\SmmUserAccount;
 use App\Services\SmmService;
 use Carbon\Carbon;
@@ -57,6 +58,8 @@ class SmmUserAccountController extends AdminDistController
             $grid->column('account_id');
             $grid->column('expires_at');
             $grid->column('created_at')->sortable();
+
+
             $grid->column('status')->display(function ($name) {
                 if ($this->parent_id > 0) {
                     //如果当前时间大于过期时间,则显示过期
@@ -67,6 +70,24 @@ class SmmUserAccountController extends AdminDistController
                     }
                 }
             });
+
+            $grid->column('quota_explanation', admin_trans_label('quota_explanation'))->display(function ($name) {
+                if ($this->parent_id == 0) {
+                    $quota = SmmPostLog::getPostQuota($this->name);
+                    if ($this->name == 'Twitter') {
+                        return admin_trans_label('twitter_quota_explanation',['quota'=>$quota]);
+                    } else if ($this->name == 'YouTube'){
+                        return admin_trans_label('youtube_quota_explanation',['quota'=>$quota]);
+                    } else if ($this->name == 'Facebook') {
+                        return admin_trans_label('facebook_quota_explanation',['quota'=>$quota]);
+                    } else if ($this->name == 'Instagram') {
+                        return admin_trans_label('instagram_quota_explanation',['quota'=>$quota]);
+                    } else {
+                        return admin_trans_label('-');
+                    }
+                }
+            })->width('30%');
+
             $grid->filter(function (Grid\Filter $filter) {
                 $filter->panel();
                 $filter->expand();

+ 91 - 2
app/Distributor/Repositories/SmmPostLog.php

@@ -15,6 +15,8 @@ class SmmPostLog extends EloquentRepository
      */
     protected $eloquentClass = Model::class;
 
+
+
     /*
      * 创建日志
      */
@@ -38,11 +40,98 @@ class SmmPostLog extends EloquentRepository
     /*
      * 找状态为0并且发送时间小于当前时间的日志
      */
-    public static function getSendLog()
+    public static function getSendLog($limit = 5)
     {
         $log = new Model();
-        $logs = $log->where('status', 0)->where('send_time', '<', Carbon::now())->get();
+        $logs = $log->where('status', 0)->where('send_time', '<', Carbon::now())->limit($limit)->get();
         return $logs;
     }
 
+
+    /*
+     * 计算Twitter月配额,每月只能发送100个帖子,(只限发送帖子,其他接口,每个用户1个请求,15分钟内只允许发送一次)
+     *
+     */
+    public static function getPostQuota($mediaName = 'Twitter')
+    {
+        $log = new Model();
+
+        if ($mediaName === 'Twitter') {
+            // 获取当月第一天 00:00:00 的时间戳
+            $startOfMonth = Carbon::now()->startOfMonth();
+
+            $count = $log->where('media_name', 'Twitter')
+                ->where('created_at', '>=', $startOfMonth->format('Y-m-d H:i:s'))
+                ->count();
+
+            return 100 - $count;
+
+        } elseif ($mediaName === 'YouTube') {
+            // 获取当天 00:00:00 的时间戳
+            $startOfDay = Carbon::now()->startOfDay();
+
+            $count = $log->where('media_name', 'YouTube')
+                ->where('created_at', '>=', $startOfDay->format('Y-m-d H:i:s'))
+                ->count();
+
+            // 计算可用配额(向下取整)
+            $quota = floor((10000 - 1600 * $count) / 1600);
+            return max($quota, 0); // 保证最小返回0
+
+        } else {
+            return 999;
+        }
+    }
+
+
+
+    /*
+     * 返回Twitter可以发送的时间
+     */
+    public static function getTwitterSendTime($sendTime)
+    {
+        // 将字符串转换为Carbon实例
+        $sendTimeCarbon = Carbon::parse($sendTime);
+
+        $log = new Model();
+        $query = $log->where('status', 0)
+            ->whereBetween('send_time', [
+                $sendTimeCarbon->copy()->subMinutes(15),
+                $sendTimeCarbon
+            ])
+            ->orderByDesc('send_time')
+            ->first();
+
+        if ($query) {
+            // 返回格式化的时间字符串(与原输入格式保持一致)
+            $query_send_time = Carbon::parse($query->send_time);
+            return $query_send_time
+                ->addMinutes(15)
+                ->toDateTimeString();
+        }
+        // 没有记录时返回原始字符串
+        return $sendTime;
+    }
+
+    /*
+     * 判断是否可以发送
+     *
+     */
+    public static function twitterCanSend()
+    {
+        $log = new Model();
+        //查找最后一条发送记录
+        $lastSendLog = $log->where('status', 1)->where('media_name', 'Twitter')->orderByDesc('send_time')->first();
+        //如果时间间隔小于15分钟,则不允许发送
+        if ($lastSendLog) {
+            $lastSendTime = Carbon::parse($lastSendLog->send_time);
+            $nowTime = Carbon::now();
+            $diffTime = $nowTime->diffInMinutes($lastSendTime);
+            if ($diffTime <= 15) {
+                return false;
+            }
+        }
+        return true;
+    }
+
 }

+ 11 - 0
app/Distributor/Repositories/SmmUserAccount.php

@@ -81,6 +81,17 @@ class SmmUserAccount extends EloquentRepository
         return $accounts;
     }
 
+    /*
+     *  查找所有用户账号
+     */
+    public static function getAllYouTubeUserAccounts()
+    {
+        $model = new Model();
+        $youTube = $model->where('name', 'YouTube')->first();
+        $accounts = $model->where('parent_id','=',$youTube->id)->where('expires_at','>', Carbon::now())->orderBy('id', 'asc')->get();
+        return $accounts;
+    }
+
     /*
      *  查找所有用户账号
      */

+ 3 - 0
app/Distributor/routes.php

@@ -80,6 +80,9 @@ Route::group([
     $router->get('ssm-user-account', 'SmmUserAccountController@index');
     //社媒传单管理
     $router->resource('ssm-post', 'SmmPostController');
+    //社媒传单日志
+    $router->get('ssm-post-log', 'SmmPostLogController@index');
+    $router->get('ssm-post-log/{id}', 'SmmPostLogController@show');
     //社媒回调
     $router->get('callback/{name}', 'SmmUserAccountController@callback');
 });

+ 7 - 0
app/Models/SmmPostLog.php

@@ -11,6 +11,13 @@ class SmmPostLog extends Model
 	use HasDateTimeFormatter;
     protected $table = 'smm_post_log';
 
+    public function account()
+    {
+        return $this->hasOne(SmmUserAccount::class,'id','account_id');
+    }
 
+    public function post() {
+        return $this->hasOne(SmmPost::class,'id','post_id');
+    }
 
 }

+ 29 - 36
app/Services/Smm/TwitterService.php

@@ -140,7 +140,6 @@ class TwitterService implements SmmPlatformInterface
                 throw new Exception("Video file does not exist or is not readable: $videoPath");
             }
 
-
             // Upload video with chunked upload
             $uploadedMedia = $this->twitterOAuth->upload('media/upload', [
                 'media' => $videoPath,
@@ -154,43 +153,37 @@ class TwitterService implements SmmPlatformInterface
             }
 
             $mediaId = $uploadedMedia->media_id_string;
+            print_r($mediaId);
+
+            $limit = 0;
+            do {
+                $status = $this->twitterOAuth->mediaStatus($mediaId);
+                print_r($status);
+                sleep(5); // 等待 5 秒
+                $limit++;
+            } while ($status->processing_info->state !== 'succeeded' && $limit <= 3); // 最多重试 3 次
+
+            if ($status->processing_info->state === 'succeeded') {
+                print_r($status->processing_info->state);
+                // 2.0版本发布推文
+                $this->twitterOAuth->setApiVersion('2');
+                $tweet = $this->twitterOAuth->post('tweets', [
+                    'text' => $message,
+                    'media' => ['media_ids' => [$mediaId]]
+                ]);
 
-
-            // 检查媒体处理状态
-            $processingInfo = $uploadedMedia->processing_info ?? null;
-            if ($processingInfo && $processingInfo->state === 'pending') {
-                $checkAfter = $processingInfo->check_after_secs;
-                sleep($checkAfter);
-                do {
-                    $status = $this->twitterOAuth->get("media/upload", [
-                        'command' => 'STATUS',
-                        'media_id' => $mediaId
-                    ]);
-                    dd($status);
-                    if (isset($status->error)) {
-                        throw new \Exception("媒体状态检查失败: " . json_encode($status));
-                    }
-                    $processingInfo = $status->processing_info ?? null;
-                    if (!$processingInfo || $processingInfo->state === 'failed') {
-                        throw new \Exception("媒体处理失败: " . json_encode($status));
-                    }
-                    if ($processingInfo->state !== 'succeeded') {
-                        sleep($processingInfo->check_after_secs ?? 5);
-                    }
-                } while ($processingInfo->state !== 'succeeded');
+                if ($this->twitterOAuth->getLastHttpCode() == 200) {
+                    return ['status' => true,
+                        'data' => [
+                            'responseIds' => [$tweet->data->id],
+                            ]
+                    ];
+                } else {
+                    throw new \Exception('推文发布失败: ' . json_encode($tweet->errors));
+                }
+            } else {
+                return ['status' => false, 'data' => '视频上传失败或处理超时。状态:' . print_r($status, true) ];
             }
-
-
-
-            // 2.0版本发布推文
-            $this->twitterOAuth->setApiVersion('2');
-            $tweet = $this->twitterOAuth->post('tweets', [
-                'text' => $message,
-                'media' => ['media_ids' => [$mediaId]]
-            ]);
-
-            dd($tweet);
-
         } catch (\Exception $e) {
             return ['status' => false, 'data' => $e->getMessage()];
         }

+ 4 - 7
app/Services/Smm/YoutubeService.php

@@ -255,20 +255,17 @@ class YoutubeService implements SmmPlatformInterface
         }
     }
 
-    public function refreshAccessToken($refreshToken, $expiresAt)
+    public function refreshAccessToken($refreshToken)
     {
-        if (Carbon::now() < Carbon::parse($expiresAt)->subMinutes(10)) {
-            return ['status' => false, 'error' => 'Access token is not expired'];
-        }
-
         try {
             $newToken = $this->client->fetchAccessTokenWithRefreshToken($refreshToken);
-
+            dd($newToken);
             return [
                 'status' => true,
                 'data' => [
                     'access_token' => $newToken['access_token'],
-                    'expires_at' => Carbon::now()->addSeconds($newToken['expires_in'])
+                    'expires_at' => Carbon::now()->addSeconds($newToken['expires_in']),
+                    'refresh_token' => $newToken['refresh_token'],
                 ]
             ];
         } catch (\Exception $e) {

+ 1 - 1
config/admin.php

@@ -289,7 +289,7 @@ return [
 
         'oss_image' => [
             'accept' => 'jpg,png,gif,jpeg,webp,svg',//允许上传的文件类型
-            'max_size' => 500, // 上传文件大小限制,单位kB
+            'max_size' => 1000, // 上传文件大小限制,单位kB
             'limit' => 20, // 上传文件数量限制
         ],
 

+ 7 - 1
config/dictionary.php

@@ -112,7 +112,13 @@ return [
         'Twitter' => 'Twitter',
         'TikTok' => 'TikTok',
         'Pinterest' => 'Pinterest',
-    ]
+    ],
+
 
+    'post_log_status' => [
+        0 => 'pending_to_send',
+        1 => 'success',
+        2 => 'failure',
+    ],
 
 ];

+ 1 - 1
config/distributor.php

@@ -283,7 +283,7 @@ return [
 
         'oss_image' => [
             'accept' => 'jpg,png,gif,jpeg,webp,svg',//允许上传的文件类型
-            'max_size' => 500, // 上传文件大小限制,单位kB
+            'max_size' => 1000, // 上传文件大小限制,单位kB
             'limit' => 20, // 上传文件数量限制
         ],
 

+ 16 - 0
lang/en/global.php

@@ -109,6 +109,8 @@ return [
         'title_en'              => 'Title',
         'account_id'            => 'Account ID',
         'expires_at'            => 'Expires At',
+        'send_post'             => 'Send Post',
+
     ],
     'labels' => [
         'list'                  => 'List',
@@ -220,6 +222,20 @@ return [
         'timing'                => 'Timing',
         'immediate'             => 'Immediate',
         'reauthorization'       => 'Reauthorization',
+        'quota_explanation'     => 'Explanation',
+        'twitter_quota_explanation' => 'Auth refreshes automatically; calls refresh monthly, :quota remaining',
+        'youtube_quota_explanation' => 'Auth refreshes automatically; calls refresh daily, :quota remaining',
+        'facebook_quota_explanation' => 'Auth valid for 60 days, refresh manually; no call limit',
+        'instagram_quota_explanation' => 'Auth valid for 60 days, refresh manually; no call limit,',
+        'else_quota_explanation' => 'No quota',
+        'post_log'              => 'Post Log',
+        'account_name'          => 'Account Name',
+        'etd'             => 'Estimated Time of Departure',
+        'media_name'           => 'Media Name',
+        'post_message'        => 'Post Message',
+        'pending_to_send'      => 'Pending to Send',
+        'success'              => 'Success',
+        'failed'               => 'Failed',
     ],
     'options' => [
         //

+ 16 - 1
lang/zh_CN/global.php

@@ -116,6 +116,8 @@ return [
         'account_id'            => '账号ID',
         'expires_at'            => '过期时间',
         'youtube_category'      => 'Youtube分类',
+        'send_post'              => '发送帖子',
+
     ],
     'labels' => [
         'list'         => '列表',
@@ -229,7 +231,20 @@ return [
         'timing'                 => '定时',
         'send_type'             => '发送类型',
         'reauthorization'       => '重新授权',
-
+        'quota_explanation'     => '说明',
+        'twitter_quota_explanation' => "认证自动刷新;调用次数每月刷新,剩余:quota次",
+        'youtube_quota_explanation' => "认证自动刷新;调用次数每日刷新,剩余:quota次",
+        'facebook_quota_explanation' => "认证有效期60天,到期手动刷新;调用次数不限制",
+        'instagram_quota_explanation' => "认证有效期60天,到期手动刷新;调用次数不限制",
+        'else_quota_explanation' => '没有限额',
+        'post_log'               => '帖子日志',
+        'account_name'           => '账号名称',
+        'etd'              => '预计发送时间',
+        'media_name'           => '媒体名称',
+        'post_message'         => '帖子内容',
+        'pending_to_send'      => '待发送',
+        'success'              => '成功',
+        'failed'               => '失败',
     ],
     'options' => [
         //

+ 1 - 0
lang/zh_CN/menu.php

@@ -58,5 +58,6 @@ return [
         'flyer_management'  =>'传单管理',
         'account_management'=>'账户管理',
         'post_sending'  =>'帖子发送',
+        'post_log'  =>'帖子日志',
     ],
 ];