马上注册,免费下载更多dz插件网资源。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- <?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); }
复制代码 根据文章内容生成视频的教程(基于百度),非常的粗糙哈!代码只提供最基本的实例
©DZ插件网所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。 网站部分内容来源于网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,得到更好的正版服务。 您在本站任何的赞助购买、下载、查阅、回复等行为等均表示接受并同意签订《DZ插件网免责声明协议》。 如有侵权请邮件与我们联系处理: discuzaddons@vip.qq.com 并出示相关证明以便删除。敬请谅解!
|