| | |
| | | import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient; |
| | | import com.alibaba.xxpt.gateway.shared.client.http.GetClient; |
| | | import com.alibaba.xxpt.gateway.shared.client.http.PostClient; |
| | | import com.aliyun.oss.OSS; |
| | | import com.aliyun.oss.OSSClientBuilder; |
| | | import com.aliyun.oss.model.ObjectMetadata; |
| | | import com.ycl.api.CommonResult; |
| | | import com.ycl.bo.AdminUserDetails; |
| | | import com.ycl.common.dingding.DingCommon; |
| | |
| | | import com.ycl.service.auth.AuthService; |
| | | import com.ycl.service.ding.BookRemarkService; |
| | | import com.ycl.service.ding.DingService; |
| | | import com.ycl.utils.ConstantPropertiesUtils; |
| | | import com.ycl.vo.AddressBookVO; |
| | | import com.ycl.vo.NewAddressBookVO; |
| | | import io.swagger.annotations.Api; |
| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.io.*; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | @Resource |
| | | private DingConfig dingConfig; |
| | | |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "根据钉钉授权码获取token") |
| | |
| | | return CommonResult.success(bookRemarkService.updateRemark(user, userId, remark)); |
| | | } |
| | | |
| | | private String getVideo(String accToken) { |
| | | private String getVideo(String MediaId,MultipartFile file) { |
| | | CloseableHttpResponse response = null; |
| | | //调用API |
| | | GetClient getClient = executableClient.newGetClient(GET_VIDEO); |
| | | String token =getToken(); |
| | | //设置参数 |
| | | try { |
| | | if (ObjectUtil.isNotNull(accToken)) { |
| | | getClient.addParameter("accessToken", accToken); |
| | | getClient.addParameter("mediaId", dingConfig.getMediaId()); |
| | | if (ObjectUtil.isNotNull(MediaId)) { |
| | | getClient.addParameter("accessToken", token); |
| | | getClient.addParameter("mediaId", MediaId); |
| | | // String result = getClient.get(); |
| | | // return parsingResult(result); |
| | | response = getClient.getB(); |
| | |
| | | fos.flush(); |
| | | fos.close(); |
| | | } |
| | | } catch (Exception e) { |
| | | if (file == null) { |
| | | return "上传视频为空"; |
| | | } |
| | | String endpoint = ConstantPropertiesUtils.END_POINT; |
| | | String accessKeyId = ConstantPropertiesUtils.ACCESS_KEY_ID; |
| | | String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET; |
| | | String bucketName = ConstantPropertiesUtils.BUCKET_NAME; |
| | | |
| | | // 创建OSSClient实例 |
| | | OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); |
| | | // 获取文件的名称 |
| | | String fileName = "sczf/" + file.getOriginalFilename(); |
| | | ObjectMetadata objectMetadata = new ObjectMetadata(); |
| | | objectMetadata.setContentType(getcontentType(fileName.substring(fileName.lastIndexOf(".")))); |
| | | // 调用oss的方法实现长传 |
| | | // 第一个参数 bucketName |
| | | // 第二个参数 上传到oss的文件路径和文件名称 |
| | | ossClient.putObject(bucketName, fileName, new ByteArrayInputStream(file.getBytes()), objectMetadata); |
| | | // 关闭OSSClient。 |
| | | ossClient.shutdown(); |
| | | // 把上传的文件路径返回 (手动拼接) |
| | | // 这里设置图片有效时间 我设置了30年 |
| | | Date expiration = new Date(System.currentTimeMillis() + (long) 946080000 * 1000); |
| | | String url = ossClient.generatePresignedUrl(bucketName, fileName, expiration).toString(); |
| | | |
| | | return url; |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | if (response != null) { |
| | |
| | | } |
| | | return null; |
| | | } |
| | | public static String getcontentType(String FilenameExtension) { |
| | | if (FilenameExtension.equalsIgnoreCase(".mp4")||FilenameExtension.equalsIgnoreCase(".mov")) { |
| | | return "video/mp4"; |
| | | } |
| | | if (FilenameExtension.equalsIgnoreCase(".bmp")) { |
| | | return "image/bmp"; |
| | | } |
| | | if (FilenameExtension.equalsIgnoreCase(".gif")) { |
| | | return "image/gif"; |
| | | } |
| | | if (FilenameExtension.equalsIgnoreCase(".jpeg") || |
| | | FilenameExtension.equalsIgnoreCase(".jpg") || |
| | | FilenameExtension.equalsIgnoreCase(".png")) { |
| | | return "image/jpg"; |
| | | } |
| | | if (FilenameExtension.equalsIgnoreCase(".html")) { |
| | | return "text/html"; |
| | | } |
| | | if (FilenameExtension.equalsIgnoreCase(".txt")) { |
| | | return "text/plain"; |
| | | } |
| | | if (FilenameExtension.equalsIgnoreCase(".vsd")) { |
| | | return "application/vnd.visio"; |
| | | } |
| | | if (FilenameExtension.equalsIgnoreCase(".pptx") || |
| | | FilenameExtension.equalsIgnoreCase(".ppt")) { |
| | | return "application/vnd.ms-powerpoint"; |
| | | } |
| | | if (FilenameExtension.equalsIgnoreCase(".docx") || |
| | | FilenameExtension.equalsIgnoreCase(".doc")) { |
| | | return "application/msword"; |
| | | } |
| | | if (FilenameExtension.equalsIgnoreCase(".xml")) { |
| | | return "text/xml"; |
| | | } |
| | | return "image/jpg"; |
| | | } |
| | | |
| | | |
| | | |