Skip to content

Instantly share code, notes, and snippets.

@MattHealy
Created June 30, 2021 11:54
Show Gist options
  • Select an option

  • Save MattHealy/0b2da711cde4612b76e26eabfbd79ce3 to your computer and use it in GitHub Desktop.

Select an option

Save MattHealy/0b2da711cde4612b76e26eabfbd79ce3 to your computer and use it in GitHub Desktop.

Revisions

  1. MattHealy created this gist Jun 30, 2021.
    38 changes: 38 additions & 0 deletions sign.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    <?php

    // HMAC-SHA512 signing

    function get_signature($event, $orderid, $listing_id) {

    // Hashing algorithm to use
    $algo = 'sha512';

    // Shared key used for signing payloads
    $secret_key = 'abcdef';

    // Number of milliseconds since epoch
    $timestamp = time() * 1000;

    // Payload to be signed
    $payload = "t=$timestamp&event=$event&orderid=$orderid&listing_id=$listing_id";

    // Generate the signed payload
    $signed_payload = hash_hmac(
    $algo,
    $payload,
    $secret_key,
    false,
    );

    return "t=$timestamp,$algo=$signed_payload";

    }

    $sig = get_signature("delivery", "12345", "L98765");

    echo $sig . "\n";

    // Include this value as a header in the request
    // curl 'http://partner.se/diakrit/notify.php?event=change&orderid=XXXXXXX&listing_id=XXXXXXXX' -H 'X-DIAKRIT-SIGNATURE: sig'

    ?>