我目前正在使用微信管理平台api编写节点应用程序。但是当我尝试使用管理平台api将拇指媒体图像文件上传到腾讯服务器时,我目前卡住了。我有一个在微信注册的用户帐户,我可以使用admin api平台成功获取我的微信帐户的访问令牌和关注者列表。 以下是我用来上传到微信服务器的微信代码:
create table TransactionTable
(
Customer varchar(50) null,
Amount_Per_Item int Null,
Available_Amount int null,
Outstanding_Amount varchar(50) null
)
insert into TransactionTable values
('x',50000,70000,null),
('x',20000,70000,null),
('y',10000,50000,null),
('y',40000,50000,null),
('y',30000,50000,null),
('z',90000,150000,null),
('z',70000,150000,null)
update t1 set t1.Outstanding_Amount=t2.TotalAmountPerItem-t2.TotalAvailableAmount
from TransactionTable t1 inner join (
select Customer
,sum(Amount_Per_Item) as TotalAmountPerItem
,max(Available_Amount) as TotalAvailableAmount
from TransactionTable
group by Customer) t2 on t1.Customer=t2.Customer
select * from TransactionTable
当我在节点中运行上述函数时,我得到HTTP响应代码为502.以及下面的text / html响应:
function uploadThumb(){
console.log('Inside uploadThumb');
var promise = new Promise(function(resolve,reject){
resolve({
then:function(onfullfill,onreject){
fs.readdir(thumb_dir,function(err,files){
if (err){
onreject();
throw err;
}
files.forEach(function(file){
fs.stat(thumb_dir+file, function(err, stats) {
var type = "thumb";
var upload_url = "http://file.api.wechat.com/cgi-bin/media/upload?access_token="+access_token+"&type="+type;
console.log('file name :'+file+': size :'+stats.size);
restler.post(upload_url, {
multipart: true,
data: {
"media['filename']": file,
"media['content type']":"image/png",
"media['file length']": stats.size,
"media['file']": restler.file(thumb_dir+file, null, stats.size, null, "image/png")
}
}).on("complete", function(fdata,response) {
console.log('Status: ' + response.statusCode);
console.log('Thumb image data :'+fdata);
console.dir(response);
//var obj = JSON.parse(fdata);
//saveUploadMediaToDB(obj,file).then(onfullfill());
onfullfill();
});
});
});
});
}
});
});
return promise;
}
请指出正确的方向帮助我,这种做法是否正确,或者我做的事情基本上都是冤屈。
答案 0 :(得分:0)
根据我在Restler文档中找到的内容,并将其与WeChat API文档进行比较,您可能会指定不正确的请求参数。
我认为你可能需要更换
restler.post(upload_url, {
multipart: true,
data: {
"media['filename']": file,
"media['content type']":"image/png",
"media['file length']": stats.size,
"media['file']": restler.file(thumb_dir+file, null, stats.size, null, "image/png")
}
[...]
有以下几点:
restler.post(upload_url, {
multipart: true,
data: {
"media": restler.file(thumb_dir+file, null, stats.size, null, "image/png")
}
[...]