基于 Gemini 2.5 Flash Image 的AI图像处理服务
🎉 新增功能:本服务现已支持微信小程序登录和积分系统!用户可以通过微信登录,充值积分,使用积分调用AI图片处理服务。
| API功能 | 积分消费 | 说明 |
|---|---|---|
| 老照片修复 | 10积分 | 基础修复功能 |
| AI换装 | 20积分 | 复杂的风格转换 |
| 自定义处理 | 15积分 | 灵活的图片处理 |
| 照片动画 | 30积分 | 最高级的视频生成 |
// 小程序端代码
wx.login({
success: (res) => {
if (res.code) {
wx.request({
url: 'https://your-domain.com/api/wechat/login',
method: 'POST',
data: { code: res.code },
success: (loginRes) => {
// 保存用户token
wx.setStorageSync('userToken', loginRes.data.token);
wx.setStorageSync('userInfo', loginRes.data.user);
console.log('积分余额:', loginRes.data.user.points);
}
});
}
}
});
// 调用AI API时需要携带token
wx.uploadFile({
url: 'https://your-domain.com/api/image/outfit-change',
filePath: imagePath,
name: 'image',
header: {
'Authorization': 'Bearer ' + wx.getStorageSync('userToken')
},
formData: { style: '商务正装' },
success: (res) => {
const data = JSON.parse(res.data);
console.log('剩余积分:', data.points.remaining);
console.log('处理结果:', data.data.imageUrl);
}
});
// 创建充值订单
wx.request({
url: 'https://your-domain.com/api/wechat/payment/create',
method: 'POST',
header: {
'Authorization': 'Bearer ' + wx.getStorageSync('userToken')
},
data: {
amount: 10.0, // 充值10元
description: '购买100积分'
},
success: (res) => {
if (res.data.success) {
// 调起微信支付
wx.requestPayment({
...res.data.paymentParams,
success: () => {
console.log('充值成功');
// 刷新用户积分
refreshUserInfo();
}
});
}
}
});
// 获取用户信息和积分余额
wx.request({
url: 'https://your-domain.com/api/wechat/user/info',
method: 'GET',
header: {
'Authorization': 'Bearer ' + wx.getStorageSync('userToken')
},
success: (res) => {
console.log('用户信息:', res.data.data);
console.log('积分余额:', res.data.data.points);
}
});
POST /api/wechat/login
功能:通过微信小程序授权码进行用户登录,获取访问令牌
| 参数名 | 类型 | 是否必须 | 说明 |
|---|---|---|---|
| code | String | 是 | 微信小程序wx.login()获取的授权码 |
{
"code": "061gHGll2A3t8K4Jfnol2jGjEp3gHGlA"
}
{
"success": true,
"user": {
"id": "user_1736250123_abcdefg",
"openid": "oABC123def456ghi789jkl",
"points": 100,
"nickname": "",
"avatar": ""
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
{
"error": "登录失败",
"message": "WeChat login error: invalid code",
"code": "LOGIN_ERROR"
}
POST /api/wechat/payment/create
功能:创建微信支付订单,用户充值积分
Authorization: Bearer {用户token}
Content-Type: application/json
| 参数名 | 类型 | 是否必须 | 说明 |
|---|---|---|---|
| amount | Number | 是 | 充值金额(元),必须大于0 |
| description | String | 否 | 订单描述,默认"购买积分" |
{
"amount": 10.0,
"description": "购买100积分"
}
{
"success": true,
"orderId": "order_1736250123_abcdefg",
"paymentParams": {
"appId": "wx765b20f090a4a0f9",
"timeStamp": "1736250123",
"nonceStr": "abc123def456",
"package": "prepay_id=wx123456789012345678901234567890",
"signType": "MD5",
"paySign": "C380BEC2BFD727A4B6845133519F3AD6"
},
"amount": 10.0
}
{
"error": "创建订单失败",
"message": "WeChat payment not configured",
"code": "CREATE_ORDER_ERROR"
}
GET /api/wechat/user/info
功能:获取用户完整信息和当前积分余额
认证:需要Bearer Token
GET /api/wechat/user/info
Authorization: Bearer your_token_here
{
"success": true,
"data": {
"id": "user_1234567890_abc123def",
"openid": "wx_openid_example_123456",
"nickname": "微信用户昵称",
"avatar": "https://wx.qlogo.cn/mmopen/avatar.jpg",
"points": 150,
"created_at": "2024-01-15T08:30:00.000Z"
}
}
GET /api/wechat/points/config
功能:获取积分系统配置信息
认证:不需要
GET /api/wechat/points/config
{
"success": true,
"data": {
"apiCosts": {
"restore_photo": 10, // 老照片修复积分消耗
"outfit_change": 20, // 换装功能积分消耗
"custom": 15, // 自定义处理积分消耗
"animate": 30 // 照片动画积分消耗
},
"exchangeRate": 10, // 充值比例:1元 = 10积分
"newUserBonus": 100 // 新用户注册赠送积分
}
}
GET /api/wechat/user/transactions
功能:获取用户积分交易记录
认证:需要Bearer Token
limit (可选): 返回记录数量,默认50GET /api/wechat/user/transactions?limit=20
Authorization: Bearer your_token_here
{
"success": true,
"data": {
"transactions": [
{
"id": "trans_123456789",
"type": "earn", // earn=获得积分, spend=消费积分
"amount": 100,
"description": "微信支付充值",
"wechat_order_id": "wx_order_123",
"created_at": "2024-01-15T10:30:00.000Z"
},
{
"id": "trans_987654321",
"type": "spend",
"amount": 20,
"description": "换装功能 API调用",
"api_call_id": "api_call_456",
"created_at": "2024-01-15T09:15:00.000Z"
}
],
"total": 25
}
}
GET /api/wechat/user/api-usage
功能:获取用户API使用记录
认证:需要Bearer Token
limit (可选): 返回记录数量,默认50GET /api/wechat/user/api-usage?limit=10
Authorization: Bearer your_token_here
{
"success": true,
"data": {
"usage": [
{
"id": "usage_123456789",
"api_type": "outfit_change",
"points_cost": 20,
"request_id": "req_789012345",
"success": true,
"created_at": "2024-01-15T09:15:00.000Z"
},
{
"id": "usage_987654321",
"api_type": "restore_photo",
"points_cost": 10,
"request_id": "req_456789012",
"success": true,
"created_at": "2024-01-15T08:45:00.000Z"
}
],
"total": 15
}
}
所有图像处理API都会返回积分信息:
{
"success": true,
"message": "处理完成",
"data": {
// ... 处理结果数据
},
"points": {
"deducted": 20, // 本次扣除的积分
"remaining": 130 // 扣除后的剩余积分
}
}
{
"error": "积分不足",
"code": "INSUFFICIENT_POINTS",
"message": "当前积分:5,需要积分:20"
}
| 接口 | 方法 | 认证 | 说明 |
|---|---|---|---|
| /api/wechat/user/info | GET | 需要 | 获取用户信息和积分余额 |
| /api/wechat/user/transactions | GET | 需要 | 获取用户交易记录 |
| /api/wechat/user/api-usage | GET | 需要 | 获取API使用记录 |
| /api/wechat/points/config | GET | 不需要 | 获取积分配置信息 |
// app.js - 全局登录处理
App({
globalData: {
userInfo: null,
token: null,
apiBase: 'https://your-domain.com/api'
},
onLaunch() {
this.login();
},
// 用户登录
async login() {
return new Promise((resolve, reject) => {
wx.login({
success: (res) => {
if (res.code) {
wx.request({
url: this.globalData.apiBase + '/wechat/login',
method: 'POST',
data: { code: res.code },
success: (loginRes) => {
if (loginRes.data.success) {
this.globalData.token = loginRes.data.token;
this.globalData.userInfo = loginRes.data.user;
wx.setStorageSync('token', loginRes.data.token);
wx.setStorageSync('userInfo', loginRes.data.user);
resolve(loginRes.data);
} else {
reject(loginRes.data);
}
},
fail: reject
});
} else {
reject(res);
}
},
fail: reject
});
});
},
// 检查积分余额
async checkPoints(required) {
const userInfo = wx.getStorageSync('userInfo') || this.globalData.userInfo;
if (!userInfo || userInfo.points < required) {
wx.showModal({
title: '积分不足',
content: `操作需要${required}积分,您当前有${userInfo?.points || 0}积分。是否前往充值?`,
success: (res) => {
if (res.confirm) {
// 跳转到充值页面
wx.navigateTo({ url: '/pages/recharge/recharge' });
}
}
});
return false;
}
return true;
},
// 使用AI服务
async useAI(apiPath, filePath, params = {}) {
const token = wx.getStorageSync('token') || this.globalData.token;
if (!token) {
await this.login();
}
return new Promise((resolve, reject) => {
wx.uploadFile({
url: this.globalData.apiBase + apiPath,
filePath: filePath,
name: 'image',
header: {
'Authorization': `Bearer ${token}`
},
formData: params,
success: (res) => {
try {
const data = JSON.parse(res.data);
if (data.success) {
// 更新用户积分信息
if (data.points) {
const userInfo = wx.getStorageSync('userInfo');
userInfo.points = data.points.remaining;
wx.setStorageSync('userInfo', userInfo);
this.globalData.userInfo = userInfo;
}
resolve(data);
} else {
reject(data);
}
} catch (e) {
reject({ message: '解析响应失败', error: e });
}
},
fail: reject
});
});
}
});
Nano Banana 提供四个场景化的AI图像处理接口,基于 Gemini 2.5 Flash Image Preview 模型。
Authorization: Bearer {token} 并确保有足够的积分余额。
使用AI图片处理功能前,用户需要先登录获取token,如积分不足需要充值。
POST https://banana.8miao.cn/api/wechat/login
功能说明:通过微信小程序授权码进行用户登录,新用户自动注册并获得100积分奖励。
| 参数名 | 类型 | 是否必须 | 说明 |
|---|---|---|---|
| code | String | 是 | 微信小程序wx.login()获取的授权码 |
{
"success": true,
"user": {
"id": "user_1736250123_abcdefg",
"openid": "oABC123def456ghi789jkl",
"points": 100,
"nickname": "",
"avatar": ""
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
POST https://banana.8miao.cn/api/wechat/payment/create
功能说明:创建微信支付订单,用户充值积分。充值比例:1元 = 10积分。
Authorization: Bearer {用户token}
Content-Type: application/json
| 参数名 | 类型 | 是否必须 | 说明 |
|---|---|---|---|
| amount | Number | 是 | 充值金额(元),必须大于0 |
| description | String | 否 | 订单描述,默认"购买积分" |
{
"success": true,
"orderId": "order_1736250123_abcdefg",
"paymentParams": {
"appId": "wx765b20f090a4a0f9",
"timeStamp": "1736250123",
"nonceStr": "abc123def456",
"package": "prepay_id=wx123456789012345678901234567890",
"signType": "MD5",
"paySign": "C380BEC2BFD727A4B6845133519F3AD6"
},
"amount": 10.0
}
POST https://banana.8miao.cn/api/image/restore
使用AI技术修复老旧、破损的照片,提升清晰度,修复划痕和污渍,调整亮度和对比度,保持原有历史风格。
Authorization: Bearer {用户token}
Content-Type: multipart/form-data
| 参数名 | 类型 | 是否必须 | 说明 |
|---|---|---|---|
| image | File | 是 | 需要修复的老照片文件 |
💰 消费:10积分 | 仅在处理成功后扣除
{
"success": true,
"message": "老照片修复完成",
"requestId": "req_1704123456",
"processingTime": "3245ms",
"data": {
"originalImage": "upload_123.jpg",
"restoredImage": "restored_123.jpg",
"imageUrl": "/uploads/restored_123.jpg"
},
"points": {
"deducted": 10,
"remaining": 170
}
}
POST https://banana.8miao.cn/api/image/outfit-change
为人物图片更换服装风格,保持人物面部和体型特征不变,支持风格描述和参考图片两种方式。
Authorization: Bearer {用户token}
Content-Type: multipart/form-data
| 参数名 | 类型 | 是否必须 | 说明 |
|---|---|---|---|
| image | File | 是 | 包含人物的原始图片 |
| style | String | 二选一 | 服装风格描述 |
| reference | File | 二选一 | 参考服装的图片文件 |
💰 消费:20积分 | 仅在处理成功后扣除
{
"success": true,
"message": "换装完成",
"requestId": "req_1704123457",
"processingTime": "5678ms",
"data": {
"originalImage": "upload_124.jpg",
"changedImage": "outfit_124.jpg",
"imageUrl": "/uploads/outfit_124.jpg",
"style": "商务正装",
"useReference": false,
"referenceImage": null
},
"points": {
"deducted": 20,
"remaining": 150
}
}
POST https://banana.8miao.cn/api/image/custom
根据用户自定义指令对图片进行AI处理,支持背景更换、滤镜效果、风格转换等多种操作。
Authorization: Bearer {用户token}
Content-Type: multipart/form-data
| 参数名 | 类型 | 是否必须 | 说明 |
|---|---|---|---|
| image | File | 是 | 需要处理的原始图片 |
| prompt | String | 是 | 处理指令描述 |
💰 消费:15积分 | 仅在处理成功后扣除
{
"success": true,
"message": "自定义图片处理完成",
"requestId": "req_1704123458",
"processingTime": "4567ms",
"data": {
"originalImage": "upload_125.jpg",
"processedImage": "custom_125.jpg",
"imageUrl": "/uploads/custom_125.jpg",
"prompt": "把背景改成海滩日落风景"
},
"points": {
"deducted": 15,
"remaining": 135
}
}
POST https://banana.8miao.cn/api/image/animate
使用Veo 3将静态照片转换为动态视频,支持人像动画、场景动画和自定义动画效果。
Authorization: Bearer {用户token}
Content-Type: multipart/form-data
| 参数名 | 类型 | 是否必须 | 说明 |
|---|---|---|---|
| image | File | 是 | 需要制作动画的图片文件 |
| animationType | String | 否 | 动画类型:general/portrait/scene/custom,默认general |
| expressionType | String | 否 | 表情类型(portrait时使用):natural/smile/blink/nod/speak |
| sceneType | String | 否 | 场景类型(scene时使用):gentle/dynamic/nature/urban/vintage |
| motionPrompt | String | 条件必须 | 自定义动作描述(custom时必须) |
| modelType | String | 否 | 模型版本:preview/fast/stable,默认preview |
| aspectRatio | String | 否 | 宽高比:16:9/9:16,默认16:9 |
| negativePrompt | String | 否 | 负面提示词,排除不希望的内容 |
💰 消费:30积分 | 仅在处理成功后扣除
{
"success": true,
"message": "照片动画生成完成",
"requestId": "req_1704123459",
"processingTime": "15678ms",
"data": {
"originalImage": "upload_126.jpg",
"animatedVideo": "animated_126_photo.mp4",
"videoUrl": "/uploads/animated_126_photo.mp4",
"animationType": "portrait",
"duration": "3s",
"resolution": "1024x576",
"mimeType": "video/mp4"
},
"points": {
"deducted": 30,
"remaining": 105
}
}
{
"success": false,
"message": "具体错误信息",
"error": "错误代码或详细描述"
}
| 状态码 | 错误类型 | 说明 |
|---|---|---|
| 401 | Unauthorized | 未登录或token过期,需要重新登录 |
| 402 | Payment Required | 积分不足,需要充值后重试 |
| 429 | Too Many Requests | API配额限制,请稍后重试 |
| 502 | Bad Gateway | AI服务错误,请稍后重试 |