我正在尝试使用以下代码发布履行
我正在使用json将其转换为xml,因为我的json是
var ShipJson = {
"AmazonEnvelope": {
"-xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"-xsi:noNamespaceSchemaLocation": "amznenvelope.xsd",
"Header": {
"DocumentVersion": "1.01",
"MerchantIdentifier": MRChID
},
"MessageType": "OrderFulfillment",
"Message": {
"MessageID": "1",
"OrderFulfillment": {
"MerchantOrderID" : OrderId,
"MerchantFulfillmentID":"1234567",
"FulfillmentDate": "2017-06-20T00:36:33-08:00",
"FulfillmentData": {
"CarrierName": "UPS",
"ShippingMethod": "Second Day",
"ShipperTrackingNumber": "1234567890"
},
"Item": {
"MerchantOrderItemID":"1234567",
"MerchantFulfillmentItemID": "1234567",
"Quantity": "2"
}
}
}
}
};
这个json我转换成xml然后使用crypto js转换为bae64-md5
var xml = cm.util.Formatter.json2xml(ShipJson);
var ContentMD5Value = CryptoJS.MD5(xml,true);
var MD5Base64 = CryptoJS.enc.Base64.stringify(ContentMD5Value);
var that = this;
var uri = "/";
var today = new Date();
time = today.toISOString();
var parameters = {
"AWSAccessKeyId":;kjuhjfgd,
"Action":"SubmitFeed",
"ContentMD5Value": MD5Base64,
"FeedType":"_POST_ORDER_FULFILLMENT_DATA_",
"Merchant":lgtjljtd,
"PurgeAndReplace":"false",
"SignatureMethod":"HmacSHA256",
"SignatureVersion":"2",
"Timestamp": time,
"Version":"2009-01-01"
};
var parameters1 = $.param(parameters);
var messageToEncrypt = sap.ui.getCore.method+"\n"+sap.ui.getCore.host+"\n"+ uri +"\n"+parameters1;
var hash = CryptoJS.HmacSHA256(messageToEncrypt, sap.ui.getCore().secreteKey);
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
var parameters100 = {
"AWSAccessKeyId":jhfjfzhkhgs,
"Action":"SubmitFeed",
"Merchant":gjdhjdgfzgd,
"SignatureVersion":"2",
"Timestamp": time,
"Version":"2009-01-01",
"ContentMD5Value": MD5Base64,
"Signature":hashInBase64,
"SignatureMethod":"HmacSHA256",
"FeedType":"_POST_ORDER_FULFILLMENT_DATA_",
"PurgeAndReplace":"false"
};
var parameters101 = $.param( parameters100 );
var mwsRequest = sap.ui.getCore.protocol+"://"+sap.ui.getCore.host;
var odatamodel = new sap.ui.model.odata.ODataModel(mwsRequest, {
headers: {
"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"
}
});
sap.ui.getCore().setModel(odatamodel);
OData.request({
requestUri: mwsRequest+ "/?" + parameters101,
method: "POST",
headers: {
},
data: {}
},
function(data, response) {
},
function(err,response) {
var res = err.response.body;
}
);
但是我的MD5内容值不匹配错误
"<?xml version="1.0"?>
<ErrorResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/"><Error><Type>Sender</Type><Code>ContentMD5DoesNotMatch</Code><Message>the Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed</Message><Detail/></Error><RequestID>43637524-65a0-42be-bdfc-3d78290e8810</RequestID></ErrorResponse>"
请帮我解决错误的方法,或者我错过了什么或者我的MD5库错了?
答案 0 :(得分:1)
您计算MD5的方式似乎是正确的。但是,您发送ContentMD5Value
作为请求的一部分。我不确定这是否是一种可接受的替代方案,我见过的所有代码都会发送一个http标头:Content-MD5: stringWithMD5inBase64
以及Content-Type: text/xml
。
我不确定sap.ui的所有内容是什么(而且我对JavaScript并不是很好),但我猜你需要更改headers
OData.request中的元素。但话说回来,我还没有看到你实际发送xml
的内容?