xushengqiang 5 年 前
コミット
c4cb8b6c47

+ 21 - 1
src/main/java/cn/efunbox/audio/impl/hag/HagContentServiceImpl.java

@@ -6,14 +6,17 @@ import cn.efunbox.audio.repository.hag.HagAlbumRepository;
 import cn.efunbox.audio.repository.hag.HagContentRepository;
 import cn.efunbox.audio.service.hag.HagContentService;
 import cn.efunbox.audio.utils.DateUtil;
+import cn.efunbox.audio.utils.MD5;
 import cn.efunbox.audio.vo.hag.*;
 import com.alibaba.fastjson.JSON;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 /**
@@ -24,11 +27,18 @@ import java.util.*;
 @Service
 public class HagContentServiceImpl implements HagContentService {
 
+    @Value("${hag.oss.audio.prefix}")
+    private String hagAudioPrefix;
+
+    @Value("${hag.cdn.secret.sign.key}")
+    private String cdnSecret;
+
     @Autowired
     private HagContentRepository hagContentRepository;
     @Autowired
     private HagAlbumRepository hagAlbumRepository;
 
+
     @Override
     public HagBaseResp list(HagContentReq hagContentReq) {
 
@@ -167,7 +177,7 @@ public class HagContentServiceImpl implements HagContentService {
         command.setNamespace("AudioPlayer");
         command.setName("Play");
         AudioUrl audioUrl = new AudioUrl();
-        audioUrl.setUrl(url);
+        audioUrl.setUrl(hagAudioPrefix + md5PlayUrl(cdnSecret, url));
         Map<String,List<AudioUrl>> map = new HashMap<>();
         map.put("audioItemList",Arrays.asList(audioUrl));
         command.setBody(map);
@@ -175,4 +185,14 @@ public class HagContentServiceImpl implements HagContentService {
         hagSkillResp.setReply(reply);
         return hagSkillResp;
     }
+
+
+    private String md5PlayUrl(String key, String url){
+        SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMddHHmm");
+        long endTime = System.currentTimeMillis() + (3 * 60 * 1000L);
+        Date date = new Date(endTime);
+        String time = sdf.format(date);
+        String md5Url = MD5.MD5Encode(key + time + url);
+        return "/" + time + "/" + md5Url + url;
+    }
 }

+ 1 - 5
src/main/java/cn/efunbox/audio/impl/hag/HagProductServiceImpl.java

@@ -5,8 +5,6 @@ import cn.efunbox.audio.repository.hag.HagProductRepository;
 import cn.efunbox.audio.service.hag.HagProductService;
 import cn.efunbox.audio.utils.DateUtil;
 import cn.efunbox.audio.vo.hag.*;
-import com.alibaba.fastjson.JSON;
-import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
@@ -20,7 +18,6 @@ import java.util.Objects;
  * HagProductServiceImpl
  * Created by xusq on 2019/12/25.
  */
