17808
2023-09-13 c99438c64037b06c629e37f1f1acb5ce48a31036
ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
@@ -19,18 +19,23 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.ycl.common.constant.DingConst.GET_TIKER;
import static com.ycl.common.constant.DingConst.GET_TOKEN;
import static com.ycl.common.constant.DingConst.*;
@RestController
@RequestMapping("/ding")
@@ -137,7 +142,6 @@
    @GetMapping("/addressBook")
    public CommonResult<List<AddressBookVO>> getAddressBook() {
        AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return CommonResult.success(dingService.getAddressBook(user.getUserId()));
    }
@@ -165,5 +169,47 @@
        return CommonResult.success(bookRemarkService.updateRemark(user, userId, remark));
    }
    private String getVideo(String accToken) {
        CloseableHttpResponse response = null;
        //调用API
        GetClient getClient = executableClient.newGetClient(GET_VIDEO);
        //设置参数
        try {
            if (ObjectUtil.isNotNull(accToken)) {
            getClient.addParameter("accessToken", accToken);
            getClient.addParameter("mediaId", dingConfig.getMediaId());
//            String result = getClient.get();
//            return parsingResult(result);
            response = getClient.getB();
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            File voice = new File("/Users/video/log1.xlsx");
            OutputStream fos = new FileOutputStream(voice);
            int cache = 10 * 1024;
            byte[] buffer = new byte[cache];
            int ch = 0;
                while ((ch = is.read(buffer)) != -1) {
                fos.write(buffer, 0, ch);
                }
            is.close();
            fos.flush();
            fos.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (response != null) {
                try {
                    //特别提醒:需要调用response的close方法关闭网络连接!!!
                    response.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}