sf-apple-sdk
Version:
Apple SF SDK for SF WMS
49 lines (48 loc) • 1.66 kB
JavaScript
import { generateSFDigest } from "./generateSFDigest.js";
export function post(options) {
const { url, checkword, sysSource, serviceCode, specialStr, body } = options;
return new Promise(async (resolve, reject) => {
const headers = {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
Checkword: checkword,
serviceCode: serviceCode,
sysSource: sysSource,
};
const jsonStr = JSON.stringify(body);
const dataDigest = generateSFDigest(jsonStr, specialStr);
const params = new URLSearchParams({
logistics_interface: jsonStr,
data_digest: dataDigest,
});
try {
const resp = await fetch(url, {
method: "POST",
headers: headers,
body: params,
});
console.log({
method: "POST",
url,
headers,
body: {
logistics_interface: jsonStr,
data_digest: dataDigest,
},
});
// 检查响应状态
if (!resp.ok) {
const errorText = await resp.text();
throw new Error(`HTTP error! Status: ${resp.status}, Body: ${errorText}`);
}
// 解析响应的 JSON
const text = await resp.text();
console.log(text);
const json = JSON.parse(text);
resolve(json);
}
catch (error) {
console.error("请求失败:", error);
reject(error);
}
});
}