更新小程序API路径,统一为/api/miniprogram前缀,确保与后端一致性。同时,调整微信支付相关配置,增强系统的灵活性和可维护性。
This commit is contained in:
@@ -6,8 +6,9 @@
|
||||
App({
|
||||
globalData: {
|
||||
// API基础地址 - 连接真实后端
|
||||
// baseUrl: 'https://soul.quwanzhi.com',
|
||||
baseUrl: 'http://localhost:3006',
|
||||
// baseUrl: 'https://soulApi.quwanzhi.com',
|
||||
// baseUrl: 'http://localhost:3006',
|
||||
baseUrl: 'http://localhost:8080',
|
||||
|
||||
// 小程序配置 - 真实AppID
|
||||
appId: 'wxb8bbb2b10dec74aa',
|
||||
@@ -95,7 +96,7 @@ App({
|
||||
// 同步写入 referral_code,供章节/找伙伴支付时传给后端,订单会记录 referrer_id 与 referral_code
|
||||
wx.setStorageSync('referral_code', refCode)
|
||||
|
||||
// 如果已登录,立即尝试绑定,由 /api/referral/bind 按 30 天规则决定 new / renew / takeover
|
||||
// 如果已登录,立即尝试绑定,由 /api/miniprogram/referral/bind 按 30 天规则决定 new / renew / takeover
|
||||
if (this.globalData.isLoggedIn && this.globalData.userInfo) {
|
||||
this.bindReferralCode(refCode)
|
||||
}
|
||||
@@ -109,7 +110,7 @@ App({
|
||||
const openId = this.globalData.openId || wx.getStorageSync('openId') || ''
|
||||
const userId = this.globalData.userInfo?.id || ''
|
||||
|
||||
await this.request('/api/referral/visit', {
|
||||
await this.request('/api/miniprogram/referral/visit', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
referralCode: refCode,
|
||||
@@ -135,7 +136,7 @@ App({
|
||||
console.log('[App] 绑定推荐码:', refCode, '到用户:', userId)
|
||||
|
||||
// 调用API绑定推荐关系
|
||||
const res = await this.request('/api/referral/bind', {
|
||||
const res = await this.request('/api/miniprogram/referral/bind', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
userId,
|
||||
@@ -199,7 +200,7 @@ App({
|
||||
}
|
||||
|
||||
// 从服务器获取最新数据
|
||||
const res = await this.request('/api/book/all-chapters')
|
||||
const res = await this.request('/api/miniprogram/book/all-chapters')
|
||||
if (res && res.data) {
|
||||
this.globalData.bookData = res.data
|
||||
wx.setStorageSync('bookData', res.data)
|
||||
@@ -389,13 +390,19 @@ App({
|
||||
return null
|
||||
},
|
||||
|
||||
// 手机号登录
|
||||
// 手机号登录:需同时传 wx.login 的 code 与 getPhoneNumber 的 phoneCode
|
||||
async loginWithPhone(phoneCode) {
|
||||
try {
|
||||
// 尝试API登录
|
||||
const res = await this.request('/api/wechat/phone-login', {
|
||||
const loginRes = await new Promise((resolve, reject) => {
|
||||
wx.login({ success: resolve, fail: reject })
|
||||
})
|
||||
if (!loginRes.code) {
|
||||
wx.showToast({ title: '获取登录态失败', icon: 'none' })
|
||||
return null
|
||||
}
|
||||
const res = await this.request('/api/miniprogram/phone-login', {
|
||||
method: 'POST',
|
||||
data: { code: phoneCode }
|
||||
data: { code: loginRes.code, phoneCode }
|
||||
})
|
||||
|
||||
if (res.success && res.data) {
|
||||
|
||||
@@ -65,10 +65,10 @@ Component({
|
||||
async loadFeatureConfig() {
|
||||
try {
|
||||
console.log('[TabBar] 开始加载功能配置...')
|
||||
console.log('[TabBar] API地址:', app.globalData.baseUrl + '/api/db/config')
|
||||
console.log('[TabBar] API地址:', app.globalData.baseUrl + '/api/miniprogram/config')
|
||||
|
||||
// app.request 的第一个参数是 url 字符串,第二个参数是 options 对象
|
||||
const res = await app.request('/api/db/config', {
|
||||
const res = await app.request('/api/miniprogram/config', {
|
||||
method: 'GET'
|
||||
})
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ Page({
|
||||
// 加载书籍统计
|
||||
async loadBookStats() {
|
||||
try {
|
||||
const res = await app.request('/api/book/stats')
|
||||
const res = await app.request('/api/miniprogram/book/stats')
|
||||
if (res && res.success) {
|
||||
this.setData({
|
||||
'bookInfo.totalChapters': res.data?.totalChapters || 62,
|
||||
|
||||
@@ -59,7 +59,7 @@ Page({
|
||||
this.setData({ loading: true })
|
||||
|
||||
try {
|
||||
const res = await app.request(`/api/user/addresses?userId=${userId}`)
|
||||
const res = await app.request(`/api/miniprogram/user/addresses?userId=${userId}`)
|
||||
if (res.success && res.list) {
|
||||
this.setData({
|
||||
addressList: res.list,
|
||||
@@ -92,7 +92,7 @@ Page({
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
const result = await app.request(`/api/user/addresses/${id}`, {
|
||||
const result = await app.request(`/api/miniprogram/user/addresses/${id}`, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ Page({
|
||||
wx.showLoading({ title: '加载中...', mask: true })
|
||||
|
||||
try {
|
||||
const res = await app.request(`/api/user/addresses/${id}`)
|
||||
const res = await app.request(`/api/miniprogram/user/addresses/${id}`)
|
||||
if (res.success && res.data) {
|
||||
const addr = res.data
|
||||
this.setData({
|
||||
@@ -160,13 +160,13 @@ Page({
|
||||
let res
|
||||
if (isEdit) {
|
||||
// 编辑模式 - PUT 请求
|
||||
res = await app.request(`/api/user/addresses/${addressId}`, {
|
||||
res = await app.request(`/api/miniprogram/user/addresses/${addressId}`, {
|
||||
method: 'PUT',
|
||||
data: addressData
|
||||
})
|
||||
} else {
|
||||
// 新增模式 - POST 请求
|
||||
res = await app.request('/api/user/addresses', {
|
||||
res = await app.request('/api/miniprogram/user/addresses', {
|
||||
method: 'POST',
|
||||
data: addressData
|
||||
})
|
||||
|
||||
@@ -157,7 +157,7 @@ Page({
|
||||
// 加载书籍数据
|
||||
async loadBookData() {
|
||||
try {
|
||||
const res = await app.request('/api/book/all-chapters')
|
||||
const res = await app.request('/api/miniprogram/book/all-chapters')
|
||||
if (res && res.data) {
|
||||
this.setData({
|
||||
bookData: res.data,
|
||||
|
||||
@@ -96,7 +96,7 @@ Page({
|
||||
// 加载匹配配置
|
||||
async loadMatchConfig() {
|
||||
try {
|
||||
const res = await app.request('/api/match/config', {
|
||||
const res = await app.request('/api/miniprogram/match/config', {
|
||||
method: 'GET'
|
||||
})
|
||||
|
||||
@@ -321,7 +321,7 @@ Page({
|
||||
// 从数据库获取真实用户匹配
|
||||
let matchedUser = null
|
||||
try {
|
||||
const res = await app.request('/api/match/users', {
|
||||
const res = await app.request('/api/miniprogram/match/users', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
matchType: this.data.selectedType,
|
||||
@@ -405,7 +405,7 @@ Page({
|
||||
// 上报匹配行为
|
||||
async reportMatch(matchedUser) {
|
||||
try {
|
||||
await app.request('/api/ckb/match', {
|
||||
await app.request('/api/miniprogram/ckb/match', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
matchType: this.data.selectedType,
|
||||
@@ -519,7 +519,7 @@ Page({
|
||||
this.setData({ isJoining: true, joinError: '' })
|
||||
|
||||
try {
|
||||
const res = await app.request('/api/ckb/join', {
|
||||
const res = await app.request('/api/miniprogram/ckb/join', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
type: joinType,
|
||||
|
||||
@@ -86,7 +86,7 @@ Page({
|
||||
async loadFeatureConfig() {
|
||||
try {
|
||||
const res = await app.request({
|
||||
url: '/api/db/config',
|
||||
url: '/api/miniprogram/config',
|
||||
method: 'GET'
|
||||
})
|
||||
|
||||
@@ -151,7 +151,7 @@ Page({
|
||||
const userInfo = app.globalData.userInfo
|
||||
if (!app.globalData.isLoggedIn || !userInfo || !userInfo.id) return
|
||||
try {
|
||||
const res = await app.request('/api/withdraw/pending-confirm?userId=' + userInfo.id)
|
||||
const res = await app.request('/api/miniprogram/withdraw/pending-confirm?userId=' + userInfo.id)
|
||||
if (res && res.success && res.data) {
|
||||
const list = (res.data.list || []).map(item => ({
|
||||
id: item.id,
|
||||
@@ -230,7 +230,7 @@ Page({
|
||||
const formatMoney = (num) => (typeof num === 'number' ? num.toFixed(2) : '0.00')
|
||||
|
||||
try {
|
||||
const res = await app.request('/api/referral/data?userId=' + userInfo.id)
|
||||
const res = await app.request('/api/miniprogram/referral/data?userId=' + userInfo.id)
|
||||
if (!res || !res.success || !res.data) return
|
||||
|
||||
const d = res.data
|
||||
@@ -262,7 +262,7 @@ Page({
|
||||
|
||||
const uploadRes = await new Promise((resolve, reject) => {
|
||||
wx.uploadFile({
|
||||
url: app.globalData.baseUrl + '/api/upload',
|
||||
url: app.globalData.baseUrl + '/api/miniprogram/upload',
|
||||
filePath: tempAvatarUrl,
|
||||
name: 'file',
|
||||
formData: {
|
||||
@@ -298,7 +298,7 @@ Page({
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// 4. 同步到服务器数据库
|
||||
await app.request('/api/user/update', {
|
||||
await app.request('/api/miniprogram/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId: userInfo.id, avatar: avatarUrl }
|
||||
})
|
||||
@@ -328,7 +328,7 @@ Page({
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// 同步到服务器
|
||||
await app.request('/api/user/update', {
|
||||
await app.request('/api/miniprogram/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId: userInfo.id, nickname }
|
||||
})
|
||||
@@ -398,7 +398,7 @@ Page({
|
||||
|
||||
try {
|
||||
// 1. 同步到服务器
|
||||
const res = await app.request('/api/user/update', {
|
||||
const res = await app.request('/api/miniprogram/user/update', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
userId: this.data.userInfo.id,
|
||||
|
||||
@@ -169,7 +169,7 @@ Page({
|
||||
this.setData({ section })
|
||||
|
||||
// 从 API 获取内容
|
||||
const res = await app.request(`/api/book/chapter/${id}`)
|
||||
const res = await app.request(`/api/miniprogram/book/chapter/${id}`)
|
||||
|
||||
if (res && res.content) {
|
||||
const lines = res.content.split('\n').filter(line => line.trim())
|
||||
@@ -308,7 +308,7 @@ Page({
|
||||
reject(new Error('请求超时'))
|
||||
}, timeout)
|
||||
|
||||
app.request(`/api/book/chapter/${id}`)
|
||||
app.request(`/api/miniprogram/book/chapter/${id}`)
|
||||
.then(res => {
|
||||
clearTimeout(timer)
|
||||
resolve(res)
|
||||
@@ -622,7 +622,7 @@ Page({
|
||||
const userId = app.globalData.userInfo?.id
|
||||
|
||||
if (userId) {
|
||||
const checkRes = await app.request(`/api/user/purchase-status?userId=${userId}`)
|
||||
const checkRes = await app.request(`/api/miniprogram/user/purchase-status?userId=${userId}`)
|
||||
|
||||
if (checkRes.success && checkRes.data) {
|
||||
// 更新本地购买状态
|
||||
@@ -852,7 +852,7 @@ Page({
|
||||
}
|
||||
|
||||
// 调用专门的购买状态查询接口
|
||||
const res = await app.request(`/api/user/purchase-status?userId=${userId}`)
|
||||
const res = await app.request(`/api/miniprogram/user/purchase-status?userId=${userId}`)
|
||||
|
||||
if (res.success && res.data) {
|
||||
// 更新全局购买状态
|
||||
|
||||
@@ -95,7 +95,7 @@ Page({
|
||||
let realData = null
|
||||
try {
|
||||
// app.request 第一个参数是 URL 字符串(会自动拼接 baseUrl)
|
||||
const res = await app.request('/api/referral/data?userId=' + userInfo.id)
|
||||
const res = await app.request('/api/miniprogram/referral/data?userId=' + userInfo.id)
|
||||
console.log('[Referral] API返回:', JSON.stringify(res).substring(0, 200))
|
||||
|
||||
if (res && res.success && res.data) {
|
||||
@@ -682,7 +682,7 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
const res = await app.request('/api/withdraw', {
|
||||
const res = await app.request('/api/miniprogram/withdraw', {
|
||||
method: 'POST',
|
||||
data: { userId, amount }
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ Page({
|
||||
// 加载热门章节(从服务器获取点击量高的章节)
|
||||
async loadHotChapters() {
|
||||
try {
|
||||
const res = await app.request('/api/book/hot')
|
||||
const res = await app.request('/api/miniprogram/book/hot')
|
||||
if (res && res.success && res.chapters?.length > 0) {
|
||||
this.setData({ hotChapters: res.chapters })
|
||||
}
|
||||
@@ -77,7 +77,7 @@ Page({
|
||||
this.setData({ loading: true, searched: true })
|
||||
|
||||
try {
|
||||
const res = await app.request(`/api/book/search?q=${encodeURIComponent(keyword.trim())}`)
|
||||
const res = await app.request(`/api/miniprogram/book/search?q=${encodeURIComponent(keyword.trim())}`)
|
||||
|
||||
if (res && res.success) {
|
||||
this.setData({
|
||||
|
||||
@@ -114,7 +114,7 @@ Page({
|
||||
const userId = app.globalData.userInfo?.id
|
||||
if (!userId) return
|
||||
|
||||
await app.request('/api/user/update', {
|
||||
await app.request('/api/miniprogram/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId, address }
|
||||
})
|
||||
@@ -147,7 +147,7 @@ Page({
|
||||
|
||||
// 同步到服务器
|
||||
try {
|
||||
await app.request('/api/user/update', {
|
||||
await app.request('/api/miniprogram/user/update', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
userId: app.globalData.userInfo?.id,
|
||||
@@ -201,7 +201,7 @@ Page({
|
||||
|
||||
// 同步到服务器
|
||||
try {
|
||||
await app.request('/api/user/update', {
|
||||
await app.request('/api/miniprogram/user/update', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
userId: app.globalData.userInfo?.id,
|
||||
@@ -273,7 +273,7 @@ Page({
|
||||
const userId = app.globalData.userInfo?.id
|
||||
if (!userId) return
|
||||
|
||||
const res = await app.request('/api/user/profile', {
|
||||
const res = await app.request('/api/miniprogram/user/profile', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
userId,
|
||||
@@ -313,7 +313,7 @@ Page({
|
||||
|
||||
const uploadRes = await new Promise((resolve, reject) => {
|
||||
wx.uploadFile({
|
||||
url: app.globalData.baseUrl + '/api/upload',
|
||||
url: app.globalData.baseUrl + '/api/miniprogram/upload',
|
||||
filePath: tempAvatarUrl,
|
||||
name: 'file',
|
||||
formData: {
|
||||
@@ -353,7 +353,7 @@ Page({
|
||||
// 4. 同步到服务器数据库
|
||||
const userId = app.globalData.userInfo?.id
|
||||
if (userId) {
|
||||
await app.request('/api/user/profile', {
|
||||
await app.request('/api/miniprogram/user/profile', {
|
||||
method: 'POST',
|
||||
data: { userId, nickname: nickName, avatar: avatarUrl }
|
||||
})
|
||||
|
||||
@@ -27,7 +27,7 @@ Page({
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const res = await app.request('/api/withdraw/records?userId=' + userInfo.id)
|
||||
const res = await app.request('/api/miniprogram/withdraw/records?userId=' + userInfo.id)
|
||||
if (res && res.success && res.data && Array.isArray(res.data.list)) {
|
||||
const list = (res.data.list || []).map(item => ({
|
||||
id: item.id,
|
||||
|
||||
@@ -22,7 +22,7 @@ class ChapterAccessManager {
|
||||
*/
|
||||
async fetchLatestConfig() {
|
||||
try {
|
||||
const res = await app.request('/api/db/config', { timeout: 3000 })
|
||||
const res = await app.request('/api/miniprogram/config', { timeout: 3000 })
|
||||
if (res.success && res.freeChapters) {
|
||||
return {
|
||||
freeChapters: res.freeChapters,
|
||||
@@ -70,7 +70,7 @@ class ChapterAccessManager {
|
||||
|
||||
// 3. 请求服务端校验是否已购买(带重试)
|
||||
const res = await this.requestWithRetry(
|
||||
`/api/user/check-purchased?userId=${encodeURIComponent(userId)}&type=section&productId=${encodeURIComponent(sectionId)}`,
|
||||
`/api/miniprogram/user/check-purchased?userId=${encodeURIComponent(userId)}&type=section&productId=${encodeURIComponent(sectionId)}`,
|
||||
{ timeout: 5000 },
|
||||
2 // 最多重试2次
|
||||
)
|
||||
@@ -145,7 +145,7 @@ class ChapterAccessManager {
|
||||
if (!userId) return
|
||||
|
||||
try {
|
||||
const res = await app.request(`/api/user/purchase-status?userId=${encodeURIComponent(userId)}`)
|
||||
const res = await app.request(`/api/miniprogram/user/purchase-status?userId=${encodeURIComponent(userId)}`)
|
||||
|
||||
if (res.success && res.data) {
|
||||
app.globalData.hasFullBook = res.data.hasFullBook || false
|
||||
|
||||
@@ -174,7 +174,7 @@ class ReadingTracker {
|
||||
this.activeTracker.lastScrollTime = now
|
||||
|
||||
try {
|
||||
await app.request('/api/user/reading-progress', {
|
||||
await app.request('/api/miniprogram/user/reading-progress', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
userId,
|
||||
|
||||
Reference in New Issue
Block a user