Skip to content

Commit

Permalink
再次解决艹蛋的支付宝API编码问题, fix #61
Browse files Browse the repository at this point in the history
  • Loading branch information
yansongda committed Jan 4, 2018
1 parent ae81a9c commit 3a051ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Gateways/Alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ public function verify(): Collection

$data = $request->request->count() > 0 ? $request->request->all() : $request->query->all();

$data = Arr::encoding($data, 'utf-8', 'gb2312');
$data = (!isset($data['charset']) || $data['charset'] != 'utf-8') ? Arr::encoding($data, 'utf-8', 'gb2312') : $data;

Log::debug('Receive Alipay Request:', $data);

if (Support::verifySign($data, $this->config->get('ali_public_key'))) {
return new Collection($data);
}

Log::warning('Alipay Sign verify FAILED', $data);
Log::warning('Alipay Sign Verify FAILED', $data);

throw new InvalidSignException('Alipay Sign verify FAILED', 3, $data);
throw new InvalidSignException('Alipay Sign Verify FAILED', 3, $data);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Gateways/Alipay/Support.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public static function verifySign($data, $publicKey = null, $sync = false, $sign
$sign = $sign ?? $data['sign'];

$toVerify = $sync ? mb_convert_encoding(json_encode($data, JSON_UNESCAPED_UNICODE), 'gb2312', 'utf-8') :
self::getSignContent(Arr::encoding($data, 'gb2312', 'utf-8'), true);
self::getSignContent(
(!isset($data['charset']) || $data['charset'] != 'utf-8') ? Arr::encoding($data, 'gb2312', 'utf-8') : $data,
true
);

return openssl_verify($toVerify, base64_decode($sign), $publicKey, OPENSSL_ALGO_SHA256) === 1;
}
Expand Down

0 comments on commit 3a051ab

Please sign in to comment.