|
楼主 |
发表于 2018-7-19 20:16:35
|
显示全部楼层
广东省深圳市
date_default_timezone_set ( 'PRC' );
require_once 'include/HttpRequest.php';
print_r($_FILES);
if(($_FILES["file"]["type"]=="image/png"||$_FILES["file"]["type"]=="image/jpeg")&&$_FILES["file"]["size"]<1024000)
{
//防止文件名重复
$filename =time().$_FILES["file"]["name"];
//转码,把utf-8转成gb2312,返回转换后的字符串, 或者在失败时返回 FALSE。
$filename =iconv("UTF-8","gb2312",$filename);
//检查文件或目录是否存在
if(file_exists($filename))
{
echo"该文件已存在";
print_r($filename);exit;
}
else {
//保存文件, move_uploaded_file 将上传的文件移动到新位置
move_uploaded_file($_FILES["file"]["tmp_name"], $filename);//将临时地址移动到指定地址
}
}
//gScmM8xh/yo0TtZ9ZTeFa2U+
//gScmM8xh/yo0TtZ9ZTeFa2U+
$url="http://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json";
$time = time()*1000;
$boundry="--".str_shuffle('WebKitFormBoundarypFcgOR4GXSgABCU8');
$post_data="";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"id\"\r\n\r\nWU_FILE_0\r\n";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"name\"\r\n\r\n".$filename."\r\n";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"type\"\r\n\r\n".$_FILES['file']['type']."\r\n";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"lastModifiedDate\"\r\n\r\n".date('r').' (中国标准时间)'."\r\n";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"size\"\r\n\r\n".$_FILES['file']['size']."\r\n";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"chunks\"\r\n\r\n 2"."\r\n";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"chunk\"\r\n\r\n 1 "."\r\n";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"mediatype\"\r\n\r\n pic"."\r\n";
$upload="";
// $n = new imgdata;
// $n -> getdir($_FILES['img']['tmp_name']);
$upload.="{\"UploadType\":2,\"BaseRequest\":{\"Uin\":".$user_info['wxuin'].",\"Sid\":\"".$user_info['wxsid']."\",\"Skey\":\"".$user_info['wxskey']."\",\"DeviceID\":\"".$user_info['deviceid']."\"}" .
",\"ClientMediaId\":".$time.",\"TotalLen\":".$_FILES['file']['size'].",\"StartPos\":0,\"DataLen\":".$_FILES['file']['size'].",\"MediaType\":4,\"FromUserName\":\"".$user_info['wxusername']."" .
"\",\"ToUserName\":\"".$user_info['wxusername']."\",\"FileMd5\":\"".md5_file($filename)."\"}";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"uploadmediarequest\"\r\n\r\n".$upload."\r\n";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"webwx_data_ticket\"\r\n\r\n".$_COOKIE['webwx_data_ticket']."\r\n";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"pass_ticket\"\r\n\r\n".$user_info['wxticket']."\r\n";
$post_data.=$boundry."\r\n Content-Disposition: form-data; name=\"filename\"; filename=\"".$filename."\"\r\n Content-Type: image/jpeg\r\n\r\n"."\r\n";
$post_data.=$boundry."--";
$header="";
$webwx_auth_ticket = $_COOKIE['webwx_auth_ticket'];
$webwx_data_ticket = $_COOKIE['webwx_data_ticket'];
$wxsid = $user_info['wxsid'];
$wxuin = $user_info['wxuin'];
$header.="Accept: */*\n";
$header.="Accept-Encoding: gzip, deflate, br\n";
$header.="Accept-Language: zh-CN,zh;q=0.9\n";
$header.="Connection: keep-alive\n";
$header.="Content-Length: ".strlen($post_data)."\n";
$header.="Content-Type: multipart/form-data;boundary=".$boundry."\n";
$header.="Connection: Keep-Alive\n";
$header.="Cookie:webwxuvid=67b00b80a8b56205e0f22cdcca1a0bf76ce42e21dd9e9b8a2e1874704bb942105a9ccb48b1d55a585383c911d684ef00;
pgv_pvi=8630461440; pt2gguin=o0201534638; RK=DQodCekRZM; ptcz=d33ddb33fafe7177b36be69ff28185740dfcca5778ed32bbf78fd70ee169f30a;
pgv_pvid=303899198; wxuin=2965383124; wxsid=HEdcI68QHUyx5PhT; mm_lang=zh_CN;
webwx_data_ticket=gScy0Yv+Cxtb83FjrN0ZtmWg; webwx_auth_ticket=CIsBEI/MmYoPGoABWcE1Pb3IEqQ+NnjhpW7iLtQUBiLsPLYDP0wynNB/7kIUsSFajmW8+FP/rxVZ94rcPS5LxM1MY7K/xU4DKXGqxmyJ5IMZRSbAuK6kjCMHL7zmMWPhGjhA8FyOPrpM6XuNtbia2E9ASwHfMreBTVFGP6uLFuNqOySEK/XVy/6Kf9E=;
wxloadtime=1531282537_expired; wxpluginkey=1531263725;\n";
$header.="Host: file.wx2.qq.com\n";
$header.="Origin: https://wx2.qq.com/\r\n";
$header.="Referer: https://wx2.qq.com/?&lang=zh_CN\n";
$header.="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36\n";
$opts = array('http' =>array(
'method' => 'POST',
'header' =>$header,
'content' => $post_data
)
);
//$res = HttpRequest::request3($url,$post_data,$header);
//var_dump($res);exit;
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
print_r($post_data);
print_r($header);
echo $result;exit;
这就是代码,求大神看看是怎么回事,是不是我缺少了哪些参数 |
|