<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## appKey和appSecret驗證 由途狐管車服務平臺給出api連接地址、有效的appkey和appSecret,用戶通過appkey、appSecret獲取accessToken。 調用API時傳入appkey和accessToken,并對請求參數進行簽名,途狐API服務器端會驗證請求參數是否合法。**獲取的accessToken需要添加到消息頭中,每次訪問在消息頭中攜帶傳遞。定義Key值為X-Access-Token。如:{“X-Access-Token”:“xxxxx”}** ## API簽名 為了防止API調用過程中被黑客惡意篡改,調用任何一個API都需要攜帶簽名,途狐服務端會根據請求參數,對簽名進行驗證,簽名不合法的請求將會被拒絕。目前支持的簽名算法有:MD5(本接口通用參數里面signMethod的值為md5),簽名大體過程如下: 對所有API請求參數(包括公共參數和業務參數,但除去sign參數和byte\[\]類型的參數),根據參數名稱的ASCII碼表的順序排序。如:foo=1, bar=2, foo\_bar=3, foobar=4排序后的順序是bar=2, foo=1, foo\_bar=3, foobar=4。 將排序好的參數名和參數值拼裝在一起,根據上面的示例得到的結果為:bar2foo1foo\_bar3foobar4。 把拼裝好的字符串采用utf-8編碼,使用簽名算法對編碼后的字節流進行摘要。如果使用MD5算法,則需要在拼裝的字符串前后加上app的secret后,再進行摘要,如:md5(secret+bar2foo1foo\_bar3foobar4+secret)。 將摘要得到的字節流結果使用十六進制表示,如:hex(“helloworld”.getBytes(“utf-8”)) = “68656C6C6F776F726C64”。 說明:MD5是128位長度的摘要算法,用16進制表示,一個十六進制的字符能表示4個位,所以簽名后的字符串長度固定為32個十六進制字符。 ### 算法 JAVA代碼示例: ~~~ public static String signTuhuRequest(Map params, String secret, String signMethod) throws IOException { ????// 第一步:檢查參數是否已經排序 ????String[] keys = params.keySet().toArray(new String[0]); ????Arrays.sort(keys); ? ????// 第二步:把所有參數名和參數值串在一起 ????StringBuilder query = new StringBuilder(); ????if ("md5".equals(signMethod)) { ????????query.append(secret); ????} ????for (String key : keys) { ????????String value = params.get(key); ????????if (StringUtils.areNotEmpty(key, value)) { ????????????query.append(key).append(value); ????????} ????} ? ????// 第三步:使用MD5/HMAC加密 ????byte[] bytes; ????if ("hmac".equals(signMethod)) { ????????bytes = encryptHMAC(query.toString(), secret); ????} else { ????????query.append(secret); ????????bytes = encryptMD5(query.toString()); ????} ? ????// 第四步:把二進制轉化為大寫的十六進制 ????return byte2hex(bytes); } ? public static byte[] encryptHMAC(String data, String secret) throws IOException { ????byte[] bytes = null; ????try { ????????SecretKey secretKey = new SecretKeySpec(secret.getBytes("UTF-8"), "HmacMD5"); ????????Mac mac = Mac.getInstance(secretKey.getAlgorithm()); ????????mac.init(secretKey); ????????bytes = mac.doFinal(data.getBytes("UTF-8")); ????} catch (GeneralSecurityException gse) { ????????throw new IOException(gse.toString()); ????} ????return bytes; } ? public static byte[] encryptMD5(String data) throws IOException { ????return encryptMD5(data.getBytes("UTF-8")); } private static byte[] encryptMD5(byte[] bytes) throws IOException { MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new IOException(e.toString()); } return md.digest(bytes); } ? public static String byte2hex(byte[] bytes) { ????StringBuilder sign = new StringBuilder(); ????for (int i = 0; i < bytes.length; i++) { ????????String hex = Integer.toHexString(bytes[i] & 0xFF); ????????if (hex.length() == 1) { ????????????sign.append("0"); ????????} ????????sign.append(hex.toUpperCase()); ????} ????return sign.toString(); } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看