CloudHub Docs
Download Documents

RTC


RestAPI

token signature rules

Note: This signature is generated by the user’s server and cannot be placed directly on the client, otherwise the security will be affected;

  1. All interface requests are submitted by POST (Does not support json format submission);

  2. The app_id value in the request parameter must be passed;

  3. Verification parameter token generation rule (This parameter must also be passed);

    • 3.1 Generation rules:md5(md5( app_id + BodyStr) + md5(SecretKey)).
    • 3.2 app_id : The APPID can be found through the enterprise management background.
    • 3.3 BodyStr : POST submits parameters (token is generated and appended later, not in bodyStr), sorts the submitted parameters according to the specified rules, and then generates a string.
    • 3.4 SecretKey : The default management background is automatically generated, and subsequent customers can modify it by themselves.

    The PHP generated token case is posted below: After the token is generated, put it in the Post submission parameters and submit it together

<?php
    /**
     * Get token
     * @param $postData   Post submission parameters
     * @param $appId        app_id enterprise app_id value
     * @param $secretKey
     * @return string
     */
    function getToken($postData,$appId,$secretKey){
    // Excluding these 2 items, no string generation is performed
        unset($postData['token']);
        unset($postData['app_id']);
        // Submit the Post parameter to generate a string
        $bodyStr = $postData?getBodyStr($postData):'';
        // Generate rule md5 (enterprise key + bodyStr string + enterprise random string);
        return md5(md5($appId.$bodyStr).md5($secretKey));
    }
    
    /**
     * [Convert the corresponding irregular array into a string]
     * @param  [type] $data [Post submission parameters]
     * @param  [type] $str  [description]
     * @return [type]       [description]
     */
    function getBodyStr($data, $str = '') {
        // Sort data key values
        ksort($data);
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                if ($value) {
                    $str .= $key;
                    $str = getBodyStr($value, $str);
                }
            } else {
                if (($value || $value === 0 || $value === '0') && $value !== null && $value !== false && $value !== true) {
                    $str .= $key . $value;
                }
            }
        }
        return $str;
    }