TlsEventSig.php 604 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Created by KLXQ
  4. * user: youyi
  5. * Date:2024/6/14 16:29.
  6. * Tencent SDK.
  7. * 目前主要用于腾讯事件回调验签.
  8. */
  9. namespace App\Http\Helpers\Tencent;
  10. class TlsEventSig
  11. {
  12. private string $key;
  13. private string $body;
  14. public function __construct($key, $body)
  15. {
  16. $this->key = $key;
  17. $this->body = $body;
  18. }
  19. private function __hmacsha256()
  20. {
  21. $hash = hash_hmac('sha256', $this->body, $this->key, true);
  22. return base64_encode($hash);
  23. }
  24. public function genEventSig()
  25. {
  26. return $this->__hmacsha256();
  27. }
  28. }