|
@@ -4,6 +4,7 @@ import com.ym.config.IMProperties;
|
|
|
import com.ym.utils.CodeUtil;
|
|
|
import io.rong.util.GsonUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
@@ -252,4 +253,45 @@ public class HttpHelper {
|
|
|
conn.setReadTimeout(30000);
|
|
|
conn.setRequestProperty("Content-Type", contentType);
|
|
|
}
|
|
|
+
|
|
|
+ public HttpURLConnection createIMRtcPostHttpConnection(String uri, String contentType,String roomId)
|
|
|
+ throws IOException{
|
|
|
+ return createCommonRtcPostHttpConnection(imProperties.getRtcHost(),
|
|
|
+ imProperties.getAppKey(), imProperties.getSecret(), uri,
|
|
|
+ contentType,roomId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public HttpURLConnection createCommonRtcPostHttpConnection(String host, String appKey,
|
|
|
+ String appSecret, String uri, String contentType,String roomId)
|
|
|
+ throws IOException{
|
|
|
+ String nonce = String.valueOf(Math.random() * 1000000);
|
|
|
+ String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
|
|
+ StringBuilder toSign = new StringBuilder(appSecret).append(nonce).append(timestamp);
|
|
|
+ String sign = CodeUtil.hexSHA1(toSign.toString());
|
|
|
+ uri = host + uri;
|
|
|
+ URL url = new URL(uri);
|
|
|
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
|
+ if (conn == null) {
|
|
|
+ log.info("open url connectin fail, url={}", uri);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ conn.setUseCaches(false);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setRequestMethod("POST");
|
|
|
+ conn.setInstanceFollowRedirects(true);
|
|
|
+ conn.setConnectTimeout(30000);
|
|
|
+ conn.setReadTimeout(30000);
|
|
|
+
|
|
|
+ conn.setRequestProperty("App-Key", appKey);
|
|
|
+ conn.setRequestProperty("Nonce", nonce);
|
|
|
+ conn.setRequestProperty("Timestamp", timestamp);
|
|
|
+ conn.setRequestProperty("Signature", sign);
|
|
|
+ if(StringUtils.isNotEmpty(roomId)){
|
|
|
+ conn.setRequestProperty("Room-Id", roomId);
|
|
|
+ }
|
|
|
+ conn.setRequestProperty("Content-Type", contentType);
|
|
|
+ return conn;
|
|
|
+ }
|
|
|
}
|