@cogito.ai/cli 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/templates/web-nextjs/apps/docs/.source/browser.ts +8 -18
  3. package/dist/templates/web-nextjs/apps/docs/.source/dynamic.ts +5 -11
  4. package/dist/templates/web-nextjs/apps/docs/.source/server.ts +26 -37
  5. package/dist/templates/web-nextjs/apps/docs/content/docs/meta.json +1 -1
  6. package/dist/templates/web-nextjs/apps/docs/content/docs/template/alipay.mdx +276 -0
  7. package/dist/templates/web-nextjs/apps/docs/content/docs/template/deployment.mdx +32 -0
  8. package/dist/templates/web-nextjs/apps/docs/content/docs/template/drizzle.mdx +18 -0
  9. package/dist/templates/web-nextjs/apps/docs/content/docs/template/getting-started.mdx +98 -0
  10. package/dist/templates/web-nextjs/apps/docs/content/docs/template/meta.json +13 -0
  11. package/dist/templates/web-nextjs/apps/docs/content/docs/template/stripe.mdx +18 -0
  12. package/dist/templates/web-nextjs/apps/docs/content/docs/template/supabase.mdx +130 -0
  13. package/dist/templates/web-nextjs/apps/docs/content/docs/template/troubleshooting.mdx +87 -0
  14. package/dist/templates/web-nextjs/apps/docs/content/docs/template/wechat-pay.mdx +318 -0
  15. package/dist/templates/web-nextjs/apps/web/.env.example +35 -0
  16. package/dist/templates/web-nextjs/apps/web/messages/en.json +70 -0
  17. package/dist/templates/web-nextjs/apps/web/messages/zh.json +71 -1
  18. package/dist/templates/web-nextjs/apps/web/next-env.d.ts +1 -1
  19. package/dist/templates/web-nextjs/apps/web/package.json +4 -0
  20. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(auth)/forgot-password/page.tsx +4 -10
  21. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/payment/[paymentId]/page.tsx +88 -0
  22. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/payment/checkout/page.tsx +170 -0
  23. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/pricing/page.tsx +120 -0
  24. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/settings/layout.tsx +48 -1
  25. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/settings/subscription/page.tsx +128 -0
  26. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/create/route.ts +43 -0
  27. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/notify/route.ts +105 -0
  28. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/query/route.ts +54 -0
  29. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/return/route.ts +20 -0
  30. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/create/route.ts +52 -0
  31. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/wechat/create/route.ts +58 -0
  32. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/wechat/notify/route.ts +92 -0
  33. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/wechat/query/route.ts +54 -0
  34. package/dist/templates/web-nextjs/apps/web/src/app/docs/page.tsx +5 -0
  35. package/dist/templates/web-nextjs/apps/web/src/features/subscription/alipay/client.ts +36 -0
  36. package/dist/templates/web-nextjs/apps/web/src/features/subscription/alipay/server.ts +83 -0
  37. package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/index.ts +4 -0
  38. package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/pro-badge.tsx +9 -0
  39. package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/pro-feature-comparison.tsx +70 -0
  40. package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/quota-warning-banner.tsx +37 -0
  41. package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/upgrade-button.tsx +42 -0
  42. package/dist/templates/web-nextjs/apps/web/src/features/subscription/hooks.ts +141 -0
  43. package/dist/templates/web-nextjs/apps/web/src/features/subscription/payment-helpers.ts +27 -0
  44. package/dist/templates/web-nextjs/apps/web/src/features/subscription/payment-service.ts +56 -0
  45. package/dist/templates/web-nextjs/apps/web/src/features/subscription/service.ts +55 -0
  46. package/dist/templates/web-nextjs/apps/web/src/features/subscription/types.ts +73 -0
  47. package/dist/templates/web-nextjs/apps/web/src/features/subscription/wechat/client.ts +33 -0
  48. package/dist/templates/web-nextjs/apps/web/src/features/subscription/wechat/server.ts +147 -0
  49. package/dist/templates/web-nextjs/apps/web/src/lib/supabase/admin.ts +23 -0
  50. package/dist/templates/web-nextjs/apps/web/src/lib/wechat-pay/client.ts +66 -0
  51. package/dist/templates/web-nextjs/apps/web/src/lib/wechat-pay/crypto.ts +99 -0
  52. package/dist/templates/web-nextjs/apps/web/src/lib/wechat-pay/types.ts +10 -0
  53. package/dist/templates/web-nextjs/pnpm-lock.yaml +319 -0
  54. package/dist/templates/web-nextjs/pnpm-workspace.yaml +7 -8
  55. package/dist/templates/web-nextjs/supabase/migrations/20250608_add_subscription_tables.sql +125 -0
  56. package/package.json +1 -1
