feat(passport): 迁移并修复小程序支付页面访问 websopy API 问题

- 迁移 src/passport/pay 相关代码至当前项目,无需替换文件
- 新增环境变量 WEBSOPY_API_BASE_URL,提供 websopy API 基础地址
- 在 config/app.ts 导出 WebsopyBaseUrl,供代码引用
- 配置 env.d.ts 类型定义,消除 TypeScript 隐式 any 错误
- request 请求方法支持自定义 baseUrl 以调用不同接口地址
- passport/pay 页面调用订阅接口统一传入 WebsopyBaseUrl
- 修正 tenantId 类型为 number,调整登录用户类型断言
- 确认编译成功,dist 目录生成对应文件及正确请求地址
- 说明 type-check 依赖库问题不影响正常构建和运行
This commit is contained in:
2026-07-16 01:34:27 +08:00
parent 9df90c1176
commit 85a1558e84
8 changed files with 92 additions and 34 deletions

32
.idea/workspace.xml generated
View File

@@ -4,7 +4,13 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="2de94e4f-0587-4c9b-8bfd-e87e0ae95b81" name="更改" comment="feat(pay-bak): 新增小程序支付页面及相关配置&#10;&#10;- 新增确认支付页面配置,设置导航栏标题和样式&#10;- 实现小程序支付页完整组件逻辑包括加载订单、发起JSAPI支付等&#10;- 支持通过 scene 或 subscriptionNo 获取订单参数&#10;- 完善支付流程接口请求及错误处理,支持自动登录和支付确认&#10;- 增加支付成功、支付中、支付失败、取消等状态页面展示&#10;- 支持支付成功后跳转已购产品页或用户页&#10;- 提供取消支付返回逻辑和界面展示&#10;- 细化支付金额显示和提示用户支付后可使用应用功能" /> <list default="true" id="2de94e4f-0587-4c9b-8bfd-e87e0ae95b81" name="更改" comment="feat(address): 新增收货地址与售后申请功能&#10;&#10;- 新增地址编辑页面,支持地址智能识别、地图选点、地区选择和默认地址设置&#10;- 实现地址列表页面,支持地址查看、删除、设为默认及选择返回结算页&#10;- 新增售后申请页面,支持退款类型选择、商品选择、原因填写、图片上传和提交审核&#10;- 修复 passport 分包配置,移除不存在分包并补充缺失声明,避免 Taro 编译报错&#10;- 新增地址类型定义,增强前端地址数据结构类型安全&#10;- 优化页面交互体验,完善表单校验及错误提示逻辑&#10;- 统一代码格式与命名规范,保持代码风格一致性">
<change beforePath="$PROJECT_DIR$/.workbuddy/memory/2026-07-16.md" beforeDir="false" afterPath="$PROJECT_DIR$/.workbuddy/memory/2026-07-16.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/app.ts" beforeDir="false" afterPath="$PROJECT_DIR$/config/app.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/env.js" beforeDir="false" afterPath="$PROJECT_DIR$/config/env.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/passport/pay/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/passport/pay/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils/request.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/request.ts" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -111,15 +117,7 @@
<workItem from="1782971387128" duration="7154000" /> <workItem from="1782971387128" duration="7154000" />
<workItem from="1784093204572" duration="6082000" /> <workItem from="1784093204572" duration="6082000" />
<workItem from="1784131049625" duration="2304000" /> <workItem from="1784131049625" duration="2304000" />
<workItem from="1784133736973" duration="2124000" /> <workItem from="1784133736973" duration="2917000" />
</task>
<task id="LOCAL-00005" summary="fix(passport): 修正邀请接受接口的URL路径&#10;&#10;- 将邀请接受接口URL从/api/_app/invite/accept修改为/api/_app/developer/invite/accept&#10;- 确保请求正确指向开发者邀请接受接口&#10;- 修复因URL错误导致的邀请接受失败问题">
<option name="closed" value="true" />
<created>1775896148590</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1775896148590</updated>
</task> </task>
<task id="LOCAL-00006" summary="fix(passport): 修正邀请接受接口的URL路径&#10;&#10;- 将邀请接受接口URL从/api/_app/invite/accept修改为/api/_app/developer/invite/accept&#10;- 确保请求正确指向开发者邀请接受接口&#10;- 修复因URL错误导致的邀请接受失败问题"> <task id="LOCAL-00006" summary="fix(passport): 修正邀请接受接口的URL路径&#10;&#10;- 将邀请接受接口URL从/api/_app/invite/accept修改为/api/_app/developer/invite/accept&#10;- 确保请求正确指向开发者邀请接受接口&#10;- 修复因URL错误导致的邀请接受失败问题">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -505,7 +503,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1784131564427</updated> <updated>1784131564427</updated>
</task> </task>
<option name="localTasksCounter" value="54" /> <task id="LOCAL-00054" summary="feat(address): 新增收货地址与售后申请功能&#10;&#10;- 新增地址编辑页面,支持地址智能识别、地图选点、地区选择和默认地址设置&#10;- 实现地址列表页面,支持地址查看、删除、设为默认及选择返回结算页&#10;- 新增售后申请页面,支持退款类型选择、商品选择、原因填写、图片上传和提交审核&#10;- 修复 passport 分包配置,移除不存在分包并补充缺失声明,避免 Taro 编译报错&#10;- 新增地址类型定义,增强前端地址数据结构类型安全&#10;- 优化页面交互体验,完善表单校验及错误提示逻辑&#10;- 统一代码格式与命名规范,保持代码风格一致性">
<option name="closed" value="true" />
<created>1784135922873</created>
<option name="number" value="00054" />
<option name="presentableId" value="LOCAL-00054" />
<option name="project" value="LOCAL" />
<updated>1784135922873</updated>
</task>
<option name="localTasksCounter" value="55" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -525,7 +531,6 @@
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" /> <option name="CHECK_NEW_TODO" value="false" />
<MESSAGE value="refactor(api): 移除未使用的配置接口及相关Hook&#10;&#10;- 从cmsWebsiteField接口中删除configWebsiteField方法&#10;- 删除useConfig自定义Hook及其引用&#10;- 更新about页面去除对config对象和useConfig的使用&#10;- 修正invite模块请求URL统一加上/api前缀" />
<MESSAGE value="fix(invite): 修正邀请接口路径以支持小程序专用前缀&#10;&#10;- 将请求邀请信息接口路径改为使用 /api/_app 前缀,确保小程序免登录访问&#10;- 修改接受邀请接口路径,统一使用小程序专用 API 域名和前缀&#10;- 更新邀请相关接口注释,明确小程序专用接口前缀含义&#10;- 在专家历史数据中添加高级开发工程师 Will 的条目并更新时间戳" /> <MESSAGE value="fix(invite): 修正邀请接口路径以支持小程序专用前缀&#10;&#10;- 将请求邀请信息接口路径改为使用 /api/_app 前缀,确保小程序免登录访问&#10;- 修改接受邀请接口路径,统一使用小程序专用 API 域名和前缀&#10;- 更新邀请相关接口注释,明确小程序专用接口前缀含义&#10;- 在专家历史数据中添加高级开发工程师 Will 的条目并更新时间戳" />
<MESSAGE value="fix(passport): 添加邀请接受接口调试日志&#10;&#10;- 在接受邀请请求前打印token和请求URL、参数&#10;- 在请求响应后输出接口响应及返回数据&#10;- 在调用失败时打印错误信息及异常日志&#10;- 保持请求流程和状态管理不变,增强调试能力" /> <MESSAGE value="fix(passport): 添加邀请接受接口调试日志&#10;&#10;- 在接受邀请请求前打印token和请求URL、参数&#10;- 在请求响应后输出接口响应及返回数据&#10;- 在调用失败时打印错误信息及异常日志&#10;- 保持请求流程和状态管理不变,增强调试能力" />
<MESSAGE value="fix(passport): 优化邀请码接受失败的用户提示和处理&#10;&#10;- 针对“用户不存在”、“用户创建失败”及“请先登录”提示,改为弹窗提示需登录&#10;- 在弹窗中增加“去登录”按钮点击后跳转到登录页面并携带重定向token参数&#10;- 其他错误仍使用原Toast提示方式展示错误信息&#10;- 保留错误日志打印,便于排查异常情况" /> <MESSAGE value="fix(passport): 优化邀请码接受失败的用户提示和处理&#10;&#10;- 针对“用户不存在”、“用户创建失败”及“请先登录”提示,改为弹窗提示需登录&#10;- 在弹窗中增加“去登录”按钮点击后跳转到登录页面并携带重定向token参数&#10;- 其他错误仍使用原Toast提示方式展示错误信息&#10;- 保留错误日志打印,便于排查异常情况" />
@@ -550,7 +555,8 @@
<MESSAGE value="feat(pay): 优化小程序支付流程并增强日志调试&#10;&#10;- 更新 wx-login 接口以返回完整 LoginResult包括 access_token 和 user 对象&#10;- 支付页面新增大量日志,详尽打印参数、请求和响应信息&#10;- 优化获取订阅详情流程,支持 returnRaw 返回完整响应用于调试&#10;- 支付流程新增步骤,先通过 code 获取 openid 并缓存,再尝试用 openid 自动登录&#10;- 增加自动登录失败交互,提示未注册用户先登录&#10;- 支付相关请求均使用 returnRaw 方便错误排查&#10;- request 请求模块添加统一请求和响应日志,增强调试能力&#10;- request 认证错误和业务错误时加入详细日志输出" /> <MESSAGE value="feat(pay): 优化小程序支付流程并增强日志调试&#10;&#10;- 更新 wx-login 接口以返回完整 LoginResult包括 access_token 和 user 对象&#10;- 支付页面新增大量日志,详尽打印参数、请求和响应信息&#10;- 优化获取订阅详情流程,支持 returnRaw 返回完整响应用于调试&#10;- 支付流程新增步骤,先通过 code 获取 openid 并缓存,再尝试用 openid 自动登录&#10;- 增加自动登录失败交互,提示未注册用户先登录&#10;- 支付相关请求均使用 returnRaw 方便错误排查&#10;- request 请求模块添加统一请求和响应日志,增强调试能力&#10;- request 认证错误和业务错误时加入详细日志输出" />
<MESSAGE value="feat(pay): 支付成功后自动跳转到已购产品页面&#10;&#10;- 支付成功后显示成功提示&#10;- 延迟1.5秒自动跳转到已购产品页面&#10;- 处理跳转失败时回退到用户首页&#10;- 优化用户支付完成后的使用体验" /> <MESSAGE value="feat(pay): 支付成功后自动跳转到已购产品页面&#10;&#10;- 支付成功后显示成功提示&#10;- 延迟1.5秒自动跳转到已购产品页面&#10;- 处理跳转失败时回退到用户首页&#10;- 优化用户支付完成后的使用体验" />
<MESSAGE value="feat(pay-bak): 新增小程序支付页面及相关配置&#10;&#10;- 新增确认支付页面配置,设置导航栏标题和样式&#10;- 实现小程序支付页完整组件逻辑包括加载订单、发起JSAPI支付等&#10;- 支持通过 scene 或 subscriptionNo 获取订单参数&#10;- 完善支付流程接口请求及错误处理,支持自动登录和支付确认&#10;- 增加支付成功、支付中、支付失败、取消等状态页面展示&#10;- 支持支付成功后跳转已购产品页或用户页&#10;- 提供取消支付返回逻辑和界面展示&#10;- 细化支付金额显示和提示用户支付后可使用应用功能" /> <MESSAGE value="feat(pay-bak): 新增小程序支付页面及相关配置&#10;&#10;- 新增确认支付页面配置,设置导航栏标题和样式&#10;- 实现小程序支付页完整组件逻辑包括加载订单、发起JSAPI支付等&#10;- 支持通过 scene 或 subscriptionNo 获取订单参数&#10;- 完善支付流程接口请求及错误处理,支持自动登录和支付确认&#10;- 增加支付成功、支付中、支付失败、取消等状态页面展示&#10;- 支持支付成功后跳转已购产品页或用户页&#10;- 提供取消支付返回逻辑和界面展示&#10;- 细化支付金额显示和提示用户支付后可使用应用功能" />
<option name="LAST_COMMIT_MESSAGE" value="feat(pay-bak): 新增小程序支付页面及相关配置&#10;&#10;- 新增确认支付页面配置,设置导航栏标题和样式&#10;- 实现小程序支付页完整组件逻辑包括加载订单、发起JSAPI支付等&#10;- 支持通过 scene 或 subscriptionNo 获取订单参数&#10;- 完善支付流程接口请求及错误处理,支持自动登录和支付确认&#10;- 增加支付成功、支付中、支付失败、取消等状态页面展示&#10;- 支持支付成功后跳转已购产品页或用户页&#10;- 提供取消支付返回逻辑和界面展示&#10;- 细化支付金额显示和提示用户支付后可使用应用功能" /> <MESSAGE value="feat(address): 新增收货地址与售后申请功能&#10;&#10;- 新增地址编辑页面,支持地址智能识别、地图选点、地区选择和默认地址设置&#10;- 实现地址列表页面,支持地址查看、删除、设为默认及选择返回结算页&#10;- 新增售后申请页面,支持退款类型选择、商品选择、原因填写、图片上传和提交审核&#10;- 修复 passport 分包配置,移除不存在分包并补充缺失声明,避免 Taro 编译报错&#10;- 新增地址类型定义,增强前端地址数据结构类型安全&#10;- 优化页面交互体验,完善表单校验及错误提示逻辑&#10;- 统一代码格式与命名规范,保持代码风格一致性" />
<option name="LAST_COMMIT_MESSAGE" value="feat(address): 新增收货地址与售后申请功能&#10;&#10;- 新增地址编辑页面,支持地址智能识别、地图选点、地区选择和默认地址设置&#10;- 实现地址列表页面,支持地址查看、删除、设为默认及选择返回结算页&#10;- 新增售后申请页面,支持退款类型选择、商品选择、原因填写、图片上传和提交审核&#10;- 修复 passport 分包配置,移除不存在分包并补充缺失声明,避免 Taro 编译报错&#10;- 新增地址类型定义,增强前端地址数据结构类型安全&#10;- 优化页面交互体验,完善表单校验及错误提示逻辑&#10;- 统一代码格式与命名规范,保持代码风格一致性" />
<option name="NON_MODAL_COMMIT_POSTPONE_SLOW_CHECKS" value="false" /> <option name="NON_MODAL_COMMIT_POSTPONE_SLOW_CHECKS" value="false" />
</component> </component>
</project> </project>

