|
| 1 | +package me.chanjar.weixin.cp.api.impl; |
| 2 | + |
| 3 | +import com.google.gson.JsonObject; |
| 4 | +import lombok.NonNull; |
| 5 | +import lombok.RequiredArgsConstructor; |
| 6 | +import lombok.extern.slf4j.Slf4j; |
| 7 | +import me.chanjar.weixin.common.error.WxErrorException; |
| 8 | +import me.chanjar.weixin.cp.api.WxCpOaWeDocService; |
| 9 | +import me.chanjar.weixin.cp.api.WxCpService; |
| 10 | +import me.chanjar.weixin.cp.bean.WxCpBaseResp; |
| 11 | +import me.chanjar.weixin.cp.bean.oa.doc.*; |
| 12 | + |
| 13 | +import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*; |
| 14 | + |
| 15 | +/** |
| 16 | + * 企业微信微盘接口实现类. |
| 17 | + * |
| 18 | + * @author Wang_Wong created on 2022-04-22 |
| 19 | + */ |
| 20 | +@Slf4j |
| 21 | +@RequiredArgsConstructor |
| 22 | +public class WxCpOaWeDocServiceImpl implements WxCpOaWeDocService { |
| 23 | + private final WxCpService cpService; |
| 24 | + |
| 25 | + @Override |
| 26 | + public WxCpDocCreateData docCreate(@NonNull WxCpDocCreateRequest request) throws WxErrorException { |
| 27 | + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_CREATE_DOC); |
| 28 | + String responseContent = this.cpService.post(apiUrl, request.toJson()); |
| 29 | + return WxCpDocCreateData.fromJson(responseContent); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public WxCpBaseResp docRename(@NonNull WxCpDocRenameRequest request) throws WxErrorException { |
| 34 | + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_RENAME_DOC); |
| 35 | + String responseContent = this.cpService.post(apiUrl, request.toJson()); |
| 36 | + return WxCpBaseResp.fromJson(responseContent); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public WxCpBaseResp docDelete(String docId, String formId) throws WxErrorException { |
| 41 | + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_DEL_DOC); |
| 42 | + JsonObject jsonObject = new JsonObject(); |
| 43 | + jsonObject.addProperty("docid", docId); |
| 44 | + jsonObject.addProperty("formid", formId); |
| 45 | + String responseContent = this.cpService.post(apiUrl, jsonObject.toString()); |
| 46 | + return WxCpBaseResp.fromJson(responseContent); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public WxCpDocInfo docInfo(@NonNull String docId) throws WxErrorException { |
| 51 | + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_GET_DOC_BASE_INFO); |
| 52 | + JsonObject jsonObject = new JsonObject(); |
| 53 | + jsonObject.addProperty("docid", docId); |
| 54 | + String responseContent = this.cpService.post(apiUrl, jsonObject.toString()); |
| 55 | + return WxCpDocInfo.fromJson(responseContent); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public WxCpDocShare docShare(@NonNull String docId) throws WxErrorException { |
| 60 | + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_DOC_SHARE); |
| 61 | + JsonObject jsonObject = new JsonObject(); |
| 62 | + jsonObject.addProperty("docid", docId); |
| 63 | + String responseContent = this.cpService.post(apiUrl, jsonObject.toString()); |
| 64 | + return WxCpDocShare.fromJson(responseContent); |
| 65 | + } |
| 66 | +} |
0 commit comments