Ver código fonte

Merge branch 'dev' of yeshijie/wlyy2.0 into dev

叶仕杰 3 anos atrás
pai
commit
bc7c2d0bc1

+ 73 - 0
common/common-util/src/main/java/com/yihu/jw/util/tencent/TencentVODUtil.java

@ -0,0 +1,73 @@
package com.yihu.jw.util.tencent;
import sun.misc.BASE64Encoder;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.util.Random;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yeshijie
 * @Date: 2021/5/18
 * @Description: 腾讯视频云存储工具类
 */
public class TencentVODUtil {
    private String secretId;
    private String secretKey;
    //签名算法
    private static final String HMAC_ALGORITHM = "HmacSHA1";
    private static final String CONTENT_CHARSET = "UTF-8";
    public static byte[] byteMerger(byte[] byte1, byte[] byte2) {
        byte[] byte3 = new byte[byte1.length + byte2.length];
        System.arraycopy(byte1, 0, byte3, 0, byte1.length);
        System.arraycopy(byte2, 0, byte3, byte1.length, byte2.length);
        return byte3;
    }
    // 获取签名
    public String getUploadSignature() throws Exception {
        String strSign = "";
        String contextStr = "";
        // 生成原始参数字符串
        long currentTime = System.currentTimeMillis() / 1000;
        int random = new Random().nextInt(Integer.MAX_VALUE);
        // 签名有效期:30 分钟
        int signValidDuration = 1800;
        long endTime = (currentTime + signValidDuration);
        contextStr += "secretId=" + java.net.URLEncoder.encode(secretId, "utf8");
        contextStr += "&currentTimeStamp=" + currentTime;
        contextStr += "&expireTime=" + endTime;
        contextStr += "&random=" + random;
        try {
            Mac mac = Mac.getInstance(HMAC_ALGORITHM);
            SecretKeySpec secretKey = new SecretKeySpec(this.secretKey.getBytes(CONTENT_CHARSET), mac.getAlgorithm());
            mac.init(secretKey);
            byte[] hash = mac.doFinal(contextStr.getBytes(CONTENT_CHARSET));
            byte[] sigBuf = byteMerger(hash, contextStr.getBytes("utf8"));
            strSign = base64Encode(sigBuf);
            strSign = strSign.replace(" ", "").replace("\n", "").replace("\r", "");
        } catch (Exception e) {
            throw e;
        }
        return strSign;
    }
    private String base64Encode(byte[] buffer) {
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(buffer);
    }
    public void setSecretId(String secretId) {
        this.secretId = secretId;
    }
    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }
}

+ 16 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/course/CourseEndpoint.java

@ -8,11 +8,13 @@ import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.util.tencent.TencentVODUtil;
import com.yihu.jw.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@ -36,6 +38,11 @@ public class CourseEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    @Value("${tencent.secretId}")
    private String secretId;
    @Value("${tencent.secretKey}")
    private String secretKey;
    @PostMapping(value = "create")
    @ApiOperation(value = "创建")
    public ObjEnvelop<CourseDO> create (
@ -121,4 +128,13 @@ public class CourseEndpoint extends EnvelopRestEndpoint {
            @RequestParam(value = "orgCode", required = false) String orgCode) throws Exception {
        return success(courseService.findDoctorByOrg(orgCode));
    }
    @GetMapping(value = "getTXUploadSignature")
    @ApiOperation(value = "获取腾讯视频上传签名")
    public Envelop getTXUploadSignature() throws Exception {
        TencentVODUtil tencentVODUtil = new TencentVODUtil();
        tencentVODUtil.setSecretId(secretId);
        tencentVODUtil.setSecretKey(secretKey);
        return success(tencentVODUtil.getUploadSignature());
    }
}

+ 10 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/dict/BusinessSysDictEndpoint.java

@ -1,5 +1,6 @@
package com.yihu.jw.base.endpoint.dict;
import com.yihu.jw.base.dao.dict.BusinessSysDictDao;
import com.yihu.jw.base.service.dict.BusinessSysDictService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
@ -27,6 +28,8 @@ public class BusinessSysDictEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private BusinessSysDictService businessSysDictService;
    @Autowired
    private BusinessSysDictDao businessSysDictDao;
    @ApiOperation("查询字典")
    @GetMapping(value= "findDict")
@ -96,4 +99,11 @@ public class BusinessSysDictEndpoint extends EnvelopRestEndpoint {
        return businessSysDictService.deleteByModelName(preDictName);
    }
    @ApiOperation("查单条")
    @GetMapping(value= "findOneDict")
    public Envelop findOneDict(@ApiParam(name = "id", value = "id", required = true)
                               @RequestParam(value = "id", required = true)String id) throws Exception{
        return success(businessSysDictDao.findOne(id));
    }
}

+ 5 - 0
svr/svr-base/src/main/resources/application.yml

@ -75,6 +75,11 @@ fast-dfs:
configDefault: # 默认配置
  saasId: xmjkzl_saasId
tencent:
  secretId: AKIDa1C6k7D2astd6JGvKRJvFJ6dsrZ1C5h2
  secretKey: 7xWpsd7KGC3f16vUq0ucARRAcnhKfjX4
---
spring:
  profiles: jwdev