目標用戶:大學(xué)生、知識付費人群、興趣愛好者、小眾社群、企業(yè)員工等。
商業(yè)模式:
| — | ||||
|---|---|---|---|---|
| 在線開發(fā)環(huán)境 | Replit | |||
| AI 引擎 | OpenAI API | |||
| 前端框架 | 微信小程序原生 / WePY, 支付寶小程序原生 | |||
| 后端語言 | Node.js / Python | |||
| Web 框架 | Express (Express.js) / FastAPI (FastAPI) | |||
| 數(shù)據(jù)存儲 | MongoDB Atlas / Firebase | |||
| 支付對接 | 微信支付 / 支付寶開放平臺 | |||
| 部署平臺 | Replit 內(nèi)置部署 / Vercel / Railway | |||
| 日志與監(jiān)控 | Sentry / Logflare |
提示:初期可省略專用數(shù)據(jù)庫,使用 Replit 提供的文件存儲;隨著用戶量增長,再遷移至云端數(shù)據(jù)庫。
以「智能對話問答+文本生成」為核心,搭建一款面向 校園課業(yè)答疑 或 興趣愛好問答 的小程序。主要功能:
以下示例以 Node.js + Express + OpenAI 為后端,微信小程序為前端,演示核心流程。支付寶小程序同理,API 名稱有所差異,文末附對接要點。
注冊并登錄 Replit;
點擊 “Create” → 選擇 “Node.js” 模板;
在項目根目錄新建 .env,添加:
OPENAI_API_KEY=你的_openai_api_key
WECHAT_APPID=你的小程序 AppID
WECHAT_MCHID=你的商戶號
WECHAT_APIKEY=你的支付密鑰
安裝依賴:
npm install express openai weixin-pay body-parser cors
app.listen(port, () = > console.log(后端服務(wù)已啟動,端口 ${port}));
const app = express();
app.use(cors(), bodyParser.json());
/** OpenAI 配置 */
const openai = new [OpenAIApi](http://www.dlbhg.com/api/ai_openai_brand)(new Configuration({
apiKey: process.env.OPENAI_API_KEY,
}));
/** [微信支付](http://www.dlbhg.com/provider/uid2024012990261bb023f9)配置 */
const wxpay = new WechatPay({
appid: process.env.WECHAT_APPID,
mch_id: process.env.WECHAT_MCHID,
partner_key: process.env.WECHAT_APIKEY,
});
/** [AI 問答接口](http://www.dlbhg.com/blog/ua-ai-free-api-comprehensive-guide) */
app.post('/api/ask', async (req, res) = > {
const { messages } = req.body;
try {
const rsp = await openai.createChatCompletion({
model: 'gpt-3.5-turbo',
messages,
temperature: 0.6,
max_tokens: 800,
});
res.json({ reply: rsp.data.choices[0].message.content });
} catch (e) {
console.error(e);
res.status(500).json({ error: 'AI 服務(wù)異常' });
}
});
/** 發(fā)起支付接口 */
app.post('/api/pay', (req, res) = > {
const { openid, description, amount } = req.body;
const params = {
body: description,
out_trade_no: Date.now().toString(),
total_fee: amount, // 分為單位
spbill_create_ip: req.ip,
notify_url: 'https://你的域名/api/pay/notify',
trade_type: 'JSAPI',
openid,
};
wxpay.getBrandWCPayRequestParams(params, (err, payargs) = > {
if (err) return res.status(500).json({ error: err });
res.json(payargs);
});
});
/** 支付回調(diào)通知 */
app.post('/api/pay/notify', bodyParser.xml(), (req, res) = > {
const notifyData = req.body.xml;
// TODO: 驗簽、訂單狀態(tài)更新
res.send({ xml: { return_code: 'SUCCESS', return_msg: 'OK' } });
});
const port = process.env.PORT || 3000;
app.listen(port, () = > console.log(后端服務(wù)已啟動,端口 ${port}));
使用微信開發(fā)者工具,新建小程序項目,AppID 填寫你的 __WECHAT_APPID__。
app.jsApp({
globalData: {
apiUrl: 'https://你的 Replit 域名',
history: [],
}
});
pages/index/index.wxml
{{item.role}}: {{item.content}}
pages/index/index.jsconst app = getApp();
Page({
data: {
input: '',
history: [],
},
onInput(e) {
this.setData({ input: e.detail.value });
},
async askAI() {
const { input, history } = this.data;
const messages = [...history, { role: 'user', content: input }];
const res = await wx.request({
url: ${app.globalData.apiUrl}/api/ask,
method: 'POST',
data: { messages },
});
const reply = res.data.reply;
const newHistory = [...messages, { role: 'assistant', content: reply }];
this.setData({ history: newHistory, input: '' });
},
async toPay() {
const session = await wx.login();
const res = await wx.request({
url: ${app.globalData.apiUrl}/api/pay,
method: 'POST',
data: { openid: session.code, description: 'AI 會員', amount: 100 },
});
wx.requestPayment(res.data);
},
});
index.wxss.container { padding: 20px; }
textarea { width: 100%; height: 100px; border: 1px solid #ccc; }
button { margin-top: 10px; }
Replit 自動部署:在項目 Settings → Secrets/Variables 中配置環(huán)境變量,Replit 會自動重啟并更新。
自定義域名:購買域名并在 Replit 設(shè)置中綁定,實現(xiàn) https://your-domain.com。
HTTPS 證書:Replit 自動管理,無需手動配置。
alipay-trade-sdk 或直接調(diào)用 REST 接口。支付流程:
alipay.trade.create;my.tradePay 接口。notify_id 與簽名,確保支付安全。示例后端代碼略與微信一致,僅需替換支付 SDK 與接口參數(shù)。
付費社群:AI 問答+大咖直播;
專屬定制:企業(yè)或課程機構(gòu)定制版小程序。
如何控制 API 成本?
max_tokens;如何提升響應(yīng)速度?
如何保障穩(wěn)定運營?
| — | ||||||||
|---|---|---|---|---|---|---|---|---|
| 按次付費 | 3 元/次,平均每日 200 次 | 6000 次 | 18,000 | |||||
| 會員訂閱 | 50 元/月 × 100 人 | 100 人 | 5,000 | |||||
| 廣告分成 | 0.2 元/次 × 10,000 次 | 10,000 次 | 2,000 | |||||
| 合計 | — | — | 25,000+ |
即使保守估計,僅憑 200 人日常使用,也能實現(xiàn)日入 500+ 的目標。
推廣啟動:制定校園和線上推廣計劃,實現(xiàn)穩(wěn)定引流與變現(xiàn)。
行動提示:現(xiàn)在就打開你的瀏覽器,登錄 Replit,創(chuàng)建第一個 AI 小程序項目,2 小時后,你就能擁有第一筆小程序收入!
本文提到的平臺與文檔:
- Replit:https://replit.com/
- OpenAI API:https://platform.openai.com/
- 微信支付:https://pay.weixin.qq.com/
- 支付寶開放平臺:https://open.alipay.com/
- Express.js:https://expressjs.com/
- FastAPI:https://fastapi.tiangolo.com/
祝你在 2025 年的副業(yè)道路上捷報頻傳,開啟 AI 小程序賺錢快車道!