fix:syncBook用live_image、product/save用live_image[]匹配服务端form标签
This commit is contained in:
parent
ba0829ba04
commit
26298368ca
@ -2129,8 +2129,7 @@ export default {
|
|||||||
|
|
||||||
var sign = calculateSign(params)
|
var sign = calculateSign(params)
|
||||||
params.sign = sign
|
params.sign = sign
|
||||||
var formBody = buildFormBodyWithImages(params, imageUrls)
|
var formBody = buildFormBodyWithImages(params, imageUrls, 'live_image')
|
||||||
|
|
||||||
const apiUrl = 'https://psi.api.buzhiyushu.cn/api/syncBook'
|
const apiUrl = 'https://psi.api.buzhiyushu.cn/api/syncBook'
|
||||||
const token = uni.getStorageSync('token') || ''
|
const token = uni.getStorageSync('token') || ''
|
||||||
console.log('【syncBook】请求地址:', apiUrl)
|
console.log('【syncBook】请求地址:', apiUrl)
|
||||||
@ -2280,7 +2279,7 @@ export default {
|
|||||||
// 计算签名(与仓库列表一致的签名算法)
|
// 计算签名(与仓库列表一致的签名算法)
|
||||||
var sign = calculateSign(params)
|
var sign = calculateSign(params)
|
||||||
params.sign = sign
|
params.sign = sign
|
||||||
var formBody = buildFormBodyWithImages(params, imageUrls)
|
var formBody = buildFormBodyWithImages(params, imageUrls, 'live_image')
|
||||||
|
|
||||||
const apiUrl = 'https://psi.api.buzhiyushu.cn/api/syncBook'
|
const apiUrl = 'https://psi.api.buzhiyushu.cn/api/syncBook'
|
||||||
console.log('【syncBook】请求地址:', apiUrl)
|
console.log('【syncBook】请求地址:', apiUrl)
|
||||||
@ -2392,8 +2391,8 @@ export default {
|
|||||||
}
|
}
|
||||||
var sign = calculateSign(params)
|
var sign = calculateSign(params)
|
||||||
params.sign = sign
|
params.sign = sign
|
||||||
// 构建 form body(live_image[] 每个 URL 单独发送)
|
// 构建 form body(live_image[] 每个 URL 单独发送,product/save 需要 live_image[])
|
||||||
var formBody = buildFormBodyWithImages(params, imageUrls)
|
var formBody = buildFormBodyWithImages(params, imageUrls, 'live_image[]')
|
||||||
var saveUrl = 'https://psi.api.buzhiyushu.cn/api/product/save'
|
var saveUrl = 'https://psi.api.buzhiyushu.cn/api/product/save'
|
||||||
console.log('【保存商品】请求地址:', saveUrl)
|
console.log('【保存商品】请求地址:', saveUrl)
|
||||||
console.log('【保存商品】请求参数:', params)
|
console.log('【保存商品】请求参数:', params)
|
||||||
|
|||||||
@ -333,18 +333,19 @@ export function searchBookByIsbn(isbn) {
|
|||||||
export { calculateSign }
|
export { calculateSign }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建 form-urlencoded body,支持 live_image[] 以多个单独字段发送
|
* 构建 form-urlencoded body,支持图片以多个单独字段发送
|
||||||
* @param {Object} params - 已包含 sign 的 params 对象(live_image[] 为逗号拼接)
|
* @param {Object} params - 已包含 sign 的 params 对象(live_image[] 为逗号拼接)
|
||||||
* @param {string[]} imageUrls - 图片 URL 数组
|
* @param {string[]} imageUrls - 图片 URL 数组
|
||||||
|
* @param {string} imageKey - 图片字段名(如 'live_image' 或 'live_image[]')
|
||||||
* @returns {string} form-urlencoded 字符串
|
* @returns {string} form-urlencoded 字符串
|
||||||
*/
|
*/
|
||||||
function buildFormBodyWithImages(params, imageUrls) {
|
function buildFormBodyWithImages(params, imageUrls, imageKey) {
|
||||||
var parts = []
|
var parts = []
|
||||||
for (var key in params) {
|
for (var key in params) {
|
||||||
if (key === 'live_image[]') {
|
if (key === imageKey) {
|
||||||
// 每个 URL 单独发送
|
// 每个 URL 单独发送
|
||||||
for (var j = 0; j < imageUrls.length; j++) {
|
for (var j = 0; j < imageUrls.length; j++) {
|
||||||
parts.push(encodeURIComponent('live_image[]') + '=' + encodeURIComponent(imageUrls[j]))
|
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(imageUrls[j]))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(String(params[key])))
|
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(String(params[key])))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user