|
| 1 | +package cn.binarywang.wx.miniapp.api; |
| 2 | + |
| 3 | +import cn.binarywang.wx.miniapp.bean.cloud.*; |
| 4 | +import com.google.gson.JsonArray; |
| 5 | +import me.chanjar.weixin.common.error.WxErrorException; |
| 6 | + |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +/** |
| 10 | + * 云开发相关接口. |
| 11 | + * |
| 12 | + * @author <a href="https://github.com/binarywang">Binary Wang</a> |
| 13 | + * @date 2020-01-22 |
| 14 | + */ |
| 15 | +public interface WxMaCloudService { |
| 16 | + String INVOKE_CLOUD_FUNCTION_URL = "https://api.weixin.qq.com/tcb/invokecloudfunction?env=%s&name=%s"; |
| 17 | + String DATABASE_COLLECTION_GET_URL = "https://api.weixin.qq.com/tcb/databasecollectionget"; |
| 18 | + String DATABASE_COLLECTION_DELETE_URL = "https://api.weixin.qq.com/tcb/databasecollectiondelete"; |
| 19 | + String DATABASE_COLLECTION_ADD_URL = "https://api.weixin.qq.com/tcb/databasecollectionadd"; |
| 20 | + String GET_QCLOUD_TOKEN_URL = "https://api.weixin.qq.com/tcb/getqcloudtoken"; |
| 21 | + String BATCH_DELETE_FILE_URL = "https://api.weixin.qq.com/tcb/batchdeletefile"; |
| 22 | + String UPLOAD_FILE_URL = "https://api.weixin.qq.com/tcb/uploadfile"; |
| 23 | + String DATABASE_MIGRATE_QUERY_INFO_URL = "https://api.weixin.qq.com/tcb/databasemigratequeryinfo"; |
| 24 | + String DATABASE_MIGRATE_EXPORT_URL = "https://api.weixin.qq.com/tcb/databasemigrateexport"; |
| 25 | + String DATABASE_MIGRATE_IMPORT_URL = "https://api.weixin.qq.com/tcb/databasemigrateimport"; |
| 26 | + String UPDATE_INDEX_URL = "https://api.weixin.qq.com/tcb/updateindex"; |
| 27 | + String DATABASE_COUNT_URL = "https://api.weixin.qq.com/tcb/databasecount"; |
| 28 | + String DATABASE_AGGREGATE_URL = "https://api.weixin.qq.com/tcb/databaseaggregate"; |
| 29 | + String DATABASE_QUERY_URL = "https://api.weixin.qq.com/tcb/databasequery"; |
| 30 | + String DATABASE_UPDATE_URL = "https://api.weixin.qq.com/tcb/databaseupdate"; |
| 31 | + String DATABASE_DELETE_URL = "https://api.weixin.qq.com/tcb/databasedelete"; |
| 32 | + String DATABASE_ADD_URL = "https://api.weixin.qq.com/tcb/databaseadd"; |
| 33 | + |
| 34 | + /** |
| 35 | + * <pre> |
| 36 | + * 触发云函数。注意:HTTP API 途径触发云函数不包含用户信息。 |
| 37 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/functions/invokeCloudFunction.html |
| 38 | + * |
| 39 | + * 请求地址 |
| 40 | + * POST https://api.weixin.qq.com/tcb/invokecloudfunction?access_token=ACCESS_TOKEN&env=ENV&name=FUNCTION_NAME |
| 41 | + * |
| 42 | + * </pre> |
| 43 | + * |
| 44 | + * @param env string 是 云开发环境ID |
| 45 | + * @param name string 是 云函数名称 |
| 46 | + * @param body string 是 云函数的传入参数,具体结构由开发者定义。 |
| 47 | + * @return resp_data string 云函数返回的buffer |
| 48 | + * @throws WxErrorException . |
| 49 | + */ |
| 50 | + String invokeCloudFunction(String env, String name, String body) throws WxErrorException; |
| 51 | + |
| 52 | + /** |
| 53 | + * <pre> |
| 54 | + * 数据库插入记录 |
| 55 | + * |
| 56 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseAdd.html |
| 57 | + * 请求地址:POST https://api.weixin.qq.com/tcb/databaseadd?access_token=ACCESS_TOKEN |
| 58 | + * </pre> |
| 59 | + * |
| 60 | + * @param env 云环境ID |
| 61 | + * @param query 数据库操作语句 |
| 62 | + * @return 插入成功的数据集合主键_id |
| 63 | + * @throws WxErrorException . |
| 64 | + */ |
| 65 | + JsonArray databaseAdd(String env, String query) throws WxErrorException; |
| 66 | + |
| 67 | + /** |
| 68 | + * <pre> |
| 69 | + * 数据库删除记录 |
| 70 | + * |
| 71 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseDelete.html |
| 72 | + * 请求地址:POST https://api.weixin.qq.com/tcb/databasedelete?access_token=ACCESS_TOKEN |
| 73 | + * </pre> |
| 74 | + * |
| 75 | + * @param env 云环境ID |
| 76 | + * @param query 数据库操作语句 |
| 77 | + * @return 删除记录数量 |
| 78 | + * @throws WxErrorException . |
| 79 | + */ |
| 80 | + int databaseDelete(String env, String query) throws WxErrorException; |
| 81 | + |
| 82 | + /** |
| 83 | + * <pre> |
| 84 | + * 数据库更新记录 |
| 85 | + * |
| 86 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseUpdate.html |
| 87 | + * 请求地址:POST https://api.weixin.qq.com/tcb/databaseupdate?access_token=ACCESS_TOKEN |
| 88 | + * </pre> |
| 89 | + * |
| 90 | + * @param env 云环境ID |
| 91 | + * @param query 数据库操作语句 |
| 92 | + * @return . |
| 93 | + * @throws WxErrorException . |
| 94 | + */ |
| 95 | + WxCloudDatabaseUpdateResult databaseUpdate(String env, String query) throws WxErrorException; |
| 96 | + |
| 97 | + /** |
| 98 | + * <pre> |
| 99 | + * 数据库查询记录 |
| 100 | + * |
| 101 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseQuery.html |
| 102 | + * 请求地址:POST https://api.weixin.qq.com/tcb/databasequery?access_token=ACCESS_TOKEN |
| 103 | + * </pre> |
| 104 | + * |
| 105 | + * @param env 云环境ID |
| 106 | + * @param query 数据库操作语句 |
| 107 | + * @return . |
| 108 | + * @throws WxErrorException . |
| 109 | + */ |
| 110 | + WxCloudDatabaseQueryResult databaseQuery(String env, String query) throws WxErrorException; |
| 111 | + |
| 112 | + /** |
| 113 | + * <pre> |
| 114 | + * 数据库聚合记录 |
| 115 | + * |
| 116 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseAggregate.html |
| 117 | + * 请求地址:POST https://api.weixin.qq.com/tcb/databaseaggregate?access_token=ACCESS_TOKEN |
| 118 | + * </pre> |
| 119 | + * |
| 120 | + * @param env 云环境ID |
| 121 | + * @param query 数据库操作语句 |
| 122 | + * @return . |
| 123 | + * @throws WxErrorException . |
| 124 | + */ |
| 125 | + JsonArray databaseAggregate(String env, String query) throws WxErrorException; |
| 126 | + |
| 127 | + /** |
| 128 | + * <pre> |
| 129 | + * 统计集合记录数或统计查询语句对应的结果记录数 |
| 130 | + * |
| 131 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCount.html |
| 132 | + * 请求地址:POST https://api.weixin.qq.com/tcb/databasecount?access_token=ACCESS_TOKEN |
| 133 | + * </pre> |
| 134 | + * |
| 135 | + * @param env 云环境ID |
| 136 | + * @param query 数据库操作语句 |
| 137 | + * @return 记录数量 |
| 138 | + * @throws WxErrorException . |
| 139 | + */ |
| 140 | + Long databaseCount(String env, String query) throws WxErrorException; |
| 141 | + |
| 142 | + /** |
| 143 | + * <pre> |
| 144 | + * 变更数据库索引 |
| 145 | + * |
| 146 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/updateIndex.html |
| 147 | + * 请求地址:POST https://api.weixin.qq.com/tcb/updateindex?access_token=ACCESS_TOKEN |
| 148 | + * </pre> |
| 149 | + * |
| 150 | + * @param env 云环境ID |
| 151 | + * @param collectionName 集合名称 |
| 152 | + * @param createIndexes 新增索引对象 |
| 153 | + * @param dropIndexNames 要删除的索引的名字 |
| 154 | + * @throws WxErrorException . |
| 155 | + */ |
| 156 | + void updateIndex(String env, String collectionName, List<WxCloudDatabaseCreateIndexRequest> createIndexes, |
| 157 | + List<String> dropIndexNames) throws WxErrorException; |
| 158 | + |
| 159 | + /** |
| 160 | + * <pre> |
| 161 | + * 数据库导入 |
| 162 | + * |
| 163 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateImport.html |
| 164 | + * 请求地址: POST https://api.weixin.qq.com/tcb/databasemigrateimport?access_token=ACCESS_TOKEN |
| 165 | + * </pre> |
| 166 | + * |
| 167 | + * @param env 云环境ID |
| 168 | + * @param collectionName 导入collection名 |
| 169 | + * @param filePath 导入文件路径(导入文件需先上传到同环境的存储中,可使用开发者工具或 HTTP API的上传文件 API上传) |
| 170 | + * @param fileType 导入文件类型, 1 JSON, 2 CSV |
| 171 | + * @param stopOnError 是否在遇到错误时停止导入 |
| 172 | + * @param conflictMode 冲突处理模式 : 1 INSERT , 2 UPSERT |
| 173 | + * @return jobId |
| 174 | + * @throws WxErrorException . |
| 175 | + */ |
| 176 | + Long databaseMigrateImport(String env, String collectionName, String filePath, int fileType, boolean stopOnError, |
| 177 | + int conflictMode) throws WxErrorException; |
| 178 | + |
| 179 | + /** |
| 180 | + * <pre> |
| 181 | + * 数据库导出 |
| 182 | + * |
| 183 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateExport.html |
| 184 | + * 请求地址: POST https://api.weixin.qq.com/tcb/databasemigrateexport?access_token=ACCESS_TOKEN |
| 185 | + * </pre> |
| 186 | + * |
| 187 | + * @param env 云环境ID |
| 188 | + * @param filePath 导出文件路径(文件会导出到同环境的云存储中,可使用获取下载链接 API 获取下载链接) |
| 189 | + * @param fileType 导出文件类型, 1 JSON, 2 CSV |
| 190 | + * @param query 导出条件 |
| 191 | + * @return jobId |
| 192 | + * @throws WxErrorException . |
| 193 | + */ |
| 194 | + Long databaseMigrateExport(String env, String filePath, int fileType, String query) throws WxErrorException; |
| 195 | + |
| 196 | + /** |
| 197 | + * <pre> |
| 198 | + * 数据库迁移状态查询 |
| 199 | + * |
| 200 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateQueryInfo.html |
| 201 | + * 请求地址:POST https://api.weixin.qq.com/tcb/databasemigratequeryinfo?access_token=ACCESS_TOKEN |
| 202 | + * </pre> |
| 203 | + * |
| 204 | + * @param env 云环境ID |
| 205 | + * @param jobId 迁移任务ID |
| 206 | + * @return . |
| 207 | + * @throws WxErrorException . |
| 208 | + */ |
| 209 | + WxCloudCloudDatabaseMigrateQueryInfoResult databaseMigrateQueryInfo(String env, Long jobId) throws WxErrorException; |
| 210 | + |
| 211 | + /** |
| 212 | + * <pre> |
| 213 | + * 获取文件上传链接 |
| 214 | + * |
| 215 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/uploadFile.html |
| 216 | + * 请求地址:POST https://api.weixin.qq.com/tcb/uploadfile?access_token=ACCESS_TOKEN |
| 217 | + * |
| 218 | + * </pre> |
| 219 | + * |
| 220 | + * @param env 云环境ID |
| 221 | + * @param path 上传路径 |
| 222 | + * @return 上传结果 |
| 223 | + * @throws WxErrorException . |
| 224 | + */ |
| 225 | + WxCloudUploadFileResult uploadFile(String env, String path) throws WxErrorException; |
| 226 | + |
| 227 | + /** |
| 228 | + * <pre> |
| 229 | + * 获取文件下载链接 |
| 230 | + * |
| 231 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/batchDownloadFile.html |
| 232 | + * 请求地址:POST https://api.weixin.qq.com/tcb/batchdownloadfile?access_token=ACCESS_TOKEN |
| 233 | + * |
| 234 | + * </pre> |
| 235 | + * |
| 236 | + * @param env 云环境ID |
| 237 | + * @param fileIds 文件ID列表 |
| 238 | + * @param maxAges 下载链接有效期列表,对应文件id列表 |
| 239 | + * @return 下载链接信息 |
| 240 | + * @throws WxErrorException . |
| 241 | + */ |
| 242 | + WxCloudBatchDownloadFileResult batchDownloadFile(String env, String[] fileIds, long[] maxAges) throws WxErrorException; |
| 243 | + |
| 244 | + /** |
| 245 | + * <pre> |
| 246 | + * 删除文件 |
| 247 | + * |
| 248 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/batchDeleteFile.html |
| 249 | + * 请求地址:POST https://api.weixin.qq.com/tcb/batchdeletefile?access_token=ACCESS_TOKEN |
| 250 | + * |
| 251 | + * </pre> |
| 252 | + * |
| 253 | + * @param env 云环境ID |
| 254 | + * @param fileIds 文件ID列表 |
| 255 | + * @return 下载链接信息 |
| 256 | + * @throws WxErrorException . |
| 257 | + */ |
| 258 | + WxCloudBatchDeleteFileResult batchDeleteFile(String env, String[] fileIds) throws WxErrorException; |
| 259 | + |
| 260 | + /** |
| 261 | + * <pre> |
| 262 | + * 获取腾讯云API调用凭证 |
| 263 | + * |
| 264 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/utils/getQcloudToken.html |
| 265 | + * 请求地址:POST https://api.weixin.qq.com/tcb/getqcloudtoken?access_token=ACCESS_TOKEN |
| 266 | + * </pre> |
| 267 | + * |
| 268 | + * @param lifeSpan 有效期(单位为秒,最大7200) |
| 269 | + * @return . |
| 270 | + * @throws WxErrorException . |
| 271 | + */ |
| 272 | + WxCloudGetQcloudTokenResult getQcloudToken(long lifeSpan) throws WxErrorException; |
| 273 | + |
| 274 | + /** |
| 275 | + * <pre> |
| 276 | + * 新增集合 |
| 277 | + * |
| 278 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionAdd.html |
| 279 | + * 请求地址:POST https://api.weixin.qq.com/tcb/databasecollectionadd?access_token=ACCESS_TOKEN |
| 280 | + * </pre> |
| 281 | + * |
| 282 | + * @param env 云环境ID |
| 283 | + * @param collectionName 集合名称 |
| 284 | + * @throws WxErrorException . |
| 285 | + */ |
| 286 | + void databaseCollectionAdd(String env, String collectionName) throws WxErrorException; |
| 287 | + |
| 288 | + /** |
| 289 | + * <pre> |
| 290 | + * 删除集合 |
| 291 | + * |
| 292 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionDelete.html |
| 293 | + * 请求地址:POST https://api.weixin.qq.com/tcb/databasecollectionadd?access_token=ACCESS_TOKEN |
| 294 | + * </pre> |
| 295 | + * |
| 296 | + * @param env 云环境ID |
| 297 | + * @param collectionName 集合名称 |
| 298 | + * @throws WxErrorException . |
| 299 | + */ |
| 300 | + void databaseCollectionDelete(String env, String collectionName) throws WxErrorException; |
| 301 | + |
| 302 | + /** |
| 303 | + * <pre> |
| 304 | + * 获取特定云环境下集合信息 |
| 305 | + * |
| 306 | + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionGet.html |
| 307 | + * 请求地址:POST https://api.weixin.qq.com/tcb/databasecollectionget?access_token=ACCESS_TOKEN |
| 308 | + * </pre> |
| 309 | + * |
| 310 | + * @param env 云环境ID |
| 311 | + * @param limit 获取数量限制,默认值:10 |
| 312 | + * @param offset 偏移量,默认值:0 |
| 313 | + * @return . |
| 314 | + * @throws WxErrorException . |
| 315 | + */ |
| 316 | + WxCloudDatabaseCollectionGetResult databaseCollectionGet(String env, Long limit, Long offset) throws WxErrorException; |
| 317 | +} |
0 commit comments