开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 2050|回复: 3
收起左侧

[PHP相关教程] php实现微信web网页上传图片返回ret=1

[复制链接]
结帖率:0% (0/1)
发表于 2018-7-10 15:51:54 | 显示全部楼层 |阅读模式   广东省深圳市
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive
Content-Length: 1717
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarypFcgOR4GXSgABCU8
Connection: Keep-Alive
Cookie:mm_lang=zh_CN; wxuin=Je1qzrhDNbmqT5fE; wxsid=2965383124; webwx_data_ticket=gSeK88OrVSpK5cN+X351uzmB;webwx_auth_ticket=CIsBELHR5ZMOGoAB147hnSA6r5Xs9eBnmREBMNQUBiLsPLYDP0wynNB/7kJPNgWHPPrTLV1HT8Cp7/Sqo3+87JWKl77aTIhK02i3uVlfO7QzhJ1vP63pq20JD3/TDrC61Uj3q85vLO1VrFDXnVB4eF2UEX4d4y9HLgLJaAUyEovItslZdKXqZuRv5cA=;
Host: file.wx2.qq.com
Origin: https://wx2.qq.com/
Referer: https://wx2.qq.com/?&lang=zh_CN
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
----WebKitFormBoundarypFcgOR4GXSgABCU8
Content-Disposition: form-data; name="id"

WU_FILE_0
----WebKitFormBoundarypFcgOR4GXSgABCU8
Content-Disposition: form-data; name="name"

Chrysanthemum.jpg
----WebKitFormBoundarypFcgOR4GXSgABCU8
Content-Disposition: form-data; name="type"

image/jpeg
----WebKitFormBoundarypFcgOR4GXSgABCU8
Content-Disposition: form-data; name="lastModifiedDate"

Tue, 10 Jul 2018 15:45:52 +0800 (中国标准时间)
----WebKitFormBoundarypFcgOR4GXSgABCU8
Content-Disposition: form-data; name="size"

879394
----WebKitFormBoundarypFcgOR4GXSgABCU8
Content-Disposition: form-data; name="mediatype"

pic
----WebKitFormBoundarypFcgOR4GXSgABCU8
Content-Disposition: form-data; name="uploadmediarequest"

{"UploadType":2,"BaseRequest":{"Uin":2965383124,"Sid":"Je1qzrhDNbmqT5fE","Skey":"@crypt_acab629d_cb2b0f861a98e36023558c012306721b","DeviceID":"e351901350098439"},"ClientMediaId":Tue Jun 12 2018 06:12:56 GMT+0000 (GMT),"TotalLen":879394,"StartPos":0,"DataLen":879394,"MediaType":4,"FromUserName":"@518fc40ecf16c3036ce2e89fe0e6f83537dc7cf321d6b720ebf0c62b72c4b879","ToUserName":"@518fc40ecf16c3036ce2e89fe0e6f83537dc7cf321d6b720ebf0c62b72c4b879","FileMd5":"4889cabb54a4eaca17a1af706392f50a"}
----WebKitFormBoundarypFcgOR4GXSgABCU8
Content-Disposition: form-data; name="webwx_data_ticket"

gSc+ANGymvpiLAM+5HMZSOPz
----WebKitFormBoundarypFcgOR4GXSgABCU8
Content-Disposition: form-data; name="pass_ticket"

QKlA5SisY3PK%2FX9m09ARWHUPsgBnLDM8e%2FzOZuwFkT4FZw4qF0UQm4DlcSkO68QF
----WebKitFormBoundarypFcgOR4GXSgABCU8
Content-Disposition: form-data; name="filename"; filename="Chrysanthemum.jpg"
Content-Type: image/jpeg


----WebKitFormBoundarypFcgOR4GXSgABCU8--


错在哪里?求大神指导!!!

结帖率:0% (0/1)
 楼主| 发表于 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;


这就是代码,求大神看看是怎么回事,是不是我缺少了哪些参数
回复 支持 反对

使用道具 举报

结帖率:0% (0/1)
 楼主| 发表于 2018-7-19 20:15:55 | 显示全部楼层   广东省深圳市

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;
回复 支持 反对

使用道具 举报

发表于 2018-7-12 12:34:22 | 显示全部楼层   山东省临沂市
代码呢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表