-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: wanghaojie <[email protected]> Co-authored-by: yansongda <[email protected]>
- Loading branch information
1 parent
df334dd
commit db85283
Showing
48 changed files
with
2,104 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
## 3.7.7 | ||
|
||
### added | ||
|
||
- feat: 新增江苏银行e融支付(#1002) | ||
|
||
## v3.7.6 | ||
|
||
### fixed | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yansongda\Pay\Plugin\Jsb; | ||
|
||
use Closure; | ||
use Yansongda\Artful\Contract\PluginInterface; | ||
use Yansongda\Artful\Exception\ContainerException; | ||
use Yansongda\Artful\Exception\InvalidConfigException; | ||
use Yansongda\Artful\Exception\InvalidParamsException; | ||
use Yansongda\Artful\Exception\ServiceNotFoundException; | ||
use Yansongda\Artful\Logger; | ||
use Yansongda\Artful\Rocket; | ||
use Yansongda\Pay\Exception\Exception; | ||
use Yansongda\Supports\Collection; | ||
|
||
use function Yansongda\Pay\get_private_cert; | ||
use function Yansongda\Pay\get_provider_config; | ||
|
||
class AddPayloadSignPlugin implements PluginInterface | ||
{ | ||
/** | ||
* @throws ContainerException | ||
* @throws InvalidConfigException | ||
* @throws InvalidParamsException | ||
* @throws ServiceNotFoundException | ||
*/ | ||
public function assembly(Rocket $rocket, Closure $next): Rocket | ||
{ | ||
Logger::info('[Jsb][AddPayloadSignPlugin] 插件开始装载', ['rocket' => $rocket]); | ||
|
||
$params = $rocket->getParams(); | ||
$config = get_provider_config('jsb', $params); | ||
$payload = $rocket->getPayload(); | ||
|
||
if (empty($payload) || $payload->isEmpty()) { | ||
throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 缺少支付必要参数。可能插件用错顺序,应该先使用 `业务插件`'); | ||
} | ||
|
||
$privateCertPath = $config['mch_secret_cert_path'] ?? ''; | ||
|
||
if (empty($privateCertPath)) { | ||
throw new InvalidConfigException(Exception::CONFIG_JSB_INVALID, '配置异常: 缺少配置参数 -- [mch_secret_cert_path]'); | ||
} | ||
|
||
$rocket->mergePayload([ | ||
'signType' => 'RSA', | ||
'sign' => $this->getSignature(get_private_cert($privateCertPath), $payload), | ||
]); | ||
|
||
Logger::info('[Jsb][AddPayloadSignPlugin] 插件装载完毕', ['rocket' => $rocket]); | ||
|
||
return $next($rocket); | ||
} | ||
|
||
protected function getSignature(string $pkey, Collection $payload): string | ||
{ | ||
$content = $payload->sortKeys()->toString(); | ||
|
||
openssl_sign($content, $signature, $pkey); | ||
|
||
return base64_encode($signature); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yansongda\Pay\Plugin\Jsb; | ||
|
||
use Closure; | ||
use GuzzleHttp\Psr7\Request; | ||
use Yansongda\Artful\Contract\PluginInterface; | ||
use Yansongda\Artful\Exception\ContainerException; | ||
use Yansongda\Artful\Exception\ServiceNotFoundException; | ||
use Yansongda\Artful\Logger; | ||
use Yansongda\Artful\Rocket; | ||
use Yansongda\Supports\Collection; | ||
|
||
use function Yansongda\Pay\get_jsb_url; | ||
use function Yansongda\Pay\get_provider_config; | ||
|
||
class AddRadarPlugin implements PluginInterface | ||
{ | ||
/** | ||
* @throws ServiceNotFoundException | ||
* @throws ContainerException | ||
*/ | ||
public function assembly(Rocket $rocket, Closure $next): Rocket | ||
{ | ||
Logger::info('[Jsb][AddRadarPlugin] 插件开始装载', ['rocket' => $rocket]); | ||
|
||
$params = $rocket->getParams(); | ||
$config = get_provider_config('jsb', $params); | ||
$payload = $rocket->getPayload(); | ||
|
||
$rocket->setRadar(new Request( | ||
strtoupper($params['_method'] ?? 'POST'), | ||
get_jsb_url($config, $payload), | ||
$this->getHeaders(), | ||
$this->getBody($payload), | ||
)); | ||
|
||
Logger::info('[Jsb][AddRadarPlugin] 插件装载完毕', ['rocket' => $rocket]); | ||
|
||
return $next($rocket); | ||
} | ||
|
||
protected function getHeaders(): array | ||
{ | ||
return [ | ||
'Content-Type' => 'text/html', | ||
'User-Agent' => 'yansongda/pay-v3', | ||
]; | ||
} | ||
|
||
protected function getBody(Collection $payload): string | ||
{ | ||
$sign = $payload->get('sign'); | ||
$signType = $payload->get('signType'); | ||
|
||
$payload->forget('sign'); | ||
$payload->forget('signType'); | ||
|
||
$payload = $payload->sortKeys(); | ||
|
||
$payload->set('sign', $sign); | ||
$payload->set('signType', $signType); | ||
|
||
return $payload->toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yansongda\Pay\Plugin\Jsb; | ||
|
||
use Closure; | ||
use Yansongda\Artful\Contract\PluginInterface; | ||
use Yansongda\Artful\Direction\NoHttpRequestDirection; | ||
use Yansongda\Artful\Exception\ContainerException; | ||
use Yansongda\Artful\Exception\InvalidConfigException; | ||
use Yansongda\Artful\Exception\InvalidParamsException; | ||
use Yansongda\Artful\Exception\ServiceNotFoundException; | ||
use Yansongda\Artful\Logger; | ||
use Yansongda\Artful\Rocket; | ||
use Yansongda\Pay\Exception\Exception; | ||
use Yansongda\Pay\Exception\InvalidSignException; | ||
use Yansongda\Supports\Collection; | ||
|
||
use function Yansongda\Pay\get_provider_config; | ||
use function Yansongda\Pay\verify_jsb_sign; | ||
|
||
class CallbackPlugin implements PluginInterface | ||
{ | ||
/** | ||
* @throws ContainerException | ||
* @throws InvalidConfigException | ||
* @throws InvalidParamsException | ||
* @throws ServiceNotFoundException | ||
* @throws InvalidSignException | ||
*/ | ||
public function assembly(Rocket $rocket, Closure $next): Rocket | ||
{ | ||
Logger::info('[Jsb][CallbackPlugin] 插件开始装载', ['rocket' => $rocket]); | ||
|
||
$this->formatRequestAndParams($rocket); | ||
|
||
$params = $rocket->getParams(); | ||
$config = get_provider_config('jsb', $params); | ||
|
||
$payload = $rocket->getPayload(); | ||
$signature = $payload->get('sign'); | ||
|
||
$payload->forget('sign'); | ||
$payload->forget('signType'); | ||
|
||
verify_jsb_sign($config, $payload->sortKeys()->toString(), $signature); | ||
|
||
$rocket->setDirection(NoHttpRequestDirection::class) | ||
->setDestination($rocket->getPayload()); | ||
|
||
Logger::info('[Jsb][CallbackPlugin] 插件装载完毕', ['rocket' => $rocket]); | ||
|
||
return $next($rocket); | ||
} | ||
|
||
/** | ||
* @throws InvalidParamsException | ||
*/ | ||
protected function formatRequestAndParams(Rocket $rocket): void | ||
{ | ||
$request = $rocket->getParams()['request'] ?? null; | ||
|
||
if (!$request instanceof Collection) { | ||
throw new InvalidParamsException(Exception::PARAMS_CALLBACK_REQUEST_INVALID); | ||
} | ||
|
||
$rocket->setPayload($request)->setParams($rocket->getParams()['params'] ?? []); | ||
} | ||
} |
Oops, something went wrong.