View File

@@ -13,4 +13,17 @@
- 补充 `register``src/passport/register.tsx` 存在但未声明) - 补充 `register``src/passport/register.tsx` 存在但未声明)
- 统一引号风格、清理尾随逗号 - 统一引号风格、清理尾随逗号
待确认phone-auth / invite / webview 三个页面是否需要新建(目前无文件、无引用)。 ## passport/pay 功能从 websopy-taro-bak 迁移
问题:`src/passport/pay/index.tsx` 失效,原因是当前项目基于 xinlong-shop 框架,`API_BASE_URL` 指向商城接口 `https://shop-api.websoft.top/api`,而 pay 页面需要访问 websopy 业务接口 `https://websopy-api.websoft.top/api``/app/subscription/*`
迁移与修复:
- 确认 `src/passport/pay/``src/api/passport/wx-login/` 文件和备份项目一致,无需替换。
-`config/env.js` 新增 `WEBSOPY_API_BASE_URL`
-`config/app.ts` 导出 `WebsopyBaseUrl`
- 创建 `config/env.d.ts` 消除 `config/app.ts` 导入 `.js` 的隐式 any 类型错误。
- 增强 `src/utils/request.ts`:在 `RequestConfig` 增加 `baseUrl?: string``request`/`get`/`post` 等函数支持自定义 baseUrl相对路径会自动拼接完整 URL 保持不变。
- 修改 `src/passport/pay/index.tsx`:三个订阅接口请求均传入 `baseUrl: WebsopyBaseUrl`;修复 `tenantId` 类型string -> number`saveStorageByLoginUser` 的 user 类型断言。
- 运行 `npx taro build --type weapp` 构建成功dist 中 `passport/pay` 文件生成,确认请求使用 websopy API。
- 说明:`npm run type-check` 仍因 `@tarojs/taro` 类型包解析问题失败,这是项目既有环境问题,不影响构建。

