How do I generate a valid SDK signature from PHP?

Hi, I’m trying to generate a signature but I’m only getting an error.

function generate_signature ( $api_key, $api_secret, $meeting_number, $role){
    //Set the timezone to UTC
    date_default_timezone_set("UTC");
      $time = time() * 1000 - 30000;//time in milliseconds (or close enough)
      $data = base64_encode($api_key . $meeting_number . $time . $role);
      $hash = hash_hmac('sha256', $data, $api_secret, true);
      $_sig = $api_key . "." . $meeting_number . "." . $time . "." . $role . "." . base64_encode($hash);
      //return signature, url safe base64 encoded
      return rtrim(strtr(base64_encode($_sig), '+/', '-_'), '=');
}
{type: 'JOIN_MEETING_FAILED', reason: 'Signature is invalid.', errorCode: 3712}

I’m using the CDN

<!-- For ZOOM Component and Client View -->
    <script src="https://source.zoom.us/2.4.5/lib/vendor/react.min.js"></script>
    <script src="https://source.zoom.us/2.4.5/lib/vendor/react-dom.min.js"></script>
    <script src="https://source.zoom.us/2.4.5/lib/vendor/redux.min.js"></script>
    <script src="https://source.zoom.us/2.4.5/lib/vendor/redux-thunk.min.js"></script>
    <script src="https://source.zoom.us/2.4.5/lib/vendor/lodash.min.js"></script>
    
    <!-- For ZOOM Component View -->
    <script src="https://source.zoom.us/2.4.5/zoom-meeting-embedded-2.4.5.min.js"></script>
let meetingSDKElement = document.getElementById('meetingSDKElement')

client.init({
    debug: true,
    zoomAppRoot: meetingSDKElement,
    language: 'en-US',
    customize: {
        meetingInfo: [
            'topic',
            'host',
            'mn',
            'pwd',
            'telPwd',
            'invite',
            'participant',
            'dc',
            'enctype',
        ],
        toolbar: {
            buttons: [{
                text: 'Custom Button',
                className: 'CustomButton',
                onClick: () => {
                    console.log('custom button')
                }
            }]
        }
    }
});

client.join({
    sdkKey: SDKKEY,
    signature: SIGNATURE,
    meetingNumber: MEETINGNUMBER,
    password: ZOOMPASSWORD,
    userName: ZOOMUSER,
});

Did you find the solution? Stuck at a similar problem.

Hi, @SVIF,

Welcome to the Zoom Developer Forum – we are thrilled to have you join the community. Would you be able to share what App type you are using to generate the meeting signature? The first thing I would recommend is to manually generate and enter the signature. This will help isolate the root cause of the behavior you are seeing.

Best,
Donte