Commit 0a84a9bad6fbebe6ee3e5d0ec59ba82f282dd6bb
1 parent
05930da1
add
Showing
2 changed files
with
301 additions
and
0 deletions
00.公共组件/1.1 SHA1签名.md
0 → 100644
| 1 | +/* | |
| 2 | +Title: SHA1签名 | |
| 3 | +*/ | |
| 4 | + | |
| 5 | + | |
| 6 | +### 系统参数说明 ### | |
| 7 | + | |
| 8 | +|名称 |类型 |必选 |描述| | |
| 9 | +| :----------- | :------: | :------: | :------: | | |
| 10 | +|sp_id |string |Y |入驻服务开发者(SP)的应用唯一标识码,由开放平台统一分配并提供(一个SP可自行创建多个应用号)| | |
| 11 | +|timestamp |int |Y |当前Unix时间戳,请保证请求服务器时间正确,有些API接口是有时效性要求的| | |
| 12 | +|ver |string |Y |协议版本号,统一取值为1.0| | |
| 13 | +|sign |string |Y |验证码,生成规则详见下面的说明,其中sp_key是由开放平台统一分配并提供的SP私钥| | |
| 14 | + | |
| 15 | + | |
| 16 | +### 签名描述 ### | |
| 17 | + | |
| 18 | +签名机制 | |
| 19 | +SHA1 加密 | |
| 20 | + | |
| 21 | +1. 对所有传入参数(含系统参数和接口参数)按照字段名的 ASCII 码从小到大排序(字典序)后,使用 URL 键值 对的格式。 | |
| 22 | + (即 key1=value1&key2=value2…)拼接成字符串 string1, | |
| 23 | + 注意:值为空的参数不参与签名,所有请求参数值都需要进行URL编码。 | |
| 24 | +2. 在 string1 最 后 拼 接 上 key=sp_key得 到 stringSignTemp 字 符 串 , 并 对 stringSignTemp 进行 sha1 运算,再将得到的字符串所有字符转换为大写, | |
| 25 | + 得到 sign 值 signValue。 | |
| 26 | +3. 对传入参数中所有键值对的 value 进行 urlencode 转码后重新拼接成字符串 string2。 | |
| 27 | +4. 将 sign=signValue拼接到string2后面得到最终的 参数 字符串。 | |
| 28 | + | |
| 29 | + | |
| 30 | +#### Java代码示例 | |
| 31 | + | |
| 32 | +```java | |
| 33 | + | |
| 34 | + //生成get 方式 带签名的请求URL | |
| 35 | + public static void main(String[] args) { | |
| 36 | + String sp_key = "xxxxxxxxxxx"; //开发者帐号对应的key. 请开发者谨慎保管此值。 | |
| 37 | + Map<String, String> map = new HashMap<String,String>(); | |
| 38 | + | |
| 39 | + map.put("sp_id","xxxxxxxxxx"); //开发者帐号对应的10位ID ,所有接口参数都必须有此参数。 | |
| 40 | + map.put("param1_keyname", "Parm1_vaule"); //接口需要的参数1 | |
| 41 | + map.put("param2_keyname", "Parm2_vaule"); //接口需要的参数2 。。。 等等 | |
| 42 | + | |
| 43 | + String getUrl = buildURL("http://api.cnlive.com/open/api/xxxxxxx",map, sp_key); | |
| 44 | + System.out.println(getUrl); | |
| 45 | + } | |
| 46 | + | |
| 47 | + //生成post方式的请求参数签名 | |
| 48 | + public static void main(String[] args) { | |
| 49 | + String sp_key = "xxxxxxxxxxx"; //开发者帐号对应的key. 请开发者谨慎保管此值。 | |
| 50 | + Map<String, String> map = new HashMap<String,String>(); | |
| 51 | + | |
| 52 | + map.put("sp_id","xxxxxxxxxx"); //开发者帐号对应的10位ID ,所有接口参数都必须有此参数。 | |
| 53 | + map.put("param1_keyname", "Parm1_vaule"); //接口需要的参数1 | |
| 54 | + map.put("param2_keyname", "Parm2_vaule"); //接口需要的参数2 。。。 等等 | |
| 55 | + | |
| 56 | + String post_param_signed = sign(map, sp_key); | |
| 57 | + System.out.println(post_param_signed); | |
| 58 | + } | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * 生成URL | |
| 62 | + * @param url | |
| 63 | + * @param params | |
| 64 | + * @param sp_key | |
| 65 | + * @return | |
| 66 | + */ | |
| 67 | + public static String buildURL(String url,Map<String,String> params,String sp_key){ | |
| 68 | + Map<String,String> map = order(params); | |
| 69 | + if(map.containsKey("sign")){ | |
| 70 | + map.remove("sign"); | |
| 71 | + } | |
| 72 | + String str = mapJoin(map,true,false); | |
| 73 | + String sign = SHA1.SHA1Digest(str+"&key="+sp_key).toUpperCase(); | |
| 74 | + map.put("sign", sign); | |
| 75 | + return url+"?"+mapJoin(map, false, true); | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * Map key 排序 | |
| 80 | + * @param map | |
| 81 | + * @return | |
| 82 | + */ | |
| 83 | + private static Map<String,String> order(Map<String, String> map){ | |
| 84 | + HashMap<String, String> tempMap = new LinkedHashMap<String, String>(); | |
| 85 | + List<Entry<String, String>> infoIds = new ArrayList<Entry<String, String>>( map.entrySet()); | |
| 86 | + | |
| 87 | + Collections.sort(infoIds, new Comparator<Entry<String, String>>() { | |
| 88 | + public int compare(Entry<String, String> o1,Entry<String, String> o2) { | |
| 89 | + return (o1.getKey()).toString().compareTo(o2.getKey()); | |
| 90 | + } | |
| 91 | + }); | |
| 92 | + | |
| 93 | + for (int i = 0; i < infoIds.size(); i++) { | |
| 94 | + Entry<String, String> item = infoIds.get(i); | |
| 95 | + tempMap.put(item.getKey(), item.getValue()); | |
| 96 | + } | |
| 97 | + return tempMap; | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * url 参数串连 | |
| 102 | + * @param map | |
| 103 | + * @param keyLower | |
| 104 | + * @param valueUrlencode | |
| 105 | + * @return | |
| 106 | + */ | |
| 107 | + private static String mapJoin(Map<String, String> map,boolean keyLower,boolean valueUrlencode){ | |
| 108 | + StringBuilder stringBuilder = new StringBuilder(); | |
| 109 | + for(String key :map.keySet()){ | |
| 110 | + if(map.get(key)!=null&&!"".equals(map.get(key))){ | |
| 111 | + try { | |
| 112 | + stringBuilder.append(key) | |
| 113 | + .append("=") | |
| 114 | + .append(valueUrlencode?URLEncoder.encode(map.get(key),"utf-8").replace("+", "%20"):map.get(key)) | |
| 115 | + .append("&"); | |
| 116 | + } catch (UnsupportedEncodingException e) { | |
| 117 | + e.printStackTrace(); | |
| 118 | + } | |
| 119 | + } | |
| 120 | + } | |
| 121 | + if(stringBuilder.length()>0){ | |
| 122 | + stringBuilder.deleteCharAt(stringBuilder.length()-1); | |
| 123 | + } | |
| 124 | + return stringBuilder.toString(); | |
| 125 | + } | |
| 126 | +``` | |
| 0 | 127 | \ No newline at end of file | ... | ... |
01.点播云/内容输出接口.md
0 → 100644
| 1 | +/* | |
| 2 | +Title: 1.1 获取点播信息接口 | |
| 3 | +*/ | |
| 4 | + | |
| 5 | +### 接口描述 ### | |
| 6 | + | |
| 7 | + | |
| 8 | +### 接口地址 ### | |
| 9 | +http://api.cnlive.com/open/api/dianbo/getVodInfo | |
| 10 | + | |
| 11 | +### 接口协议 ### | |
| 12 | +HTTP GET | |
| 13 | + | |
| 14 | +### 接口请求参数 ### | |
| 15 | +- vId:节目唯一标识 | |
| 16 | +- sp_id:应用ID | |
| 17 | +- timestamp:时间戳,精确到秒 | |
| 18 | + | |
| 19 | +### 返回值 ### | |
| 20 | +返回JSON格式的节目元数据信息,json示例如下: | |
| 21 | + | |
| 22 | +``` json | |
| 23 | +{ | |
| 24 | + "message":"请求成功", | |
| 25 | + "data":{ | |
| 26 | + "MAM_VideoUrl":"http://wideo03.cnlive.com/video/data1/2016/0725/137519/800/419c46d67fb34b46adbd8b7de450a0f2_137519_800.m3u8", | |
| 27 | + "MAM_VideoEditor":"许真真", | |
| 28 | + "weight":"80", | |
| 29 | + "MAM_VideoUHUrl":"", | |
| 30 | + "pageUrl":"http://www.cnlive.com/fengcaidasai/v_gy2tmmrxgy.html", | |
| 31 | + "MAM_VideoLUrl":"http://wideo03.cnlive.com/video/data1/2016/0725/137519/400/419c46d67fb34b46adbd8b7de450a0f2_137519_400.m3u8", | |
| 32 | + "vipFlag":"0", | |
| 33 | + "CMSChannelName":"华语风采大赛", | |
| 34 | + "type":"program", | |
| 35 | + "packagePomID":"3_fengcaidasai/dianfengduijue/", | |
| 36 | + "MAM_BigPostUrl":"http://y3.cnliveimg.com:8080/image/itv/2016/0725/419c46d67fb34b46adbd8b7de450a0f2_137519_101.jpg", | |
| 37 | + "cmsChannelID":"fengcaidasai/", | |
| 38 | + "MAM_ProducerID":"先锋派", | |
| 39 | + "activityId":"", | |
| 40 | + "title":"刘子赫孙悟空大闹天宫", | |
| 41 | + "docSubTitle":"刘子赫孙悟空大闹天宫", | |
| 42 | + "MAM_NodeID":"016-020-003", | |
| 43 | + "MAM_TVColumMarkID":"", | |
| 44 | + "playAuto":"xiangguanshipin", | |
| 45 | + "docID":"656276", | |
| 46 | + "onePomID":"3_419c46d67fb34b46adbd8b7de450a0f2", | |
| 47 | + "MAM_SmallPosterUrl":"http://y3.cnliveimg.com:8080/image/itv/2016/0725/419c46d67fb34b46adbd8b7de450a0f2_137519_100.jpg", | |
| 48 | + "CMCCNodeID":"", | |
| 49 | + "MAM_PrgType":"1", | |
| 50 | + "publishDate":"2016-07-25 16:47:32", | |
| 51 | + "mediaId":"419c46d67fb34b46adbd8b7de450a0f2", | |
| 52 | + "MAM_Duration":"293000", | |
| 53 | + "MAM_CPNAME":"魅力快线3", | |
| 54 | + "MAM_NodeName":"大型专题/华语风采大赛/巅峰对决", | |
| 55 | + "vip_product_id":"", | |
| 56 | + "status":"1", | |
| 57 | + "WEB_Copyright":1, | |
| 58 | + "MAM_PosterUrl":"http://y3.cnliveimg.com:8080/image/itv/2016/0725/419c46d67fb34b46adbd8b7de450a0f2_137519_100.jpg", | |
| 59 | + "cmsColumnID":"fengcaidasai/dianfengduijue/", | |
| 60 | + "MAM_CreatDate":"2016-07-25 16:22:45", | |
| 61 | + "APP_Copyright":1, | |
| 62 | + "docBodyContent":"", | |
| 63 | + "MAM_VideoFlashUHUrl":"", | |
| 64 | + "MAM_VideoFlashHUrl":"http://wideo03.cnlive.com/video/data1/2016/0725/137519/1500/419c46d67fb34b46adbd8b7de450a0f2_137519_1500.mp4", | |
| 65 | + "MAM_VideoHUrl":"http://wideo03.cnlive.com/video/data1/2016/0725/137519/1500/419c46d67fb34b46adbd8b7de450a0f2_137519_1500.m3u8", | |
| 66 | + "CMSColumnName":"巅峰对决", | |
| 67 | + "CMCCID":"", | |
| 68 | + "freePlayLength":"60", | |
| 69 | + "MAM_VideoFlashUrl":"http://wideo03.cnlive.com/video/data1/2016/0725/137519/800/419c46d67fb34b46adbd8b7de450a0f2_137519_800.mp4", | |
| 70 | + "docDescription":"刘子赫精彩演绎孙悟空大闹天宫。", | |
| 71 | + "MAM_TVDate":"", | |
| 72 | + "modules":[ | |
| 73 | + { | |
| 74 | + "id":"xiangguanshipin", | |
| 75 | + "title":"相关推荐" | |
| 76 | + } | |
| 77 | + ], | |
| 78 | + "colName":"", | |
| 79 | + "MAM_VideoFlashLUrl":"http://wideo03.cnlive.com/video/data1/2016/0725/137519/400/419c46d67fb34b46adbd8b7de450a0f2_137519_400.mp4" | |
| 80 | + }, | |
| 81 | + "errorCode":"0" | |
| 82 | +} | |
| 83 | +``` | |
| 84 | + | |
| 85 | +JSON属性说明: 四路播放地址至少一个有效 | |
| 86 | + | |
| 87 | +<table style="font-size:14px" > | |
| 88 | + <tr> | |
| 89 | + <td>字段名称</td> | |
| 90 | + <td>描述</td> | |
| 91 | + <td>备注</td> | |
| 92 | + </tr> | |
| 93 | + <tr> | |
| 94 | + <td>errorCode</td> | |
| 95 | + <td>返回码</td> | |
| 96 | + <td>0:成功</td> | |
| 97 | + </tr> | |
| 98 | + <tr> | |
| 99 | + <td>message</td> | |
| 100 | + <td>返回信息</td> | |
| 101 | + <td></td> | |
| 102 | + </tr> | |
| 103 | + <tr> | |
| 104 | + <td>MAM_VideoUrl</td> | |
| 105 | + <td>播放地址</td> | |
| 106 | + <td></td> | |
| 107 | + </tr> | |
| 108 | + <tr> | |
| 109 | + <td>MAM_PosterUrl</td> | |
| 110 | + <td>图片地址</td> | |
| 111 | + <td></td> | |
| 112 | + </tr> | |
| 113 | + <tr> | |
| 114 | + <td>status</td> | |
| 115 | + <td>状态</td> | |
| 116 | + <td>1:已发布;2:下线</td> | |
| 117 | + </tr> | |
| 118 | + <tr> | |
| 119 | + <td>cmsColumnID</td> | |
| 120 | + <td>栏目ID</td> | |
| 121 | + <td></td> | |
| 122 | + </tr> | |
| 123 | + <tr> | |
| 124 | + <td>freePlayLength</td> | |
| 125 | + <td>免费播放时长</td> | |
| 126 | + <td></td> | |
| 127 | + </tr> | |
| 128 | +</table> | |
| 129 | + | |
| 130 | + | |
| 131 | +参数需进行加密,示例: | |
| 132 | + | |
| 133 | +详细签名 http://bj.gitlab.cnlive.com/boss-team/OPEN_API/blob/master/0.%20%E5%85%AC%E5%85%B1%E7%BB%84%E4%BB%B6/1.1%20SHA1%E7%AD%BE%E5%90%8D.md | |
| 134 | + | |
| 135 | +``` java | |
| 136 | +public String getPlayVideo(ModelMap model,HttpServletRequest request) { | |
| 137 | + String result = ""; | |
| 138 | + Map params = new HashMap<>(); | |
| 139 | + params.put("sp_id", "iqhpk8pl19"); | |
| 140 | + params.put("vId", "419c46d67fb34b46adbd8b7de450a0f2"); | |
| 141 | + params.put("timestamp", System.currentTimeMillis()/1000+""); | |
| 142 | + String url = OpenUtil.buildURL("http://api.cnlive.com/open/api/dianbo/getVodInfo", params, "672db30805f848f59ec3728f8347a4a0"); | |
| 143 | + HttpURLConnection connection; | |
| 144 | + try { | |
| 145 | + URL requestUrl = new URL(url); | |
| 146 | + connection = (HttpURLConnection)requestUrl.openConnection(); | |
| 147 | + connection.setRequestMethod("GET"); | |
| 148 | + connection.setDoInput(true); | |
| 149 | + connection.setDoOutput(true); | |
| 150 | + connection.connect();//连接 | |
| 151 | + | |
| 152 | + //获得返回值 | |
| 153 | + if(connection.getResponseCode() == HttpURLConnection.HTTP_OK){ | |
| 154 | + InputStream in = connection.getInputStream(); | |
| 155 | + String currentLine = ""; | |
| 156 | + if(in != null){ | |
| 157 | + BufferedReader br = new BufferedReader(new InputStreamReader(in,"utf-8")); | |
| 158 | + while((currentLine = br.readLine()) != null){ | |
| 159 | + result += currentLine; | |
| 160 | + } | |
| 161 | + br.close(); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + }catch (Exception e) { | |
| 165 | + e.printStackTrace(); | |
| 166 | + } | |
| 167 | + | |
| 168 | + if(BaseUtil.notBlank(result)) { | |
| 169 | + JSONObject resultJson = JSONObject.parseObject(result); | |
| 170 | + model.put("videoInfo", resultJson); | |
| 171 | + } | |
| 172 | + | |
| 173 | + return "play_demo"; | |
| 174 | + } | |
| 175 | +``` | |
| 0 | 176 | \ No newline at end of file | ... | ... |