View File

@@ -1,7 +1,8 @@
import { API_BASE_URL, SERVER_API_URL } from './env' import { API_BASE_URL, SERVER_API_URL, WEBSOPY_API_BASE_URL } from './env'
export const TenantId = '5' export const TenantId = '5'
export const TenantName = '威硕开发助手' export const TenantName = '威硕开发助手'
export const BaseUrl = API_BASE_URL export const BaseUrl = API_BASE_URL
export const ServerBaseUrl = SERVER_API_URL export const ServerBaseUrl = SERVER_API_URL
export const WebsopyBaseUrl = WEBSOPY_API_BASE_URL
export const Version = 'v3.0.0' export const Version = 'v3.0.0'

30
config/env.d.ts vendored Normal file
View File

@@ -0,0 +1,30 @@
export const CURRENT_ENV: string
export const ENV_CONFIG: {
development: {
API_BASE_URL: string
SERVER_API_URL: string
WEBSOPY_API_BASE_URL: string
APP_NAME: string
DEBUG: string
}
test: {
API_BASE_URL: string
SERVER_API_URL: string
WEBSOPY_API_BASE_URL: string
APP_NAME: string
DEBUG: string
}
production: {
API_BASE_URL: string
SERVER_API_URL: string
WEBSOPY_API_BASE_URL: string
APP_NAME: string
DEBUG: string
}
}
export function getEnvConfig(): (typeof ENV_CONFIG)[keyof typeof ENV_CONFIG]
export const API_BASE_URL: string
export const SERVER_API_URL: string
export const WEBSOPY_API_BASE_URL: string
export const APP_NAME: string
export const DEBUG: string

