微信公众平台模拟登陆上传素材(求助nodejs转php)
MPWechat.prototype.uploadMedia = function(medianame,reqData,callback){ tools.log('uploadMedia start ...'); var boundary = 'tvmin'; var max = 9007199254740992; var dec = Math.random() * max; var hex = boundary + dec.toString(36); var mimes = { //image '.bmp': 'image/bmp', '.png': 'image/png', '.gif': 'image/gif', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', /oice '.mp3': 'audio/mp3', '.wav': 'audio/x-wav', '.amr': 'audior', '.wma': 'audio/x-ms-wma', /ideo '.mp4': 'video/mp4', '.rm': 'video/rm', '.rmvb': 'videond.rn-realvideo', '.wmv': 'video/x-ms-wmv', '.avi': 'video/x-msvideo', '.mpg': 'video/mpeg', '.mpeg': 'video/mpeg' }; var ext = path.extname(medianame).toLowerCase(); var mime = mimes[ext]; var boundaryKey = '----WebKitFormBoundary' + hex; var payload = '\r\n\r\n--' + boundaryKey + '\r\n' + 'Content-Disposition: form-data; name="uploadfile"; filename="'+ medianame +'"\r\n' + 'Content-Type: '+ mime +'\r\n\r\n'; var enddata = '\r\n--' + boundaryKey + '\r\n' + 'Content-Disposition: form-data; name="formId"\r\n\r\n' + '--' + boundaryKey + '--'; var contentLength = Buffer.byteLength(payload,'utf8') + reqData.length + Buffer.byteLength(enddata,'utf8'); var options = { host: host, port: 443, method: 'POST', path: '/cgi-bin/uploadmaterial?cgi=uploadmaterial&type=0&token='+ this.token +'&t=iframe-uploadfile&lang=zh_CN&formId=null', headers: { 'Content-Type': 'multipart/form-data; boundary='+boundaryKey, 'Content-Length': contentLength, 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31', 'Cookie': this.cookie, 'Referer': 'https://'+ host +'/cgi-bin/indexpage?token='+ this.token +'&lang=zh_CN&t=wxm-upload&lang=zh_CN&type=0&fromId=file_from_1341151893625' } }; var req = https.request(options, function(response) { var statusCode = response.statusCode;// console.log('STATUS: ' + statusCode,options); response.setEncoding('utf8'); var data = ''; response.on('data', function(chunk) { data += chunk; }).on('end',function(){ callback(data.match(/formId, '(\d+)'/)[1]); }); }); req.write(payload,'utf8'); req.write(reqData,'binary'); req.write(enddata,'utf8'); req.end(); req.on('error', function(e) { console.error("error:"+e); });};
以上是nodejs版本上传代码
源作者说只要把文件变成 byte
和文件名,一起call这个function就可以了
就只有两个参数
图片格式必须为以下格式:bmp, png, jpeg, jpg, gif
语音格式必须为以下格式:mp3, wma, wav, amr
视频格式必须为以下格式:rm, rmvb, wmv, avi, mpg, mpeg, mp4
想改写成php的 但改写了几天老是出错
//接口上传 public function pictures($data,$file){ $cookie =$this->read('cookie.log'); $cooken = self::read2('cooken.log'); $https = new https; $referer = 'https://mp.weixin.qq.com/cgi-bin/indexpage?token='; $referer .= $cooken.'&lang=zh_CN&t=wxm-upload&lang=zh_CN&type=0&fromId=file_from_1341151893625'; //伪装来源页地址 $submit = 'https://mp.weixin.qq.com/cgi-bin/uploadmaterial?cgi=uploadmaterial&type=0&token='; $submit .= $cooken.'&t=iframe-uploadfile&lang=zh_CN&&formId=null';//图片提交地址 $ext = strtolower(trim(substr(strrchr($file, '.'), 1, 10))); if($ext == '') return "对不起,文件名错误!"; $mime_types = array ( //image 支持的图片 'bmp' => 'image/bmp', 'png' => 'image/png', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', //oice 支持的语音 'mp3' => 'audio/mp3', 'wav' => 'audio/x-wav', 'amr' => 'audior', 'wma' => 'audio/x-ms-wma', //ideo 支持的视频 'mp4' => 'video/mp4', 'rm' => 'video/rm', 'rmvb' => 'videond.rn-realvideo', 'wmv' => 'video/x-ms-wmv', 'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg' ); $mime = isset($mime_types[$ext]) ? $mime_types[$ext] : ''; $hexken = self::randStr(15); if (empty($title)){ $medianame = self::randStr(10).'.'.$ext;// 设置文件名 }else{ $medianame = $file; } $boundaryKey = '----WebKitFormBoundary'.$hexken; $enddata = "\r\n\r\n--".$boundaryKey."\r\n"; $enddata .= 'Content-Disposition: form-data; name="uploadfile"; filename="'.$medianame.'"'; $enddata .= "\r\nContent-Type: ".$mime."\r\n\r\n".$data; $enddata .= "\r\n--".$boundaryKey."\r\n"; $enddata .= 'Content-Disposition: form-data; name="formId"'; $enddata .= "\r\n\r\n--".$boundaryKey.'--'; //echo $enddata; //file_put_contents("./data/f1.txt", date('c')."\r\n".$content."\r\n",FILE_APPEND); $result = $https->submit($submit,$enddata,$cookie,$referer); $results =$result['body']; file_put_contents("./data/data.txt", date('c')."\r\n".$results."\r\n",FILE_APPEND); echo $results; if(preg_match("/登录超时.*重新登录/", $results)){ //echo "登陆超时,发送出错!"; set_time_limit(30); sleep(2); self::login(); self::qsend($content,$type); } //$result = json_decode($results,true); if(preg_match("/上传成功/", $results)){ echo "恭喜,文件上传成功!"; }else if (preg_match("/上传文件失败/", $results)){ echo "对不起,上传文件失败!"; //echo var_dump($_SERVER);$_SERVER[PATH_TRANSLATED]; }else { echo "群发失败!"; } return $result; } public function randStr($len=6){ $chars='ABDEFGHJKLMNPQRSTVWXYkfbd23456789'; // characters to build the password from //ABDEFGHJKLMNPQRSTVWXYabdefghijkmnpqrstvwxy23456789#%* mt_srand((double)microtime()*1000000*getmypid()); // seed the random number generater (must be done) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return $password; }
这是我写的部份代码 用的curl_setopt
求大大帮忙改写
回复讨论(解决方案)
出错?提示什么?贴出错误信息出来
出错?提示什么?贴出错误信息出来
<script> document.domain = location.hostname.match(/[^\.]*?\.[^\.]*?$/); var url = window.location.href, type = url.match(/[\?&]type=([^&]*)/), formId = url.match(/[\?&]formId=([^&]*)/); type = type[1] || 0; formId = formId[1]; top.W.upload.err("上传文件失败", type, formId); </script>
只要登陆信息正确是错误就返回这个
求大神呀!
楼主我想问下,你的这个模拟登录 代码是怎么写的,我用Snoopy模拟登录,传递到http://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN四个值 username,pwd,f,imgcode 总是返回登录不成功,是怎么回事?是还要传递某些cookie吗?
楼主我想问下,你的这个模拟登录 代码是怎么写的,我用Snoopy模拟登录,传递到http://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN四个值 username,pwd,f,imgcode 总是返回登录不成功,是怎么回事?是还要传递某些cookie吗?
Snoopy是没有用的,现在微信平台更新了这些模拟都没用了,白整了!
先看下接口好不好申请 好申请的话就直接用接口了
不行就再次强、奸公众平台!
$url = "https://mp.weixin.qq.com/cgi-bin/filetransfer?action=upload_material&f=json&ticket_id={$username}&ticket={$ticket}&token={$this->token}&lang=zh_CN"; $this->send_data = array( 'action' => 'upload_material', 'ticket_id' => $username, 'ticket' => $ticket, 'token' => $this->token, 'ajax' => 1, 'file' =>"@".str_replace('/', '\\', $_SERVER['DOCUMENT_ROOT'])."\\uploads\\file\\20140324104305420.jpg", 'folder' => '/cgi-bin/uploads', 'Upload' => 'Submit Query', 't' =>'ajax-response', ); print_r($this->send_data); $this->getHeader = 1; $this->referer = "https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit&action=edit&type=10&isMul=0&isNew=1&lang=zh_CN&token={$this->token}";//'https://mp.weixin.qq.com/cgi-bin/advanced?action=dev&t=advanced/dev&token='.$this->token.'&lang=zh_CN'; return $this->curlPostFile($url);;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.
