import Wechat from './wechat'; import WechatSDK from 'oak-external-sdk/lib/WechatSDK'; import { assert } from 'oak-domain/lib/utils/assert'; import { OakPreConditionUnsetException } from 'oak-domain/lib/types'; export default class WechatBackend extends Wechat { getConfigAndInstance(application) { const { config, type } = this.getConfig(application); return { config, type, }; } async composeFileUrlBackend(options) { const { application, extraFile, context, style } = options; return ''; } async formUploadMeta(application, extraFile) { // 微信上传素材库 } async checkWhetherSuccess(application, extraFile) { const { extra1 } = extraFile; return !!extra1; } async removeFile(application, extraFile) { const { extra2, extra1: mediaId } = extraFile; const isPermanent = extra2?.isPermanent || false; const { config, type } = this.getConfigAndInstance(application); // 只有永久素材 才能删除素材 if (isPermanent) { assert(mediaId); const { appId, appSecret } = config; const wechatInstance = WechatSDK.getInstance(appId, type, appSecret); const result = await wechatInstance.deleteMaterial({ mediaId, }); return result; } } async composeChunkUploadInfo(application, extraFile, context) { throw new OakPreConditionUnsetException('微信暂不支持分片上传'); return { uploadId: '', chunkSize: 0, partSize: 0, partCount: 0, parts: [], }; } /** * 完成分片上传后的合并操作 */ async mergeChunkedUpload(application, extraFile, context) { // Implementation here } async abortMultipartUpload(application, extraFile, context) { } async listMultipartUploads(application, extraFile, context) { return { parts: [], }; } } ;