這篇文章將為大家詳細(xì)講解有關(guān)JAVA 如何對(duì)接騰訊云直播?,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)公司主要從事網(wǎng)頁(yè)設(shè)計(jì)、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、響應(yīng)式網(wǎng)站、程序開(kāi)發(fā)、網(wǎng)站優(yōu)化、微網(wǎng)站、微信小程序開(kāi)發(fā)等,憑借多年來(lái)在互聯(lián)網(wǎng)的打拼,我們?cè)诨ヂ?lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、網(wǎng)站設(shè)計(jì)、網(wǎng)絡(luò)營(yíng)銷(xiāo)經(jīng)驗(yàn),集策劃、開(kāi)發(fā)、設(shè)計(jì)、營(yíng)銷(xiāo)、管理等多方位專(zhuān)業(yè)化運(yùn)作于一體。簽名授權(quán)
public static T TecentDoPostJsonV3(String url,String key,String secretId, TecentPublicParams header, String json, OkHttpClient httpClient, Class clazz) throws Exception { // ************* 步驟 1:拼接規(guī)范請(qǐng)求串 ************* String date = DateUtils.format(new Date(Long.valueOf(header.getX_TC_Timestamp() + "000")),DateUtils.FORMAT_SHORT); String service = url.substring(0,url.indexOf(".")); //截取服務(wù)類(lèi)型 云直播是live System.out.println(json); String canonicalRequest ="POST\n" + "/\n" + "\n" + "content-type:application/json; charset=utf-8\n" + "host:"+url+"\n" + "\n" + "content-type;host\n" + sha256Hex(json); System.out.println(canonicalRequest); // ************* 步驟 2:拼接待簽名字符串 ************* String credentialScope = date+ "/" + service + "/" + "tc3_request"; String hashedCanonicalRequest = sha256Hex(canonicalRequest); String algorithm = "TC3-HMAC-SHA256"; String stringToSign = algorithm + "\n" + header.getX_TC_Timestamp() + "\n" + credentialScope + "\n" + hashedCanonicalRequest; System.out.println(stringToSign); // ************* 步驟 3:計(jì)算簽名 ************* byte[] secretDate = hmac256(("TC3" + key).getBytes(CHARSET), date); byte[] secretService = hmac256(secretDate, service); byte[] secretSigning = hmac256(secretService, "tc3_request"); String signature = DatatypeConverter.printHexBinary(hmac256(secretSigning, stringToSign)).toLowerCase(); System.out.println(signature); // ************* 步驟 4:拼接 Authorization ************* String authorization = algorithm + " " + "Credential=" + secretId + "/" + credentialScope + ", " + "SignedHeaders=" + "content-type;host" + ", " + "Signature=" + signature; System.out.println(authorization); header.setAuthorization(authorization); JSONObject jsonObject = (JSONObject)JSON.toJSON(header); RequestBody requestBody = RequestBody.create(CONTENT_TYPE, json); Request.Builder builder = new Request.Builder(); for (Map.Entry entry:jsonObject.entrySet()) { if(entry.getValue()==null){ continue; } builder.addHeader(String.valueOf(entry.getKey()).replaceAll("_","-"),String.valueOf(entry.getValue())); } // 用okhttp3 拼接發(fā)送請(qǐng)求 try { Response response = httpClient.newCall((builder).url("https://"+url).post(requestBody).build()).execute(); String request = response.body().string(); T t = JSON.parseObject(request, clazz); return t; } catch (IOException var8) { throw new ApiProcessException(ErrorCode.HTTP_REQUEST_ERROR, var8.getMessage()); } } public static byte[] hmac256(byte[] key, String msg) throws Exception { Mac mac = Mac.getInstance("HmacSHA256"); SecretKeySpec secretKeySpec = new SecretKeySpec(key, mac.getAlgorithm()); mac.init(secretKeySpec); return mac.doFinal(msg.getBytes(CHARSET)); }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.cdcxhl.com,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。