php 微信永久素材视频上传

编程入门 行业动态 更新时间:2024-10-25 02:31:06

php 微信永久<a href=https://www.elefans.com/category/jswz/34/1769407.html style=素材视频上传"/>

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 微信永久素材视频上传

本文发布于:2024-02-12 17:38:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1688756.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:素材   上传   视频   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!