From a5bb2e3b9bd81449af253bd721d9a5e9b632745a Mon Sep 17 00:00:00 2001 From: "97694732@qq.com" Date: Wed, 3 Jun 2026 16:08:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=94=E5=A4=AB=E5=AD=90?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=8E=A5=E5=8F=A3:=20keyword/list=20+=20PHPS?= =?UTF-8?q?ESSID=20+=20=E6=AD=A3=E7=A1=AE=E5=AD=97=E6=AE=B5=E6=98=A0?= =?UTF-8?q?=E5=B0=84(=E4=B8=8Ezhizhu=E4=B8=80=E8=87=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/upload/upload.vue | 33 ++++++++++++++++++++++----------- utils/kongfz.js | 39 ++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/pages/upload/upload.vue b/pages/upload/upload.vue index 831520f..17c9afb 100644 --- a/pages/upload/upload.vue +++ b/pages/upload/upload.vue @@ -210,10 +210,13 @@ + {{ item.bookName || '未知书名' }} {{ item.author || item.shopName || '' }} {{ item.totalPrice }} - {{ item.condition || item.pubDate || '' }} + 运{{ item.shippingFee }} + {{ item.condition || '' }} + {{ item.shopName || '' }} @@ -934,7 +937,8 @@ export default { }) // 2. 搜索孔夫子 - 获取在售商品信息 - searchProducts(this.isbn).then(data => { + const phpsessid = this.kongfzToken || uni.getStorageSync('kongfz_phpsessid') || '' + searchProducts(this.isbn, { phpsessid }).then(data => { this.isLoading = false if (data && data.total > 0) { // 市场统计 @@ -947,16 +951,16 @@ export default { // 在售商品列表(最多12条) const list = (data.list || []).slice(0, 12) this.productList = list.map(item => ({ - image: '', - totalPrice: item.prodNum + '本在售', - bookPrice: '', - shippingFee: '', - condition: item.binding || '', - shopName: item.press || '', - bookName: item.bookName || '', + image: item.imgBigUrl || '', + totalPrice: item.priceText || '', + bookPrice: (item.priceText || '0').replace(/[^\d.]/g, ''), + shippingFee: item.postage && item.postage.shippingList && item.postage.shippingList.length > 0 ? item.postage.shippingList[0].shippingFee || '0' : '0', + condition: item.qualityText || '', + shopName: item.shopName || '', + bookName: item.title || '', author: item.author || '', - pubDate: item.pubDate || '', - bookId: item.bookId || '' + pubDate: item.pubDateText || '', + bookId: item.id || '' })) } else { this.marketData = { onSale: 0, old: 0, new: 0, sold: 0 } @@ -1870,6 +1874,13 @@ export default { width: 100%; } +.grid-price-detail { + font-size: 18rpx; + color: #909399; + display: block; + text-align: center; +} + .grid-book-name { font-size: 24rpx; color: #303133; diff --git a/utils/kongfz.js b/utils/kongfz.js index 15912ff..7af4ad7 100644 --- a/utils/kongfz.js +++ b/utils/kongfz.js @@ -146,30 +146,39 @@ export default { } /** - * 搜索孔夫子商品(公开搜索API,无需登录) + * 搜索孔夫子在售商品(需要登录Cookie) * @param {string} keyword ISBN或书名 - * @param {number} page 页码 + * @param {object} options {phpsessid, page} * @returns {Promise<{total: number, list: Array}>} + * list中每项: {id, title, author, press, priceText, imgBigUrl, shopName, qualityText, pubDateText, postage} */ -export function searchProducts(keyword, page = 1) { +export function searchProducts(keyword, options = {}) { + const { phpsessid = '', page = 1 } = options return new Promise((resolve, reject) => { uni.request({ - url: `https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/isbnList?dataType=0&keyword=${encodeURIComponent(keyword)}&page=${page}`, + url: 'https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/list', method: 'GET', + data: { + dataType: 0, + keyword: keyword, + page: page, + userArea: '13003000000' + }, 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"' + 'Cookie': phpsessid ? `PHPSESSID=${phpsessid}` : '' }, success: (res) => { - console.log('孔夫子搜索响应:', res.statusCode, res.data) - if (res.statusCode === 200 && res.data && res.data.status === 1 && res.data.data) { - resolve(res.data.data) - } else if (res.statusCode === 200 && res.data && res.data.data) { - resolve(res.data.data) + console.log('孔夫子在售搜索响应:', res.statusCode, res.data) + if (res.statusCode === 200 && res.data && res.data.status === 1) { + const itemResp = res.data.data && res.data.data.itemResponse + if (itemResp) { + resolve({ + total: itemResp.total || 0, + list: itemResp.list || [] + }) + } else { + resolve({ total: 0, list: [] }) + } } else { resolve({ total: 0, list: [] }) }