素材视频上传"/>
php 微信永久素材视频上传
a.php 省略了一不部分token!!!! $msg=$GLOBALS['HTTP_RAW_POST_DATA']; $msgstr=(array)simplexml_load_string($msg, 'SimpleXMLElement', LIBXML_NOCDATA);$com=com($msgstr);
if($msgstr['MsgType']=='video'){ //回复视频 echo "<xml> $com <MsgType><![CDATA[video]]></MsgType> <Video> <MediaId><![CDATA[1VkhJyhTjbIz9ZL-7EPCMsLgS05FlGX86iOFgI_Bm7tTmGUqOpqQAXdn5VEUedAy]]></MediaId> <Title><![CDATA[不容易阿]]></Title> <Description><![CDATA[总算出来了]]></Description> </Video> </xml>";exit;}//公共头部 function com($msgstr){ $str=" <ToUserName><![CDATA[{$msgstr['FromUserName']}]]></ToUserName> <FromUserName><![CDATA[{$msgstr['ToUserName']}]]></FromUserName> <CreateTime>".time()."</CreateTime>"; return $str; }
上传视频部分b.php$sucai="={$token['access_token']}&type=video";//临时的素材可以永久的不行 //图片地址 //$img=dirname ( __FILE__ ).'b.jpg'; //视频地址 $img='1.mp4'; $res=curla($sucai,$img); //file_put_contents('img'.time().'.log',file_get_contents($sucai)); var_dump($res);die; function curla($sucai,$img){ $ch = curl_init(); //判断curl类的扩展是否存在可用 if(class_exists('CURLFile')){ //存在就new curl_setopt($ch,CURLOPT_SAFE_UPLOAD,true); $data=array('media'=>new \CURLFile(realpath($img)));//必须加上realpath()否则读取不到文件的路径 // $data['title']='123456'; }else{ //不存在 if(defined('CURLOPT_SAFE_UPLOAD')){ curl_setopt($ch,CURLOPT_SAFE_UPLOAD,false); } //realpath读取文件的所在的地址 $data=array('media'=>"@".realpath($img)); } curl_setopt($ch, CURLOPT_URL, $sucai); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //请求https协议时必须加上重点ssl安全验证 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // post数据 curl_setopt($ch, CURLOPT_POST, 1); // post的变量 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); curl_close($ch); return $output; }
更多推荐
php 微信永久素材视频上传
发布评论