You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pdd-order-api/app/libs/tool/class.OuterPlatformTool.php

43 lines
1.3 KiB
PHTML

11 months ago
<?php
class OuterPlatformTool {
public static function getPlatformInfos() {
return [
'PDD202303211515' => [
'appKey' => 'PDD202303211515',
'appName' => '1688订单',
'secretKey' => Zc::C('platformAuthToken'),
],
'PDD202306190900' => [
'appKey' => 'PDD202306190900',
'appName' => '1688聚宝',
'secretKey' => Zc::C('platformAuthToken'),
],
];
}
public static function checkSign($params) {
if (empty($params['appKey'])) {
throw new BizException('appKey不能为空');
}
$platformInfo = self::getPlatformInfos()[$params['appKey']];
if (empty($platformInfo)) {
throw new BizException('appKey错误');
}
if ($params['sign'] != self::generateSign($params, $platformInfo['secretKey'])) {
throw new BizException('验签错误');
}
}
private static function generateSign($params, $secretKey) {
unset($params['sign']);
ksort($params);
$string = $secretKey;
foreach ($params as $key => $val) {
$val = is_array($val) ? json_encode($val) : $val;
$string .= $key . $val;
}
$string .= $secretKey;
return md5($string);
}
}