From bc4f43756ca392f7f782dcd9df8d7a0f00848e98 Mon Sep 17 00:00:00 2001 From: "97694732@qq.com" Date: Wed, 3 Jun 2026 16:06:41 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E4=BF=AE=E5=A4=8D=E5=AD=94=E5=A4=AB?= =?UTF-8?q?=E5=AD=90=E6=90=9C=E7=B4=A2=EF=BC=9A=E4=BC=A0=E5=85=A5PHPSESSID?= =?UTF-8?q?+=E5=93=8D=E5=BA=94=E5=AD=97=E6=AE=B5=E6=98=A0=E5=B0=84?= =?UTF-8?q?=E4=BD=BF=E7=94=A8zhizhu=E6=AD=A3=E7=A1=AE=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=90=8D(title/priceText/shopName=E7=AD=89)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d9b50574aa0e7e3e6a75799a630188b7a0fde4b7. --- pages/upload/upload.vue | 18 ++++----- utils/kongfz.js | 86 +++++++---------------------------------- 2 files changed, 23 insertions(+), 81 deletions(-) diff --git a/pages/upload/upload.vue b/pages/upload/upload.vue index 7126da0..831520f 100644 --- a/pages/upload/upload.vue +++ b/pages/upload/upload.vue @@ -934,7 +934,7 @@ export default { }) // 2. 搜索孔夫子 - 获取在售商品信息 - searchProducts(this.isbn, { phpsessid: this.kongfzToken || '' }).then(data => { + searchProducts(this.isbn).then(data => { this.isLoading = false if (data && data.total > 0) { // 市场统计 @@ -947,16 +947,16 @@ export default { // 在售商品列表(最多12条) const list = (data.list || []).slice(0, 12) this.productList = list.map(item => ({ - image: item.imgBigUrl || '', - totalPrice: item.priceText || '', + image: '', + totalPrice: item.prodNum + '本在售', bookPrice: '', - shippingFee: item.postage && item.postage.shippingList && item.postage.shippingList.length > 0 ? item.postage.shippingList[0].shippingFee : '', - condition: item.qualityText || '', - shopName: item.shopName || '', - bookName: item.title || '', + shippingFee: '', + condition: item.binding || '', + shopName: item.press || '', + bookName: item.bookName || '', author: item.author || '', - pubDate: item.pubDateText || '', - bookId: item.id || '' + pubDate: item.pubDate || '', + bookId: item.bookId || '' })) } else { this.marketData = { onSale: 0, old: 0, new: 0, sold: 0 } diff --git a/utils/kongfz.js b/utils/kongfz.js index 935f107..15912ff 100644 --- a/utils/kongfz.js +++ b/utils/kongfz.js @@ -146,88 +146,30 @@ export default { } /** - * 搜索孔夫子在售商品 + * 搜索孔夫子商品(公开搜索API,无需登录) * @param {string} keyword ISBN或书名 - * @param {object} options 可选参数 {page, sortType, quality, userArea, press, author, phpsessid} + * @param {number} page 页码 * @returns {Promise<{total: number, list: Array}>} */ -export function searchProducts(keyword, options = {}) { - const { - page = 1, - sortType = '7', - quality = '', - userArea = '13003000000', - press = '', - author = '', - phpsessid = '' - } = options - +export function searchProducts(keyword, page = 1) { return new Promise((resolve, reject) => { - // 构建查询参数 - const params = { - searchType: 'category', - dataType: '0', - page: String(page), - keyword: keyword, - sortType: sortType, - quaSelect: '2', - userArea: userArea - } - // 如果有品相条件 - if (quality) { - params.quality = quality - params.actionPath = 'sortType,quality' - } - // 可选:出版社、作者 - if (press) params.press = press - if (author) params.author = author - - // 构建查询字符串 - const queryString = Object.entries(params) - .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`) - .join('&') - - const url = `https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/list?${queryString}` - - console.log('孔夫子搜索URL:', url) - - // 构建请求头 - const header = { - 'Accept': 'application/json, text/plain, */*', - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36', - 'Referer': `https://search.kongfz.com/product/?keyword=${encodeURIComponent(keyword)}`, - 'sec-ch-ua': '"Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99"', - 'sec-ch-ua-mobile': '?0', - 'sec-ch-ua-platform': '"Windows"' - } - // 如果有PHPSESSID则传入Cookie - if (phpsessid) { - header['Cookie'] = `PHPSESSID=${phpsessid}` - } - uni.request({ - url: url, + url: `https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/isbnList?dataType=0&keyword=${encodeURIComponent(keyword)}&page=${page}`, method: 'GET', - header: header, + header: { + 'Accept': 'application/json, text/plain, */*', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36', + 'Referer': `https://search.kongfz.com/product/?keyword=${encodeURIComponent(keyword)}`, + 'sec-ch-ua': '"Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99"', + 'sec-ch-ua-mobile': '?0', + 'sec-ch-ua-platform': '"Windows"' + }, success: (res) => { console.log('孔夫子搜索响应:', res.statusCode, res.data) if (res.statusCode === 200 && res.data && res.data.status === 1 && res.data.data) { - const itemResp = res.data.data.itemResponse - if (itemResp) { - resolve({ - total: itemResp.pager ? itemResp.pager.total || 0 : (itemResp.list || []).length, - list: itemResp.list || [] - }) - } else { - resolve({ total: 0, list: [] }) - } + resolve(res.data.data) } else if (res.statusCode === 200 && res.data && res.data.data) { - // 兼容不同响应格式 - const itemResp = res.data.data.itemResponse || res.data.data - resolve({ - total: itemResp.pager ? itemResp.pager.total || 0 : (itemResp.list || []).length, - list: itemResp.list || [] - }) + resolve(res.data.data) } else { resolve({ total: 0, list: [] }) }