Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: endless loop and error verification #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions php/src/Kernel/EasySDKKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ public function toMultipartRequestBody($textParams, $fileParams, $boundary)

do {
$readLength = $stream->read(1024);
} while (0 != $readLength);
} while (!$readLength);
/**
* in PHP 8.0 or above: 0 != '' always true, this is an endless loop
*/
// } while (0 != $readLength);
return $stream;
}

Expand Down Expand Up @@ -228,6 +232,7 @@ public function extractAlipayPublicKey($alipayCertSN)
public function verify($respMap, $alipayPublicKey)
{
$resp = json_decode($respMap[AlipayConstants::BODY_FIELD], true);
// var_dump($resp);
$sign = $resp[AlipayConstants::SIGN_FIELD];
$signContentExtractor = new SignContentExtractor();
$content = $signContentExtractor->getSignSourceData($respMap[AlipayConstants::BODY_FIELD],
Expand Down Expand Up @@ -355,7 +360,16 @@ private function buildQueryString(array $sortedMap)

}

private function getSortedMap($systemParams, $bizParams, $textParams)
private function getExcludeMethods()
{
return [
// 占位用,兼容不传递接口名称的情况
'placeholder',
'alipay.merchant.item.file.upload',
];
}

private function getSortedMap($systemParams, $bizParams, $textParams, $method = 'placeholder')
{
$this->textParams = $textParams;
$this->bizParams = $bizParams;
Expand Down Expand Up @@ -384,7 +398,7 @@ private function getSortedMap($systemParams, $bizParams, $textParams)
$sortedMap = $this->textParams;
}
}
if ($this->getConfig(AlipayConstants::NOTIFY_URL_CONFIG_KEY) != null) {
if (!in_array($method, $this->getExcludeMethods()) && $this->getConfig(AlipayConstants::NOTIFY_URL_CONFIG_KEY) != null) {
$sortedMap[AlipayConstants::NOTIFY_URL_FIELD] = $this->getConfig(AlipayConstants::NOTIFY_URL_CONFIG_KEY);
}
return $sortedMap;
Expand Down Expand Up @@ -463,4 +477,4 @@ function characet($data, $targetCharset)
return $data;
}

}
}