import { assert } from 'oak-domain/lib/utils/assert'; import { OakUploadException } from '../../types/Exception'; import { OakNetworkException } from 'oak-domain/lib/types/Exception'; export default class Wechat { name = 'wechat'; autoInform() { return false; } getConfig(application) { assert(application.type === 'wechatPublic'); const config = application.config; return { config: config, type: application.type, }; } async upload(options) { const { extraFile, uploadFn, file, uploadToAspect, getPercent } = options; let result; const { applicationId, type, extra2, id } = extraFile; assert(type === 'image'); try { result = (await uploadToAspect(file, 'file', 'uploadWechatMedia', { applicationId, type, isPermanent: extra2?.isPermanent || false, extraFileId: id, }, true)); } catch (err) { // 网络错误 throw new OakNetworkException('网络异常,请求失败'); } // 解析回调 if (result.mediaId) { return; } else { throw new OakUploadException('文件上传微信失败'); } } composeFileUrl(options) { return ''; } } ;