-@Slf4j
 @Service
 public class HagProductServiceImpl implements HagProductService {
 
@@ -29,7 +26,7 @@ public class HagProductServiceImpl implements HagProductService {
 
     @Override
     public HagProductResp list(HagProductReq productReq) {
-        log.info("hag request product data param : {}", JSON.toJSONString(productReq));
+
         Pagination paginationReq = productReq.getPagination();
         Integer limit = paginationReq.getLimit();
         if (Objects.isNull(limit)) {
@@ -73,7 +70,6 @@ public class HagProductServiceImpl implements HagProductService {
 
         hagProducts.forEach(product -> albumIds.add(product.getAlbumId()));
 
-
         List<ProductVO> productVOList = new ArrayList<>();
 
         if (!CollectionUtils.isEmpty(hagProducts)) {

+ 92 - 0
src/main/java/cn/efunbox/audio/utils/MD5.java

@@ -0,0 +1,92 @@
+package cn.efunbox.audio.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class MD5 {
+	public MD5() {
+	}
+
+	public static final String byte2hexString(byte[] bytes) {
+		StringBuffer buf = new StringBuffer(bytes.length * 2);
+		for (int i = 0; i < bytes.length; i++) {
+			if (((int) bytes[i] & 0xff) < 0x10) {
+				buf.append("0");
+			}
+			buf.append(Long.toString((int) bytes[i] & 0xff, 16));
+		}
+		return buf.toString();
+	}
+
+	/**
+	 * md5加密
+	 * @param sourceString
+	 * @return
+	 */
+	public static String MD5Encode(String sourceString) {
+		String resultString = null;
+		try {
+			resultString = new String(sourceString);
+			MessageDigest md = MessageDigest.getInstance("MD5");
+			resultString = byte2hexString(md.digest(resultString.getBytes()));
+		} catch (Exception ex) {
+		}
+		return resultString;
+	}
+	
+	 public static String getMD5Str(String str) {  
+	        MessageDigest messageDigest = null;  
+	  
+	        try {  
+	            messageDigest = MessageDigest.getInstance("MD5");  
+	  
+	            messageDigest.reset();  
+	  
+	            messageDigest.update(str.getBytes("UTF-8"));  
+	        } catch (NoSuchAlgorithmException e) {  
+	            System.out.println("NoSuchAlgorithmException caught!");  
+	            System.exit(-1);  
+	        } catch (UnsupportedEncodingException e) {  
+	            e.printStackTrace();  
+	        }  
+	  
+	        byte[] byteArray = messageDigest.digest();  
+	  
+	        StringBuffer md5StrBuff = new StringBuffer();  
+	  
+	        for (int i = 0; i < byteArray.length; i++) {              
+	            if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)  
+	                md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));  
+	            else  
+	                md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));  
+	        }  
+	  
+	        return md5StrBuff.toString();  
+	    }
+
+	public static void main(String[] args) throws UnsupportedEncodingException {
+
+
+
+	  /*  String data = "eyJ0aW1lIjoxNTMwODQ1MTI1LCJtc2dfaWQiOiI2MWJiYzExMTI2NWY0NmM4OTg3OWM2NWQxYmZkZGY1OSIsImVycl9jb2RlIjoiMjAwIiwiZXJyX21zZyI6Ik9LIn0=";
+	    String sign = "VB5Ybhu8MBmTMtyzP2J/rMmbmXy87lCkOA7RCDcQE+47IwG+xL5Tx8PYU+1sRBdpK6I65AaYev434fb1+w3kzcMUI0NOjHMnxNGZtDgEMKMQWpoi9njqDpCcXmrO2dDkON0ysF0MN1mD7kg9yz0oFQ4mp3ues/Uk+NzAXU29cbk=";
+
+	    String publicKey  = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7BTRi35TsWf8lbsR0z5wpKrHx8CsveKvUk51G2bPlPV9XA9JXcMCGmN6YqihoAwMhXnda4FO78KqBpMja6QqucqQjmbJ+quGc11D7yL1+4+l4CZ8ChPXNvl/R2kZPDQhDg5YiTddL8TBSWSvGbQSTFOfIZZllKKct3InCzBG5HQIDAQAB";
+
+        boolean b = RSASignature.verifySignByPublicKey(data, sign, publicKey, false);
+        System.out.println(b);
+
+        String jsonData = new String(Base64.decodeBase64(data), "utf-8");
+        NotifyResponse msgData = JsonBinder.buildNonNullBinder().fromJson(jsonData, NotifyResponse.class);
+        System.out.println(JSON.toJSONString(msgData));
+
+        String s = JsonBinder.buildNonNullBinder().toJson(msgData);
+        System.out.println(s);*/
+
+		String md5Encode = MD5Encode("123456");
+		System.out.println(md5Encode);
+
+	}
+
+}

+ 5 - 1
src/main/resources/application-dev.properties

@@ -67,4 +67,8 @@ aliyun.oss.file.prefix=audio/album/
 efunbox.oss.img.url=https://ai-admin-image.ai160.com
 
 #interface.sign.key=IhOTiTyMLDNNLFuP
-interface.sign.key=AzaSB2RR0boUz1WQ
+interface.sign.key=AzaSB2RR0boUz1WQ
+
+hag.cdn.secret.sign.key=7q28cAwmcGQgOsCj
+hag.oss.audio.prefix=http://ai-hag-audio.ai160.com
+

+ 6 - 1
src/main/resources/application-prd.properties

@@ -66,4 +66,9 @@ ali.oss.accessKeySecret=YEm1VebbntRIGmV8s8N33LQfOoC2sA
 aliyun.oss.file.prefix=audio/album/
 efunbox.oss.img.url=https://ai-admin-image.ai160.com
 
-interface.sign.key=IhOTiTyMLDNNLFuP
+interface.sign.key=IhOTiTyMLDNNLFuP
+
+
+hag.cdn.secret.sign.key=7q28cAwmcGQgOsCj
+hag.oss.audio.prefix=http://ai-hag-audio.ai160.com
+