@@ -0,0 +1,130 @@
1
+ ---
2
+ title: 数据层:Supabase
3
+ description: 如何在开发环境和生产环境中使用 Supabase,包括数据表设计、类型安全和最佳实践。
4
+ ---
5
+
6
+ ## 概述
7
+
8
+ 本项目使用 **Supabase** 作为后端数据库和身份验证服务。Supabase 提供了 PostgreSQL 数据库、自动生成的 REST API、实时订阅和身份验证功能。
9
+
10
+ ## 开发环境配置
11
+
12
+ ### 本地 Supabase CLI
13
+
14
+ 1. **安装 Supabase CLI**
15
+
16
+ ```bash
17
+ pnpm add -g supabase
18
+ ```
19
+
20
+ 2. **登录 Supabase**
21
+
22
+ ```bash
23
+ supabase login
24
+ ```
25
+
26
+ 3. **启动本地 Supabase 实例**
27
+
28
+ ```bash
29
+ supabase start
30
+ ```
31
+
32
+ 本地开发时,Supabase 服务运行在:
33
+ - **Studio UI**: http://localhost:54323
34
+ - **API URL**: http://localhost:54321
35
+ - **数据库**: postgresql://postgres:postgres@localhost:54322/postgres
36
+
37
+ ### 环境变量
38
+
39
+ 在 `.env.local` 中配置本地 Supabase:
40
+
41
+ ```
42
+ NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321
43
+ NEXT_PUBLIC_SUPABASE_ANON_KEY=your-local-anon-key
44
+ SUPABASE_SERVICE_ROLE_KEY=your-local-service-role-key
45
+ ```
46
+
47
+ > 运行 `supabase status` 获取本地密钥。
48
+
49
+ ## 生产环境配置
50
+
51
+ 1. 在 [Supabase Dashboard](https://supabase.com/dashboard) 创建新项目
52
+ 2. 获取项目 URL 和 API 密钥
53
+ 3. 更新生产环境变量
54
+
55
+ ## 数据表设计
56
+
57
+ 项目包含以下核心数据表(通过迁移脚本管理):
58
+
59
+ | 表名 | 说明 |
60
+ |------|------|
61
+ | `profiles` | 用户资料扩展 |
62
+ | `subscriptions` | 订阅信息 |
63
+ | `payments` | 支付记录 |
64
+
65
+ ### 运行迁移
66
+
67
+ ```bash
68
+ # 本地
69
+ supabase migration up
70
+
71
+ # 生产
72
+ supabase migration up --linked
73
+ ```
74
+
75
+ ## 类型安全
76
+
77
+ 项目使用 **Supabase 类型生成** 确保数据库查询的类型安全:
78
+
79
+ ```ts
80
+ import { createClient } from '@supabase/supabase-js'
81
+ import type { Database } from './supabase/types'
82
+
83
+ const supabase = createClient<Database>(url, key)
84
+ ```
85
+
86
+ 运行以下命令生成类型:
87
+
88
+ ```bash
89
+ supabase gen types typescript --project-id your-project-id --schema public > src/lib/supabase/types.ts
90
+ ```
91
+
92
+ ## 安全最佳实践
93
+
94
+ ### 行级安全策略 (RLS)
95
+
96
+ 所有表默认启用 RLS,确保用户只能访问自己的数据:
97
+
98
+ ```sql
99
+ CREATE POLICY "Users can only access their own data"
100
+ ON profiles FOR ALL
101
+ TO authenticated
102
+ USING (auth.uid() = user_id);
103
+ ```
104
+
105
+ ### 服务角色密钥
106
+
107
+ - **仅在服务器端**使用 `SUPABASE_SERVICE_ROLE_KEY`
108
+ - **绝不在客户端**暴露服务角色密钥
109
+ - 使用 `@supabase/ssr` 包管理会话
110
+
111
+ ## 开发调试
112
+
113
+ ### 查看数据库
114
+
115
+ 通过 Supabase Studio 访问本地数据库:
116
+
117
+ ```bash
118
+ supabase studio
119
+ ```
120
+
121
+ ### 日志和监控
122
+
123
+ - 本地:http://localhost:54323/project/default/logs/explorer
124
+ - 生产:Supabase Dashboard → Logs
125
+
126
+ ## 相关资源
127
+
128
+ - [Supabase 官方文档](https://supabase.com/docs)
129
+ - [Supabase JavaScript 客户端](https://supabase.com/docs/reference/javascript)
130
+ - [PostgreSQL 文档](https://www.postgresql.org/docs/)
@@ -0,0 +1,87 @@
1
+ ---
2
+ title: 故障排查
3
+ description: 常见问题及解决方案。
4
+ ---
5
+
6
+ ## 常见问题
7
+
8
+ ### pnpm install 失败
9
+
10
+ **问题**: 运行 `pnpm install` 时出现 `ERR_PNPM_IGNORED_BUILDS` 错误。
11
+
12
+ **解决方案**:
13
+ - 运行 `pnpm approve-builds` 批准构建脚本
14
+ - 或者检查 `pnpm-workspace.yaml` 中的 `onlyBuiltDependencies` 配置
15
+
16
+ ### 类型检查失败
17
+
18
+ **问题**: `pnpm check-types` 报错。
19
+
20
+ **解决方案**:
21
+ - 确保 `.env.local` 文件存在
22
+ - 运行 `pnpm build` 更新 `.source/` 文件
23
+
24
+ ### 文档站点 404
25
+
26
+ **问题**: 访问 `/docs` 返回 404。
27
+
28
+ **解决方案**:
29
+ - 确保 docs 应用已启动(`pnpm --filter @cogito.ai/docs dev`)
30
+ - 检查 `.source/` 文件是否已生成
31
+
32
+ ### 支付回调收不到
33
+
34
+ **问题**: 支付宝/微信支付回调通知收不到。
35
+
36
+ **解决方案**:
37
+ - 确保服务器公网可访问
38
+ - 检查回调地址配置是否正确
39
+ - 确认使用 HTTPS 协议
40
+ - 查看服务器防火墙设置
41
+
42
+ ### 数据库连接失败
43
+
44
+ **问题**: 无法连接 Supabase 数据库。
45
+
46
+ **解决方案**:
47
+ - 检查 `.env.local` 中的 Supabase URL 和密钥
48
+ - 确保本地 Supabase 实例已启动(`supabase start`)
49
+ - 验证网络连接
50
+
51
+ ## 调试技巧
52
+
53
+ ### 查看日志
54
+
55
+ ```bash
56
+ # Web 应用日志
57
+ pnpm --filter @cogito.ai/web dev
58
+
59
+ # 文档站点日志
60
+ pnpm --filter @cogito.ai/docs dev
61
+ ```
62
+
63
+ ### 清理缓存
64
+
65
+ ```bash
66
+ # 删除 node_modules 和 lockfile
67
+ rm -rf node_modules pnpm-lock.yaml
68
+
69
+ # 重新安装依赖
70
+ pnpm install
71
+ ```
72
+
73
+ ### 检查环境变量
74
+
75
+ ```bash
76
+ # 确认 .env.local 存在
77
+ cat .env.local
78
+
79
+ # 确认变量已加载
80
+ node -e "console.log(process.env.NEXT_PUBLIC_SUPABASE_URL)"
81
+ ```
82
+
83
+ ## 获取帮助
84
+
85
+ - [AgentDock GitHub Issues](https://github.com/your-org/agentdock/issues)
86
+ - [Next.js 文档](https://nextjs.org/docs)
87
+ - [Supabase 文档](https://supabase.com/docs)
@@ -0,0 +1,318 @@
1
+ ---
2
+ title: 支付:微信支付
3
+ description: 微信支付集成指南,包括架构、配置、安全和使用方法。
4
+ ---
5
+
6
+ ## 概述
7
+
8
+ 本项目集成了 **微信支付**(WeChat Pay),支持 Native 支付(扫码支付)和 JSAPI 支付(公众号/小程序内支付)场景。
9
+
10
+ ## 技术架构
11
+
12
+ ```
13
+ ┌─────────────────────────────────────────────────────────────┐
14
+ │ 用户浏览器 │
15
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
16
+ │ │ 选择商品 │ -> │ 创建订单 │ -> │ 扫码/调起支付 │ │
17
+ │ └──────────────┘ └──────────────┘ └──────────────┘ │
18
+ └─────────────────────────────────────────────────────────────┘
19
+
20
+
21
+ ┌─────────────────────────────────────────────────────────────┐
22
+ │ Next.js 应用 (Server) │
23
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
24
+ │ │ /api/pay │ │ 签名/验签 │ │ 回调处理 │ │
25
+ │ │ /api/notify │ │ │ │ │ │
26
+ │ └──────────────┘ └──────────────┘ └──────────────┘ │
27
+ └─────────────────────────────────────────────────────────────┘
28
+
29
+
30
+ ┌────────────────┐
31
+ │ 微信支付网关 │
32
+ │ (api.mch.weixin.qq.com) │
33
+ └────────────────┘
34
+ ```
35
+
36
+ ## 时序图
37
+
38
+ ```
39
+ 用户 前端页面 Next.js API 微信支付网关
40
+ │ │ │ │
41
+ │ 1.选择商品 │ │ │
42
+ │─────────────>│ │ │
43
+ │ │ 2.POST /create │ │
44
+ │ │─────────────────>│ │
45
+ │ │ │ 3.统一下单 │
46
+ │ │ │─────────────────>│
47
+ │ │ │ 4.返回 prepay_id│
48
+ │ │ │<─────────────────│
49
+ │ 5.返回支付参数│ │ │
50
+ │<─────────────│ │ │
51
+ │ 6.调起微信支付│ │ │
52
+ │─────────────────────────────────────────────────>│
53
+ │ 7.支付成功 │ │ │
54
+ │<─────────────────────────────────────────────────│
55
+ │ │ │ 8.异步通知 │
56
+ │ │ │<─────────────────│
57
+ │ │ │ 9.验签+更新状态 │
58
+ │ │ │ │
59
+ │ 10.跳转成功页│ │ │
60
+ │<─────────────│ │ │
61
+ ```
62
+
63
+ ## 前置条件
64
+
65
+ ### 微信支付商户账号
66
+
67
+ 1. 注册 [微信支付商户平台](https://pay.weixin.qq.com/) 账号
68
+ 2. 完成商户认证,获取 **商户号 (mch_id)**
69
+ 3. 申请 **API 证书** 和 **APIv3 密钥**
70
+
71
+ ### 必要配置
72
+
73
+ | 配置项 | 说明 | 获取位置 |
74
+ |--------|------|----------|
75
+ | `WECHAT_PAY_MCH_ID` | 商户号 | 微信支付商户平台 → 账户中心 |
76
+ | `WECHAT_PAY_APP_ID` | 应用 APPID | 微信开放平台/公众号平台 |
77
+ | `WECHAT_PAY_API_V3_KEY` | APIv3 密钥 | 微信支付商户平台 → 账户中心 → API安全 |
78
+ | `WECHAT_PAY_CERT_SERIAL_NO` | 证书序列号 | 商户平台 → API安全 → 管理证书 |
79
+ | `WECHAT_PAY_PRIVATE_KEY` | 商户私钥 | 下载的 apiclient_key.pem |
80
+
81
+ ## 开发环境配置
82
+
83
+ ### 1. 配置环境变量
84
+
85
+ 在 `.env.local` 中添加:
86
+
87
+ ```
88
+ WECHAT_PAY_MCH_ID=your-mch-id
89
+ WECHAT_PAY_APP_ID=your-app-id
90
+ WECHAT_PAY_API_V3_KEY=your-api-v3-key
91
+ WECHAT_PAY_CERT_SERIAL_NO=your-cert-serial-no
92
+ WECHAT_PAY_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----
93
+ WECHAT_PAY_NOTIFY_URL=https://your-domain.com/api/payments/wechat/notify
94
+ ```
95
+
96
+ > **注意**: 私钥包含换行符,使用 `\n` 转义。
97
+
98
+ ### 2. 下载 API 证书
99
+
100
+ 1. 登录 [微信支付商户平台](https://pay.weixin.qq.com/)
101
+ 2. 进入 **账户中心 → API安全 → 申请API证书**
102
+ 3. 下载证书文件(`apiclient_cert.pem` 和 `apiclient_key.pem`)
103
+
104
+ ### 3. 设置 APIv3 密钥
105
+
106
+ 在商户平台 → 账户中心 → API安全 → 设置 APIv3 密钥:
107
+
108
+ 1. 点击"设置密钥"
109
+ 2. 使用随机字符串生成器生成 32 位密钥
110
+ 3. 保存密钥(只会显示一次)
111
+
112
+ ## 生产环境配置
113
+
114
+ ### 服务器要求
115
+
116
+ - 公网可访问的 HTTPS 地址
117
+ - 支持接收 POST 请求的回调接口
118
+ - 服务器时间与微信服务器时间误差不超过 5 分钟
119
+
120
+ ### 回调地址配置
121
+
122
+ 在商户平台 → 产品中心 → 开发配置 中配置:
123
+
124
+ | 配置项 | 值 |
125
+ |--------|-----|
126
+ | 回调通知地址 | `https://your-domain.com/api/payments/wechat/notify` |
127
+
128
+ ## API 路由
129
+
130
+ ### 创建支付订单
131
+
132
+ ```http
133
+ POST /api/payments/wechat/create
134
+ Content-Type: application/json
135
+
136
+ {
137
+ "orderId": "ORDER_123456",
138
+ "amount": 99.99,
139
+ "description": "商品描述",
140
+ "openid": "user-openid" // JSAPI 支付需要
141
+ }
142
+ ```
143
+
144
+ **响应:**
145
+
146
+ ```json
147
+ {
148
+ "success": true,
149
+ "data": {
150
+ "prepayId": "wx20240101120000...",
151
+ "appId": "wx...",
152
+ "timeStamp": "1704096000",
153
+ "nonceStr": "...",
154
+ "package": "prepay_id=wx...",
155
+ "signType": "RSA",
156
+ "paySign": "..."
157
+ }
158
+ }
159
+ ```
160
+
161
+ ### 支付回调通知
162
+
163
+ ```http
164
+ POST /api/payments/wechat/notify
165
+ Content-Type: application/json
166
+ ```
167
+
168
+ 微信支付回调请求头包含 `Wechatpay-Serial` 和 `Wechatpay-Signature`:
169
+
170
+ ```ts
171
+ export async function POST(request: Request) {
172
+ const body = await request.text()
173
+ const signature = request.headers.get('Wechatpay-Signature')
174
+ const serial = request.headers.get('Wechatpay-Serial')
175
+
176
+ // 1. 验证签名
177
+ const isValid = await verifyWechatSignature(body, signature, serial)
178
+ if (!isValid) {
179
+ return new Response('Invalid signature', { status: 400 })
180
+ }
181
+
182
+ // 2. 解密回调数据
183
+ const data = JSON.parse(body)
184
+ const decrypted = await decryptWechatPayload(data)
185
+
186
+ // 3. 更新订单状态
187
+ // ...
188
+ }
189
+ ```
190
+
191
+ ### 查询订单状态
192
+
193
+ ```http
194
+ GET /api/payments/wechat/query?outTradeNo=ORDER_123456
195
+ ```
196
+
197
+ ## 安全注意事项
198
+
199
+ ### 签名验证
200
+
201
+ 微信支付使用 **RSA 签名** 和 **AES 加密**,必须严格验证:
202
+
203
+ ```ts
204
+ import { verifyWechatSignature, decryptWechatPayload } from '@/lib/wechat-pay'
205
+
206
+ export async function POST(request: Request) {
207
+ const body = await request.text()
208
+ const signature = request.headers.get('Wechatpay-Signature')
209
+
210
+ // 1. 验证签名
211
+ const isValid = await verifyWechatSignature(body, signature)
212
+ if (!isValid) {
213
+ return new Response('Invalid signature', { status: 400 })
214
+ }
215
+
216
+ // 2. 解密回调数据
217
+ const data = JSON.parse(body)
218
+ const decrypted = await decryptWechatPayload(data)
219
+
220
+ // 3. 验证金额(防止篡改)
221
+ const order = await db.payments.findOne({ outTradeNo: decrypted.out_trade_no })
222
+ if (order.amount !== decrypted.amount.total) {
223
+ return new Response('Amount mismatch', { status: 400 })
224
+ }
225
+
226
+ // 4. 更新订单状态
227
+ // ...
228
+ }
229
+ ```
230
+
231
+ ### 安全最佳实践
232
+
233
+ | 风险 | 防护措施 |
234
+ |------|----------|
235
+ | 回调伪造 | 严格验证签名和证书序列号 |
236
+ | 金额篡改 | 比对数据库订单金额与回调金额 |
237
+ | 重复通知 | 使用幂等性处理(out_trade_no 去重) |
238
+ | 密钥泄露 | 私钥仅存储在服务器端 |
239
+ | 中间人攻击 | 使用 HTTPS 传输 |
240
+ | 时间戳重放 | 检查时间戳是否在合理范围内(5分钟) |
241
+
242
+ ### 幂等性处理
243
+
244
+ ```ts
245
+ // 使用数据库唯一约束防止重复处理
246
+ await db.payments.updateOne(
247
+ { outTradeNo: decrypted.out_trade_no, status: { $ne: 'PAID' } },
248
+ {
249
+ $set: {
250
+ status: 'PAID',
251
+ transactionId: decrypted.transaction_id
252
+ }
253
+ }
254
+ )
255
+ ```
256
+
257
+ ## 开发环境调试
258
+
259
+ ### 沙箱环境
260
+
261
+ 微信支付提供沙箱环境用于开发测试:
262
+
263
+ 1. 登录 [微信支付商户平台](https://pay.weixin.qq.com/)
264
+ 2. 进入 **产品中心 → 开发配置 → 沙箱**
265
+ 3. 获取沙箱 API 密钥
266
+ 4. 修改环境变量为沙箱配置:
267
+
268
+ ```
269
+ WECHAT_PAY_GATEWAY_URL=https://api.mch.weixin.qq.com/sandboxnew
270
+ ```
271
+
272
+ ### 调试工具
273
+
274
+ - [微信支付开发者工具](https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/Android_JDk.html)
275
+ - [签名调试工具](https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay6_0.shtml)
276
+
277
+ ## 微信支付 FAQs
278
+
279
+ **Q: 回调通知收不到?**
280
+
281
+ A: 检查以下几点:
282
+ 1. 服务器是否公网可访问
283
+ 2. 回调地址是否正确配置在商户平台
284
+ 3. 是否使用 HTTPS(微信要求)
285
+ 4. 服务器时间是否准确(误差不超过5分钟)
286
+ 5. 防火墙是否放行
287
+
288
+ **Q: 签名验证失败?**
289
+
290
+ A: 常见原因:
291
+ 1. APIv3 密钥错误
292
+ 2. 私钥格式错误(应为 PKCS#8 格式)
293
+ 3. 时间戳误差超过 5 分钟
294
+ 4. 请求体编码错误(应为 UTF-8)
295
+
296
+ **Q: 如何测试支付流程?**
297
+
298
+ A: 使用微信支付沙箱环境:
299
+ 1. 在商户平台启用沙箱模式
300
+ 2. 使用沙箱 API 密钥
301
+ 3. 使用 [微信开发者工具](https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html) 模拟支付
302
+
303
+ **Q: 如何获取用户的 OpenID?**
304
+
305
+ A: 对于 JSAPI 支付,需要通过 OAuth 授权获取用户 OpenID:
306
+ 1. 引导用户访问微信 OAuth 授权链接
307
+ 2. 用户授权后,微信会重定向到回调地址并附带 `code`
308
+ 3. 使用 `code` 换取 `openid`
309
+
310
+ ## 相关资源
311
+
312
+ - [微信支付商户平台](https://pay.weixin.qq.com/)
313
+ - [微信支付开发文档](https://pay.weixin.qq.com/wiki/doc/apiv3/index.shtml)
314
+ - [Native 支付文档](https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml)
315
+ - [JSAPI 支付文档](https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml)
316
+ - [微信支付沙箱环境](https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay7_0.shtml)
317
+ - [APIv3 签名指南](https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_0.shtml)
318
+ - [回调通知说明](https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_1.shtml)
@@ -24,3 +24,38 @@ NEXT_PUBLIC_APP_URL=http://localhost:3000
24
24
  # Default locale used for root redirects and i18n fallback
25
25
  # Allowed values: en, zh
26
26
  APP_DEFAULT_LOCALE=zh
27
+
28
+ # ──────────────────────────────────────────────────────────────────────────────
29
+ # Alipay Payment (Optional)
30
+ # Get these from: Alipay Open Platform → App Center → your app
31
+ # Sandbox: https://open.alipay.com/develop/sandbox
32
+ # ──────────────────────────────────────────────────────────────────────────────
33
+ ALIPAY_APP_ID=<your-app-id>
34
+ ALIPAY_PRIVATE_KEY=-----BEGIN RSA PRIVATE KEY-----
35
+ <your-private-key>
36
+ -----END RSA PRIVATE KEY-----
37
+ ALIPAY_PUBLIC_KEY=-----BEGIN PUBLIC KEY-----
38
+ <your-public-key>
39
+ -----END PUBLIC KEY-----
40
+ # Sandbox gateway (uncomment for sandbox testing):
41
+ # ALIPAY_GATEWAY=https://openapi-sandbox.dl.alipaydev.com/gateway.do
42
+ ALIPAY_NOTIFY_URL=https://your-domain.com/api/payments/alipay/notify
43
+
44
+ # ──────────────────────────────────────────────────────────────────────────────
45
+ # WeChat Pay (Optional)
46
+ # Get these from: WeChat Pay Merchant Platform
47
+ # ──────────────────────────────────────────────────────────────────────────────
48
+ WECHAT_PAY_APP_ID=wx<your-app-id>
49
+ WECHAT_PAY_MCH_ID=<your-mch-id>
50
+ WECHAT_PAY_API_V3_KEY=<your-32-char-apiv3-key>
51
+ WECHAT_PAY_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----
52
+ <your-private-key>
53
+ -----END PRIVATE KEY-----
54
+ WECHAT_PAY_SERIAL_NO=<your-cert-serial-no>
55
+ # Platform public key (download from GET /v3/certificates)
56
+ WECHAT_PAY_PLATFORM_PUBLIC_KEY=-----BEGIN PUBLIC KEY-----
57
+ <platform-public-key>
58
+ -----END PUBLIC KEY-----
59
+ # Domestic: https://api.mch.weixin.qq.com; Overseas: https://apihk.mch.weixin.qq.com
60
+ WECHAT_PAY_BASE_URL=https://api.mch.weixin.qq.com
61
+ WECHAT_PAY_NOTIFY_URL=https://your-domain.com/api/payments/wechat/notify
@@ -124,6 +124,8 @@
124
124
  "resetPasswordSuccess": "Password updated. Please log in."
125
125
  },
126
126
  "settings": {
127
+ "profileTitle": "Profile",
128
+ "subscriptionTitle": "Subscription & Billing",
127
129
  "profile": {
128
130
  "title": "Profile Settings",
129
131
  "subtitle": "Manage your account settings and preferences.",
@@ -160,5 +162,73 @@
160
162
  "description": "Learn more about AgentDock.",
161
163
  "placeholder": "This page is a placeholder. Replace it with your actual about information before shipping."
162
164
  }
165
+ },
166
+ "pricing": {
167
+ "title": "Pricing",
168
+ "description": "Choose the plan that fits your needs",
169
+ "monthly": "Monthly",
170
+ "yearly": "Yearly",
171
+ "free": "Free",
172
+ "perMonth": "mo",
173
+ "perYear": "yr",
174
+ "currentPlan": "Current Plan",
175
+ "popular": "Popular",
176
+ "upgrade": "Upgrade",
177
+ "getStarted": "Get Started"
178
+ },
179
+ "payment": {
180
+ "checkoutTitle": "Checkout",
181
+ "orderSummary": "Order Summary",
182
+ "plan": "Plan",
183
+ "billingCycle": "Billing Cycle",
184
+ "total": "Total",
185
+ "paymentMethod": "Payment Method",
186
+ "alipay": "Alipay",
187
+ "wechatPay": "WeChat Pay",
188
+ "coupon": "Coupon",
189
+ "couponPlaceholder": "Enter coupon code",
190
+ "invalidCoupon": "Invalid coupon",
191
+ "paymentError": "Payment failed. Please try again.",
192
+ "confirmPayment": "Confirm Payment",
193
+ "processing": "Processing...",
194
+ "statusTitle": "Payment Status",
195
+ "paymentStatus": "Payment Status",
196
+ "paid": "Paid",
197
+ "pending": "Pending",
198
+ "failed": "Failed",
199
+ "paymentSuccess": "Payment successful!",
200
+ "paymentFailed": "Payment failed",
201
+ "paymentPending": "Waiting for payment...",
202
+ "paymentPendingDescription": "Please complete the payment. This page will update automatically.",
203
+ "goToDashboard": "Go to Dashboard",
204
+ "tryAgain": "Try Again"
205
+ },
206
+ "subscription": {
207
+ "title": "Subscription & Billing",
208
+ "description": "Manage your subscription and payment history",
209
+ "currentPlan": "Current Plan",
210
+ "status": "Status",
211
+ "active": "Active",
212
+ "trial": "Trial",
213
+ "expired": "Expired",
214
+ "cancelled": "Cancelled",
215
+ "pending": "Pending",
216
+ "billingCycle": "Billing Cycle",
217
+ "monthly": "Monthly",
218
+ "yearly": "Yearly",
219
+ "expiresOn": "Expires on",
220
+ "cancelRenewal": "Cancel Auto-Renewal",
221
+ "cancelledAtPeriodEnd": "Set to cancel at end of period",
222
+ "noActiveSubscription": "No active subscription",
223
+ "upgradeNow": "Upgrade Now",
224
+ "paymentHistory": "Payment History",
225
+ "noPayments": "No payment history",
226
+ "feature": "Feature",
227
+ "free": "Free",
228
+ "pro": "Pro",
229
+ "featureProjects": "Projects",
230
+ "featureApiCalls": "API Calls",
231
+ "featureSupport": "Priority Support",
232
+ "featureAnalytics": "Advanced Analytics"
163
233
  }
164
234
  }