更新记录
1.0.0(2026-07-18)
新增
- Web 端 AGC 云函数调用完整实现
initAGC: AGC 配置初始化(支持 agconnect-services.json 完整配置或密钥分传)callFunction: 通用云函数调用,支持自定义 operation 和参数query: 便捷查询,支持多条件 AND、排序、分页upsert: 便捷写入/更新deleteRecords: 便捷删除business: 便捷业务调用(deposit/withdraw/transfer/open_account/close_account)isInitialized: 检查初始化状态- Android/iOS/Harmony 平台 Stub 实现(返回不支持错误)
- 模板配置文件
resources/agconnect-services.example.json - 完整的使用文档和 API 参考
变更
- 架构从直连 Cloud DB 改为通过云函数间接访问
- 移除
@hw-agconnect/database依赖,改用@hw-agconnect/function - 移除
initCloudDB/openZone/closeZone/getServerStatus等直连数据库 API - 统一返回格式为
{ success, message, code, data }
平台兼容性
uni-app(5.21)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| - | - | √ | √ | - | - | - | - | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
uni-app x(5.21)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| - | - | - | - | - | - |
liuzk-webYunfunc — AGC 云函数调用插件
让 uni-app x Web 项目通过 AGC 云函数 间接访问华为云数据库(Cloud DB)。
前端不直连数据库,所有数据操作和业务校验都在云函数中完成,前端只负责调用。
架构
uni-app x Web → AGC Web SDK → 云函数 HTTP 触发器 → handler.js → Cloud DB
平台支持
| 平台 | 状态 |
|---|---|
| Web (uni-app x) | ✅ 支持 |
| Android | ⏳ Stub(返回不支持) |
| iOS | ⏳ Stub(返回不支持) |
| Harmony | ⏳ Stub(返回不支持) |
安装
1. 安装插件依赖
将本插件放入项目的 uni_modules/ 目录后,执行:
cd uni_modules/liuzk-webYunfunc
npm install
2. 添加 AGC 配置文件
从 AGC 控制台 下载你项目的 agconnect-services.json:
AGC 控制台 → 项目设置 → 常规 → 应用信息 → 下载
放置到项目的 static/ 目录:
你的项目/
├── static/
│ └── agconnect-services.json ← 你的配置文件
├── pages/
└── uni_modules/
└── liuzk-webYunfunc/
⚠️
agconnect-services.json包含密钥信息,已在.gitignore中排除,请勿提交到版本库。
3. 创建云函数 HTTP 触发器
在 AGC 控制台 → 构建 → 云函数 → 你的函数 → 触发器 → 创建:
- 触发器类型:HTTP 触发器
- 认证类型:API 客户端鉴权(SDK 自动处理鉴权)
- 创建后获得触发器标识(如
1f32mfqf/jinrong-$latest),后续代码中用到
使用方法
初始化
在页面 onLoad 或 App.uvue 的 onLaunch 中初始化:
import { initAGC } from '@/uni_modules/liuzk-webYunfunc'
// 方式一:从 static 目录加载配置(推荐)
async function init() {
const response = await fetch('/static/agconnect-services.json')
const config = await response.json()
initAGC({ agconnectConfig: config })
}
// 方式二:直接传配置对象
initAGC({
agconnectConfig: {
client: {
client_id: '你的client_id',
client_secret: '你的client_secret',
app_id: '你的app_id',
api_key: '你的api_key'
}
// ... 其他字段
}
})
// 方式三:分别传密钥
initAGC({
client_id: '你的client_id',
client_secret: '你的client_secret'
})
查询数据
import { query } from '@/uni_modules/liuzk-webYunfunc'
// 单条件查询
const res = await query('1f32mfqf/jinrong-$latest', 'user', [
{ field: 'username', op: 'equalTo', value: 'admin' }
])
if (res.success) {
console.log('查询结果:', res.data)
}
// 多条件查询(AND 关系)
const res2 = await query('1f32mfqf/jinrong-$latest', 'account_opening_informations', [
{ field: 'customer_account', op: 'equalTo', value: '6222021001000001' },
{ field: 'opening_amount', op: 'greaterThan', value: '1000' }
])
// 排序 + 分页
const res3 = await query(
'1f32mfqf/jinrong-$latest',
'account_opening_informations',
undefined, // 无条件(查全部)
{ field: 'opening_amount', desc: true }, // 按金额降序
10, // limit
0 // offset
)
写入/更新数据
import { upsert } from '@/uni_modules/liuzk-webYunfunc'
const res = await upsert('1f32mfqf/jinrong-$latest', 'user', [
{ id: '1', username: 'admin', password: '123456' }
])
删除数据
import { deleteRecords } from '@/uni_modules/liuzk-webYunfunc'
const res = await deleteRecords('1f32mfqf/jinrong-$latest', 'user', [
{ id: '1' }
])
业务操作
银行业务通过 business() 调用,校验逻辑在云函数中完成:
import { business } from '@/uni_modules/liuzk-webYunfunc'
// 存款
const deposit = await business('1f32mfqf/jinrong-$latest', 'deposit', {
customer_account: '6222021001000001',
actual_amount: 1000
})
// 取款
const withdraw = await business('1f32mfqf/jinrong-$latest', 'withdraw', {
customer_number: '6222021001000001',
amount: 500,
transaction_password: '123456'
})
// 转账
const transfer = await business('1f32mfqf/jinrong-$latest', 'transfer', {
fund_source_account: '6222021001000001',
transfer_amount: 500,
transaction_password: '123456'
})
// 开户
const openAccount = await business('1f32mfqf/jinrong-$latest', 'open_account', {
customer_account: '6222021001000003',
opening_amount: 5000
})
// 销户
const closeAccount = await business('1f32mfqf/jinrong-$latest', 'close_account', {
customer_account: '6222021001000003'
})
通用云函数调用
直接传完整参数,适合自定义 operation:
import { callFunction } from '@/uni_modules/liuzk-webYunfunc'
const res = await callFunction(
'1f32mfqf/jinrong-$latest', // triggerURI
'query', // operation
{ // params
objectType: 'user',
condition: { op: 'equalTo', field: 'username', value: 'admin' }
}
)
API 参考
初始化
| 函数 | 参数 | 说明 |
|---|---|---|
initAGC(config) |
AGCInitConfig |
初始化 AGC,传 agconnectConfig 或 client_id/client_secret |
isInitialized() |
— | 返回是否已初始化 |
数据操作
| 函数 | 参数 | 说明 |
|---|---|---|
callFunction(triggerURI, operation, params?, timeout?) |
string, string, object?, number? |
通用云函数调用 |
query(triggerURI, objectTypeName, conditions?, orderBy?, limit?, offset?) |
— | 便捷查询 |
upsert(triggerURI, objectTypeName, records) |
— | 便捷写入/更新 |
deleteRecords(triggerURI, objectTypeName, records) |
— | 便捷删除 |
business(triggerURI, operation, params) |
— | 便捷业务调用 |
查询条件操作符
equalTo, notEqualTo, greaterThan, greaterThanOrEqualTo,
lessThan, lessThanOrEqualTo, beginsWith, endsWith,
contains, isNull, isNotNull, in
返回格式
所有异步操作返回 Promise<CloudFunctionResult>:
// 成功
{ success: true, message: 'SUCCESS', code: 0, data: [...] }
// 失败
{ success: false, message: '错误信息', code: -1 }
配置说明
agconnect-services.json 格式
从 AGC 控制台下载的配置文件包含以下关键字段:
{
"client": {
"client_id": "应用ID",
"client_secret": "应用密钥",
"app_id": "应用AppID",
"api_key": "API密钥",
"cp_id": "开发者ID",
"project_id": "项目ID"
},
"agcgw": {
"url": "connect-drcn.dbankcloud.cn"
},
"region": "CN"
}
插件根目录 resources/agconnect-services.example.json 提供了完整模板。
安全注意
agconnect-services.json包含密钥,已在.gitignore中排除,请勿提交- 云函数 HTTP 触发器认证类型请选「API 客户端鉴权」,由 SDK 自动处理
- 敏感业务逻辑(密码校验、金额限制等)在云函数中完成,前端不包含业务规则
- 生产环境建议使用 AGC 的 Token 模式替代直接密钥
云函数 handler.js 接口约定
本插件调用的云函数需遵循以下接口约定:
// 请求格式(event)
{
"operation": "query|upsert|delete|deposit|withdraw|transfer|open_account|close_account",
"objectType": "user",
"condition": { "op": "equalTo", "field": "username", "value": "admin" },
"records": [...],
"params": { ... }
}
// 响应格式
{
"ret": { "code": 0, "desc": "SUCCESS" },
"data": [...]
}
依赖
@hw-agconnect/api^1.5.1@hw-agconnect/instance^1.5.1@hw-agconnect/function^1.5.1

收藏人数:
购买源码授权版(
试用
赞赏(0)
下载 40
赞赏 0
下载 12436639
赞赏 1934
赞赏
京公网安备:11010802035340号