package org.demo.utils;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

public class demo {

	public static void main(String[] args) {
		String memberKey = "联系视频云获取";
		String deviceid = "需要获取视频地址的设备编号";
		String appkey = "视频云3.0appkey，联系视频云获取";
		String secret = "视频云3.0秘钥，联系视频云获取";
		String apiHost = "http://36.103.241.111:19103/api/dict/";
		JSONObject paramdata = new JSONObject(true);
		paramdata.put("memberkey", memberKey);
		paramdata.put("deviceid", deviceid);
//		paramdata.put("networktype", "1");
		String paramStr = paramdata.toJSONString();
		String sign = StringUtils.upperCase(SecureUtil.md5(secret + "&&" + paramStr));
		String url = apiHost + "media/play?appkey=" + appkey;
		JSONObject body = new JSONObject();
		body.put("parmdata", paramdata);
		body.put("sign", sign);
		String response = HttpRequest.post(url).body(body.toJSONString()).header(Header.CONTENT_TYPE, "application/json").execute().body();
		JSONObject responseData = JSONObject.parseObject(response);
		if(responseData.getString("code").equals("1")){
			JSONObject result = responseData.getJSONObject("result");
			String flvurl = result.getString("flvuri");
			System.out.println("视频播放地址：" + flvurl);
		} else{
			System.out.println("获取设备播放地址失败");
		}
	}
}
