| | |
| | | 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") |
| | |
| | | @GetMapping("/addressBook") |
| | | public CommonResult<List<AddressBookVO>> getAddressBook() { |
| | | AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
| | | |
| | | return CommonResult.success(dingService.getAddressBook(user.getUserId())); |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | |
| | | } |