WC_Webhook::generate_signature()publicWC 2.2.0

Generate a base64-encoded HMAC-SHA256 signature of the payload body so the recipient can verify the authenticity of the webhook. Note that the signature is calculated after the body has already been encoded (JSON by default).

Метод класса: WC_Webhook{}

Хуки из метода




$WC_Webhook = new WC_Webhook();
$WC_Webhook->generate_signature( $payload );
$payload(строка) (обязательный)
Payload data to hash.

Список изменений

С версии 2.2.0 Введена.

Код WC_Webhook::generate_signature() WC 7.3.0

public function generate_signature( $payload ) {
	$hash_algo = apply_filters( 'woocommerce_webhook_hash_algorithm', 'sha256', $payload, $this->get_id() );

	// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
	return base64_encode( hash_hmac( $hash_algo, $payload, wp_specialchars_decode( $this->get_secret(), ENT_QUOTES ), true ) );