View File

@@ -4,18 +4,21 @@ export const ENV_CONFIG = {
development: { development: {
API_BASE_URL: 'https://shop-api.websoft.top/api', API_BASE_URL: 'https://shop-api.websoft.top/api',
SERVER_API_URL: 'https://server.websoft.top/api', SERVER_API_URL: 'https://server.websoft.top/api',
WEBSOPY_API_BASE_URL: 'https://websopy-api.websoft.top/api',
APP_NAME: '威硕谱软件', APP_NAME: '威硕谱软件',
DEBUG: 'true', DEBUG: 'true',
}, },
test: { test: {
API_BASE_URL: 'https://shop-api.websoft.top/api', API_BASE_URL: 'https://shop-api.websoft.top/api',
SERVER_API_URL: 'https://server.websoft.top/api', SERVER_API_URL: 'https://server.websoft.top/api',
WEBSOPY_API_BASE_URL: 'https://websopy-api.websoft.top/api',
APP_NAME: '威硕谱软件', APP_NAME: '威硕谱软件',
DEBUG: 'true', DEBUG: 'true',
}, },
production: { production: {
API_BASE_URL: 'https://shop-api.websoft.top/api', API_BASE_URL: 'https://shop-api.websoft.top/api',
SERVER_API_URL: 'https://server.websoft.top/api', SERVER_API_URL: 'https://server.websoft.top/api',
WEBSOPY_API_BASE_URL: 'https://websopy-api.websoft.top/api',
APP_NAME: '威硕谱软件', APP_NAME: '威硕谱软件',
DEBUG: 'false', DEBUG: 'false',
}, },
@@ -25,4 +28,4 @@ export function getEnvConfig() {
return ENV_CONFIG[CURRENT_ENV] || ENV_CONFIG.development return ENV_CONFIG[CURRENT_ENV] || ENV_CONFIG.development
} }
export const { API_BASE_URL, SERVER_API_URL, APP_NAME, DEBUG } = getEnvConfig() export const { API_BASE_URL, SERVER_API_URL, WEBSOPY_API_BASE_URL, APP_NAME, DEBUG } = getEnvConfig()

