if anyone still need PHP implementation, here is a working code:
$getPrivateKey = openssl_pkey_get_private(file_get_contents('../config/weather_key.pem'));
openssl_pkey_export($getPrivateKey, $privateKey);
$date = new DateTimeImmutable();
$expire_at = $date->modify('+3 minutes')->getTimestamp();
$teamID = "*******";
$encryptionType = 'ES256';
$keyID = '*****'; //key identifier
$serviceID = "net.Yourysite.myWeather";
$request_data = [
'iat' => $date->getTimestamp(),
'iss' => $teamID,
'exp' => $expire_at,
'sub' => $serviceID,
];
$mytoken = JWT::encode(
$request_data,
$privateKey,
$encryptionType,
$keyID
);
// use this valid $mytoken in curl function;