微信公众平台模拟登陆上传素材(nodejs转php)
Jun 13, 2016 am 11:39 AM
amp
function
nbsp
var
微信公众平台模拟登陆上传素材(求助nodejs转php)
MPWechat.prototype.uploadMedia = function(medianame,reqData,callback){<br> tools.log('uploadMedia start ...');<br> var boundary = 'tvmin';<br> var max = 9007199254740992;<br> var dec = Math.random() * max;<br> var hex = boundary + dec.toString(36);<br> var mimes = {<br> //image<br> '.bmp': 'image/bmp',<br> '.png': 'image/png',<br> '.gif': 'image/gif',<br> '.jpg': 'image/jpeg',<br> '.jpeg': 'image/jpeg',<br> /oice<br> '.mp3': 'audio/mp3',<br> '.wav': 'audio/x-wav',<br> '.amr': 'audior',<br> '.wma': 'audio/x-ms-wma',<br> /ideo<br> '.mp4': 'video/mp4',<br> '.rm': 'video/rm',<br> '.rmvb': 'videond.rn-realvideo',<br> '.wmv': 'video/x-ms-wmv',<br> '.avi': 'video/x-msvideo',<br> '.mpg': 'video/mpeg',<br> '.mpeg': 'video/mpeg'<br> };<br> var ext = path.extname(medianame).toLowerCase();<br> var mime = mimes[ext];<br> var boundaryKey = '----WebKitFormBoundary' + hex;<br> var payload = '\r\n\r\n--' + boundaryKey + '\r\n'<br> + 'Content-Disposition: form-data; name="uploadfile"; filename="'+ medianame +'"\r\n'<br> + 'Content-Type: '+ mime +'\r\n\r\n';<br> var enddata = '\r\n--' + boundaryKey + '\r\n'<br> + 'Content-Disposition: form-data; name="formId"\r\n\r\n'<br> + '--' + boundaryKey + '--';<br> var contentLength = Buffer.byteLength(payload,'utf8') + reqData.length + Buffer.byteLength(enddata,'utf8');<br> var options = {<br> host: host,<br> port: 443,<br> method: 'POST',<br> path: '/cgi-bin/uploadmaterial?cgi=uploadmaterial&type=0&token='+ this.token +'&t=iframe-uploadfile&lang=zh_CN&formId=null',<br> headers: {<br> 'Content-Type': 'multipart/form-data; boundary='+boundaryKey,<br> 'Content-Length': contentLength,<br> 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31',<br> 'Cookie': this.cookie,<br> 'Referer': 'https://'+ host +'/cgi-bin/indexpage?token='+ this.token +'&lang=zh_CN&t=wxm-upload&lang=zh_CN&type=0&fromId=file_from_1341151893625'<br> }<br> };<br> var req = https.request(options, function(response) {<br> var statusCode = response.statusCode;<br>// console.log('STATUS: ' + statusCode,options);<br> response.setEncoding('utf8');<br> var data = '';<br> response.on('data', function(chunk) {<br> data += chunk;<br> }).on('end',function(){<br> callback(data.match(/formId, '(\d+)'/)[1]);<br> });<br> });<br> req.write(payload,'utf8');<br> req.write(reqData,'binary');<br> req.write(enddata,'utf8');<br> req.end();<br><br> req.on('error', function(e) {<div class="clear"> </div>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

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

Solution: Your organization requires you to change your PIN

How to adjust window border settings on Windows 11: Change color and size

How to change title bar color on Windows 11?

How to enable or disable taskbar thumbnail previews on Windows 11

OOBELANGUAGE Error Problems in Windows 11/10 Repair

10 Ways to Adjust Brightness on Windows 11

How to turn off private browsing authentication for iPhone in Safari?
