修复孔夫子搜索:传入PHPSESSID+响应字段映射使用zhizhu正确字段名(title/priceText/shopName等)
This commit is contained in:
parent
4baf41b1c9
commit
d9b50574aa
@ -934,7 +934,7 @@ export default {
|
||||
})
|
||||
|
||||
// 2. 搜索孔夫子 - 获取在售商品信息
|
||||
searchProducts(this.isbn).then(data => {
|
||||
searchProducts(this.isbn, { phpsessid: this.kongfzToken || '' }).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: '',
|
||||
totalPrice: item.prodNum + '本在售',
|
||||
image: item.imgBigUrl || '',
|
||||
totalPrice: item.priceText || '',
|
||||
bookPrice: '',
|
||||
shippingFee: '',
|
||||
condition: item.binding || '',
|
||||
shopName: item.press || '',
|
||||
bookName: item.bookName || '',
|
||||
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 || '',
|
||||
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 }
|
||||
|
||||
@ -146,30 +146,88 @@ export default {
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索孔夫子商品(公开搜索API,无需登录)
|
||||
* 搜索孔夫子在售商品
|
||||
* @param {string} keyword ISBN或书名
|
||||
* @param {number} page 页码
|
||||
* @param {object} options 可选参数 {page, sortType, quality, userArea, press, author, phpsessid}
|
||||
* @returns {Promise<{total: number, list: Array}>}
|
||||
*/
|
||||
export function searchProducts(keyword, page = 1) {
|
||||
export function searchProducts(keyword, options = {}) {
|
||||
const {
|
||||
page = 1,
|
||||
sortType = '7',
|
||||
quality = '',
|
||||
userArea = '13003000000',
|
||||
press = '',
|
||||
author = '',
|
||||
phpsessid = ''
|
||||
} = options
|
||||
|
||||
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: `https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/isbnList?dataType=0&keyword=${encodeURIComponent(keyword)}&page=${page}`,
|
||||
url: url,
|
||||
method: 'GET',
|
||||
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"'
|
||||
},
|
||||
header: header,
|
||||
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)
|
||||
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: [] })
|
||||
}
|
||||
} else if (res.statusCode === 200 && res.data && res.data.data) {
|
||||
resolve(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 || []
|
||||
})
|
||||
} else {
|
||||
resolve({ total: 0, list: [] })
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user