·设为首页收藏本站📧邮箱修改🎁免费下载专区💎积分✅卡密📒收藏夹👽聊天室
返回列表 发布新帖

根据文章内容生成视频的教程(基于百度)

53 0
发表于 昨天 22:30 | 查看全部 阅读模式

马上注册,免费下载更多dz插件网资源。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
  1. <?phpheader('Access-Control-Allow-Origin: *');require("../../class/connect.php");require("../../class/db_sql.php");require("../../class/q_functions.php");include('../../data/dbcache/class.php');require("../../member/class/user.php");$link=db_connect();$empire=new mysqlquery();require_once(ECMS_PATH.'ecmsapi/EcmsApi.php'); // 引入API插件核心类,注意用require_once,引用一次即可。$api = new EcmsApi();// 实例化一个对象,一个页面只需一次。if (class_exists('Memcached')){$cache = $api->load('cache','mem'); // 第二个参数传入mem表示使用mem方式缓存.第二个参数传入yac表示使用yac方式缓存.第二个参数不传,默认使用File方式}else{$cache = $api->load('cache','file');         }$appid = '73078669'; //到百度云申请AI成片$apikey = 'a4q4PXwUVaf018CboGYFnFCw';//到百度云申请AI成片$secretkey = 'iVuBGlKDBIl7hiA4hRGO24cvnRekrDL9';//到百度云申请AI成片$ip=egetip();$riqi=time();$userid=(int)getcvar('mluserid');$groupid=(int)getcvar('mlgroupid'); $username=RepPostVar(getcvar('mlusername'));$userida=$userid?$userid:"1";$name=$username?$username:"游客";$biaoship=$public_r['add_pcurl']?$public_r['add_pcurl']:'meiweny';$biaoshi=str_replace(array('http://','https://','/','www.','.',),"",$biaoship);//只保留域名if(!$api->isPost()){$api->load('fun')->json(500 , '非法提交');}$wd = 'checkuser'.$user['userid'].''; // 备注名$cacheName = 'pc'.$biaoshi.'checkuser_'.md5($wd); //定义一个独一无二的缓存变量名称$userpic = $cache->get($cacheName); // 获取缓存if(null === $userpic){$member =$api->load('db')->one("select userpic from {$dbtbpre}enewsmemberadd where userid='$user[userid]' order by userid desc limit 1");$userpic=$member['userpic']?$member['userpic']:'/e/extend/pcpinglun/assets/nouserpic.gif';$cache->set($cacheName , $userpic , 3600*24*30); // 设置缓存,时间为3600秒}$newstext=$api->param('newstext','','RepPostStr');$newstext=str_replace("\n", "", $newstext);  $title=$api->param('title','AI智能图文生成视频','RepPostStr');if($newstext === ''||$title === ''){$api->load('fun')->json(500 , '不能为空');}$newstext=$newstext?$newstext:'<p>再过好多年在白云悬碧空的秋日,</p><p>在夕阳恋红叶的午后,</p><p>当我重新翻开你的那一页时,</p><p>依然会感受到潮湿的印痕...</p><p>美文苑文学网(meiweny.cn) 感谢您的来访! —— by:YuQi</p><p>愿我的建站生涯能遇见一位良师,结交一位良友。</p><p>站长QQ:229066206</p>';  $pattern = '/<p>(.*?)<\/p>|<br>(.*?)|<br>/i';     preg_match_all($pattern, $newstext, $matches);     $result = $matches[1];  $result = array_filter($result, function ($value) {  return $value !== '';  }); $postData = ['source' => ['structs' => []]];     foreach ($result as $index =>$text) {            $picnum=intval(mt_rand(0,2511));        $images='/uploads/images/'.$picnum.'.jpg';        $strippedText = strip_tags($text);           $postData['source']['structs'][] = ['type' => 'text', 'text' => $strippedText];     $postData['source']['structs'][]= ['type' => 'image', 'mediaSource' => ['type' => 3, 'url' => $public_r['add_pcurl'].$images]];}     $postData['config'] = ['productType' => 'video', 'duration' =>'-1','resolution' =>[1280, 720],'bgMusic' =>['mediaSource'=>['type' =>3,'url' =>''.$public_r['add_pcurl'].'/uploads/shipin/0.mp5']]];  $postData = json_encode($postData,JSON_UNESCAPED_UNICODE); function request_post($url = '', $param = ''){if (empty($url) || empty($param)) {return false;}$postUrl = $url;$curlPost = $param;$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $postUrl);curl_setopt($curl, CURLOPT_HEADER, 0);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($curl, CURLOPT_POST, 1);curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);$data = curl_exec($curl);curl_close($curl);return $data;}$url = 'https://aip.baidubce.com/oauth/2.0/token';$post_tokendata['grant_type']       = 'client_credentials';$post_tokendata['client_id']      = $apikey;//API_KEY$post_tokendata['client_secret'] = $secretkey;//SECRET_KEY$o = "";foreach ( $post_tokendata as $k => $v ){    $o.= "$k=" . urlencode( $v ). "&" ;}$post_tokendata = substr($o,0,-1);$cacheName =md5($public_r['add_pcurl']).'pcaivideo_access_token_' . md5($secretkey);$jsoninfo = $cache->get($cacheName); if(null==$jsoninfo){$res = request_post($url, $post_tokendata);$jsoninfo=json_decode($res,TRUE);$cache->set($cacheName,$jsoninfo, 3600*24*25); }$access_token =$jsoninfo['access_token'];$videourl="https://aip.baidubce.com/rpc/2.0/brain/creative/ttv/material?access_token=".$access_token;$cacheName =md5($public_r['add_pcurl']).'aivideojobId_' . md5($title);$response = $cache->get($cacheName); if(null==$response){$ch = curl_init();        $headers = array();$headers[] = "Content-Type: application/json";curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);curl_setopt($ch, CURLOPT_URL, $videourl);curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);$response=curl_exec($ch);$response=json_decode($response,TRUE);$cache->set($cacheName,$response, 3600*24*6); }if (isset($response['error_code'])) {$api->json(['error_code' =>$response['error_code'] ,'error_msg' => $response['error_msg'],'ip' => $ip,'userid' => $userid,'name' => $name,'userpic' =>$public_r['add_pcurl'].$userpic] , JSON_UNESCAPED_UNICODE);}$jobId=$response['data']['jobId'];$jobIdData = json_encode(['jobId' =>$jobId]); $videourlcha="https://aip.baidubce.com/rpc/2.0/brain/creative/ttv/query?access_token=".$access_token;$curl = curl_init();        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);curl_setopt($curl, CURLOPT_URL, $videourlcha);curl_setopt($curl, CURLOPT_POSTFIELDS, $jobIdData);curl_setopt($curl, CURLOPT_POST, 1);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);$videoruzit=curl_exec($curl);$videoruzit=json_decode($videoruzit, true);if (isset($videoruzit['error_code']) && $videoruzit['error_code'] !=0) {  $api->json(['jobId' =>$jobId ,'error_code' =>$videoruzit['error_code'] , 'error_msg' => $videoruzit['error_msg'],'ip' => $ip,'userid' => $userid,'name' => $name,'userpic' =>$public_r['add_pcurl'].$userpic], JSON_UNESCAPED_UNICODE);}else{$api->json(['jobId' =>$jobId ,'title' =>$title ,'progress' =>$videoruzit['data']['progress'],'timeline' =>$videoruzit['data']['timeline'],'statusCode' =>$videoruzit['data']['statusCode'],'data' =>$videoruzit['data'] , 'videoAddr' => $videoruzit['data']['videoAddr'],'ip' => $ip,'userid' => $userid,'name' => $name,'userpic' =>$public_r['add_pcurl'].$userpic], JSON_UNESCAPED_UNICODE);        }
复制代码
根据文章内容生成视频的教程(基于百度),非常的粗糙哈!代码只提供最基本的实例
我要说一句 收起回复

回复

 懒得打字嘛,点击右侧快捷回复【查看最新发布】   【应用商城享更多资源】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

创宇盾启航版免费网站防御网站加速服务
投诉/建议联系

discuzaddons@vip.qq.com

未经授权禁止转载,复制和建立镜像,
如有违反,按照公告处理!!!
  • 联系QQ客服
  • 添加微信客服

联系DZ插件网微信客服|最近更新|Archiver|手机版|小黑屋|DZ插件网! ( 鄂ICP备20010621号-1 )|网站地图 知道创宇云防御

您的IP:3.147.68.18,GMT+8, 2025-1-11 02:38 , Processed in 0.201231 second(s), 75 queries , Gzip On, Redis On.

Powered by Discuz! X5.0 Licensed

© 2001-2025 Discuz! Team.

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表