AyrReleaseController.php 4.3 KB
<?php

namespace App\Http\Controllers\Bside\AyrShare;

use App\Enums\Common\Code;
use App\Helper\AyrShare as AyrShareHelper;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Controllers\Bside\FileController;
use App\Http\Controllers\file\ImageController;
use App\Http\Logic\Bside\AyrShare\AyrReleaseLogic;
use App\Http\Logic\Bside\AyrShare\AyrShareLogic;
use App\Models\File\Image;
use App\Models\File\Image as ImageModel;

/**
 * @name:社交发布
 * Facebook Pages and Groups: 10 images, including a carousel post.
 *   Instagram: 10 images.
 *   Google : 1 image.
 *   LinkedIn: 9 images.
 *   Pinterest: 1 image.
 *   Reddit: 1 image.
 *   Telegram: 1 image.
 *   Twitter:4 image
 */
class AyrReleaseController extends BaseController
{
    /**
     * @name   :(获取发送数据详情)info
     * @author :lyh
     * @method :post
     * @time   :2023/5/10 14:57
     */
    public function info(AyrReleaseLogic $ayrReleaseLogic){
        $info = $ayrReleaseLogic->release_info();
        $this->response('success',Code::SUCCESS,$info);
    }

    /**
     * @name   :(获取当前用户已绑定的社交链接)info
     * @author :lyh
     * @method :post
     * @time   :2023/5/9 16:00
     */
    public function share_info(AyrShareLogic $ayrShareLogic){
        $info = $ayrShareLogic->ayr_share_info();
        $this->response('success',Code::SUCCESS,$info);
    }
    /**
     * @name   :(发布社交)send_post
     * @author :lyh
     * @method :post
     * @time   :2023/5/9 9:36
     */
    public function send_post(AyrReleaseLogic $ayrReleaseLogic,AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
        //获取发送账号详情
        $share_info = $ayrShareLogic->ayr_share_info();
        $data = [
            'images'=>$this->param['images'],
            'files'=>$this->param['video'],
        ];
        //参数处理
        $this->param['mediaUrls'] = $ayrReleaseLogic->image_file_param($data);;
        //统一生成发布
        $param = [
            'post'=>$this->param['content'],
            'platforms'=>$this->param['platforms'],
            'mediaUrls'=>$this->param['mediaUrls'],//参数处理
            'idempotencyKey'=>$this->param['idempotency_key'],//时间(如是过去时间,立即发布)
        ];
        //发送请求发布社交文章
        $res = $ayrShare->post_send_msg($param,$share_info['profile_key']);
        //保存数据库
        $ayrReleaseLogic->release_add();
        $this->response('success',Code::SUCCESS,$res);
    }

    /**
     * @name   :(图片上传到第三方平台)send_media
     * @author :lyh
     * @method :post
     * @time   :2023/5/10 14:07
     */
    public function send_media(AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
        $image_info = $ayrShareLogic->save_img_info($this->param['hash']);
        if(empty($image_info['ayr_id'])){
            //获取发送账号详情
            $share_info = $ayrShareLogic->ayr_share_info();
            //获取当前图片数据是否已上传到第三方
            $arr = (new ImageController())->index($this->param['hash']);
            //向第三方存储图片
            $param = [
                'file'=>($arr->original),//base64编码
            ];
            $param_data =  $ayrShare->post_media_upload($param,$share_info['profile_key']);
            //更新图片库
            $ayrShareLogic->save_img($param_data);
        }
        $this->response('success');
    }

    /**
     * @name   :(文件上传到第三方平台)send_media
     * @author :lyh
     * @method :post
     * @time   :2023/5/10 14:07
     */
    public function send_media_file(AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
        $image_info = $ayrShareLogic->save_file_info($this->param['hash']);
        if(empty($image_info['ayr_id'])){
            //获取发送账号详情
            $share_info = $ayrShareLogic->ayr_share_info();
            //获取当前图片数据是否已上传到第三方
            $arr = (new FileController())->index($this->param['hash']);
            //向第三方存储图片
            $param = [
                'file'=>($arr->original),//base64编码
            ];
            $param_data =  $ayrShare->post_media_upload($param,$share_info['profile_key']);
            //更新图片库
            $ayrShareLogic->save_file($param_data);
        }
        $this->response('success');
    }
}