View File

@@ -5,8 +5,9 @@ import { Check, Close, Tips, Clock } from '@nutui/icons-react-taro'
import Taro from '@tarojs/taro' import Taro from '@tarojs/taro'
import { request } from '@/utils/request' import { request } from '@/utils/request'
import { getOpenId, loginByOpenId } from '@/api/passport/wx-login' import { getOpenId, loginByOpenId } from '@/api/passport/wx-login'
import type { User } from '@/api/system/user/model'
import { saveStorageByLoginUser } from '@/utils/server' import { saveStorageByLoginUser } from '@/utils/server'
import { TenantId } from '@/config/app' import { TenantId, WebsopyBaseUrl } from '@/config/app'
/** /**
* 小程序支付页面 * 小程序支付页面
@@ -87,7 +88,8 @@ const PayPage: React.FC = () => {
const data: any = await request({ const data: any = await request({
url: `/app/subscription/detail-by-no/${subscriptionNo}`, url: `/app/subscription/detail-by-no/${subscriptionNo}`,
method: 'GET', method: 'GET',
returnRaw: true // 先用 returnRaw=true 拿到完整响应,方便调试 returnRaw: true,
baseUrl: WebsopyBaseUrl
}) })
console.log('[PayPage] 接口完整返回returnRaw=true:', JSON.stringify(data)) console.log('[PayPage] 接口完整返回returnRaw=true:', JSON.stringify(data))
@@ -175,13 +177,13 @@ const PayPage: React.FC = () => {
try { try {
const loginResult = await loginByOpenId({ const loginResult = await loginByOpenId({
code: loginRes.code, code: loginRes.code,
tenantId: TenantId tenantId: Number(TenantId)
}) })
console.log('[PayPage] loginByOpenId 结果:', loginResult) console.log('[PayPage] loginByOpenId 结果:', loginResult)
if (loginResult.success && loginResult.data) { if (loginResult.success && loginResult.data) {
// 登录成功,保存 token // 登录成功,保存 token
saveStorageByLoginUser(loginResult.data.access_token || '', loginResult.data.user) saveStorageByLoginUser(loginResult.data.access_token || '', loginResult.data.user as unknown as User)
console.log('[PayPage] 自动登录成功,已保存 token') console.log('[PayPage] 自动登录成功,已保存 token')
} else { } else {
console.warn('[PayPage] 自动登录失败:', loginResult.message) console.warn('[PayPage] 自动登录失败:', loginResult.message)
@@ -211,7 +213,8 @@ const PayPage: React.FC = () => {
url: `/app/subscription/mp-prepay/${detail.id}`, url: `/app/subscription/mp-prepay/${detail.id}`,
method: 'POST', method: 'POST',
data: { openid }, data: { openid },
returnRaw: true returnRaw: true,
baseUrl: WebsopyBaseUrl
}) })
console.log('[PayPage] mp-prepay 完整返回:', JSON.stringify(prepayRes)) console.log('[PayPage] mp-prepay 完整返回:', JSON.stringify(prepayRes))
@@ -240,7 +243,8 @@ const PayPage: React.FC = () => {
await request({ await request({
url: `/app/subscription/mp-confirm/${detail.subscriptionNo}`, url: `/app/subscription/mp-confirm/${detail.subscriptionNo}`,
method: 'POST', method: 'POST',
data: {} data: {},
baseUrl: WebsopyBaseUrl
}) })
} catch (confirmErr) { } catch (confirmErr) {
console.warn('支付确认通知失败,等待轮询:', confirmErr) console.warn('支付确认通知失败,等待轮询:', confirmErr)

View File

@@ -12,6 +12,7 @@ export interface RequestConfig {
showLoading?: boolean showLoading?: boolean
showError?: boolean showError?: boolean
returnRaw?: boolean returnRaw?: boolean
baseUrl?: string
} }
interface ApiResponse<T = any> { interface ApiResponse<T = any> {
@@ -206,7 +207,7 @@ const retryRequest = async <T>(config: RequestConfig, retryCount = 0): Promise<T
export async function request<T>(options: RequestConfig): Promise<T> { export async function request<T>(options: RequestConfig): Promise<T> {
try { try {
const config = requestInterceptor({ ...DEFAULT_CONFIG, ...options }) const config = requestInterceptor({ ...DEFAULT_CONFIG, ...options, url: buildUrl(options.url, options.baseUrl) })
return await retryRequest<T>(config) return await retryRequest<T>(config)
} catch (error) { } catch (error) {
const requestError = error as RequestError const requestError = error as RequestError
@@ -215,11 +216,11 @@ export async function request<T>(options: RequestConfig): Promise<T> {
} }
} }
const buildUrl = (url: string): string => { const buildUrl = (url: string, customBaseUrl?: string): string => {
if (url.startsWith('http://') || url.startsWith('https://')) { if (url.startsWith('http://') || url.startsWith('https://')) {
return url return url
} }
return `${baseUrl}${url}` return `${customBaseUrl || baseUrl}${url}`
} }
const buildQueryString = (params: Record<string, any>): string => { const buildQueryString = (params: Record<string, any>): string => {
@@ -231,41 +232,41 @@ const buildQueryString = (params: Record<string, any>): string => {
} }
export function get<T>(url: string, params?: any, config?: Partial<RequestConfig>): Promise<T> { export function get<T>(url: string, params?: any, config?: Partial<RequestConfig>): Promise<T> {
const fullUrl = buildUrl(url) + (params ? buildQueryString(params) : '') const fullUrl = buildUrl(url, config?.baseUrl) + (params ? buildQueryString(params) : '')
return request<T>({ url: fullUrl, method: 'GET', returnRaw: true, ...config }) return request<T>({ url: fullUrl, method: 'GET', returnRaw: true, ...config })
} }
export function post<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> { export function post<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> {
return request<T>({ url: buildUrl(url), method: 'POST', data, returnRaw: true, ...config }) return request<T>({ url: buildUrl(url, config?.baseUrl), method: 'POST', data, returnRaw: true, ...config })
} }
export function put<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> { export function put<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> {
return request<T>({ url: buildUrl(url), method: 'PUT', data, returnRaw: true, ...config }) return request<T>({ url: buildUrl(url, config?.baseUrl), method: 'PUT', data, returnRaw: true, ...config })
} }
export function patch<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> { export function patch<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> {
return request<T>({ url: buildUrl(url), method: 'PATCH', data, returnRaw: true, ...config }) return request<T>({ url: buildUrl(url, config?.baseUrl), method: 'PATCH', data, returnRaw: true, ...config })
} }
export function del<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> { export function del<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> {
return request<T>({ url: buildUrl(url), method: 'DELETE', data, returnRaw: true, ...config }) return request<T>({ url: buildUrl(url, config?.baseUrl), method: 'DELETE', data, returnRaw: true, ...config })
} }
export function getData<T>(url: string, params?: any, config?: Partial<RequestConfig>): Promise<T> { export function getData<T>(url: string, params?: any, config?: Partial<RequestConfig>): Promise<T> {
const fullUrl = buildUrl(url) + (params ? buildQueryString(params) : '') const fullUrl = buildUrl(url, config?.baseUrl) + (params ? buildQueryString(params) : '')
return request<T>({ url: fullUrl, method: 'GET', returnRaw: false, ...config }) return request<T>({ url: fullUrl, method: 'GET', returnRaw: false, ...config })
} }
export function postData<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> { export function postData<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> {
return request<T>({ url: buildUrl(url), method: 'POST', data, returnRaw: false, ...config }) return request<T>({ url: buildUrl(url, config?.baseUrl), method: 'POST', data, returnRaw: false, ...config })
} }
export function putData<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> { export function putData<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> {
return request<T>({ url: buildUrl(url), method: 'PUT', data, returnRaw: false, ...config }) return request<T>({ url: buildUrl(url, config?.baseUrl), method: 'PUT', data, returnRaw: false, ...config })
} }
export function delData<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> { export function delData<T>(url: string, data?: any, config?: Partial<RequestConfig>): Promise<T> {
return request<T>({ url: buildUrl(url), method: 'DELETE', data, returnRaw: false, ...config }) return request<T>({ url: buildUrl(url, config?.baseUrl), method: 'DELETE', data, returnRaw: false, ...config })
} }
export default { export default {

BIN
taro-feature-migration.zip Normal file

Binary file not shown.