|
...
|
...
|
@@ -2,28 +2,24 @@ |
|
|
|
|
|
|
|
namespace Lackoxygen\TiktokShop\Util;
|
|
|
|
|
|
|
|
class Signature
|
|
|
|
{
|
|
|
|
private string $appKey;
|
|
|
|
|
|
|
|
private string $appSecret;
|
|
|
|
use Lackoxygen\TiktokShop\Attribute\Config\Config;
|
|
|
|
|
|
|
|
class Signature extends Config
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private string $method;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private string $timestamp;
|
|
|
|
|
|
|
|
private string $paramJson;
|
|
|
|
|
|
|
|
private string $version;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $appKey
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public function setAppKey(string $appKey): Signature
|
|
|
|
{
|
|
|
|
$this->appKey = $appKey;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
private string $paramJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $method
|
|
...
|
...
|
@@ -43,14 +39,6 @@ class Signature |
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $appSecret
|
|
|
|
*/
|
|
|
|
public function setAppSecret($appSecret): Signature
|
|
|
|
{
|
|
|
|
$this->appSecret = $appSecret;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $paramJson
|
|
...
|
...
|
@@ -62,23 +50,42 @@ class Signature |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $version
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function setVersion($version): Signature
|
|
|
|
public function generate()
|
|
|
|
{
|
|
|
|
$this->version = $version;
|
|
|
|
return $this;
|
|
|
|
$paramPattern = 'app_key' . $this->config->getAppKey(
|
|
|
|
) . 'method' . $this->method . 'param_json' . $this->paramJson .
|
|
|
|
'timestamp' . $this->timestamp . 'v' . $this->config->getVersion();
|
|
|
|
|
|
|
|
$body = $this->config->getAppSecret() . $paramPattern . $this->config->getAppSecret();
|
|
|
|
|
|
|
|
switch ($this->config->getSignMethod()) {
|
|
|
|
case 'hmac-sha256':
|
|
|
|
case 'sha256':
|
|
|
|
return $this->sha256($body);
|
|
|
|
case 'md5':
|
|
|
|
return $this->md5($body);
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $body
|
|
|
|
* @return false|string
|
|
|
|
*/
|
|
|
|
public function generate()
|
|
|
|
protected function sha256(string $body): string
|
|
|
|
{
|
|
|
|
return (string)\hash_hmac("sha256", $body, $this->config->getAppSecret());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $body
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function md5(string $body): string
|
|
|
|
{
|
|
|
|
$paramPattern = 'app_key' . $this->appKey . 'method' .
|
|
|
|
$this->method . 'param_json' . $this->paramJson .
|
|
|
|
'timestamp' . $this->timestamp . 'v' . $this->version;
|
|
|
|
$signPattern = $this->appSecret . $paramPattern . $this->appSecret;
|
|
|
|
return hash_hmac("sha256", $signPattern, $this->appSecret);
|
|
|
|
return \md5($body . $this->config->getAppSecret());
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|