Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

v2接口添加响应可不验证sign选项 #91

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README_APIv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ $res = $instance
'desc' => '理赔',
'spbill_create_ip' => '192.168.0.1',
],
'wxpay_sign_verify' => false //该接口没有返回sign字段,不需要验证返回签名
'security' => true, //请求需要双向证书
'debug' => true //开启调试模式
])
Expand Down
9 changes: 6 additions & 3 deletions src/ClientXmlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ public static function transformResponse(string $secret = ''): callable
{
return static function (callable $handler) use ($secret): callable {
return static function (RequestInterface $request, array $options = []) use ($secret, $handler): PromiseInterface {
return $handler($request, $options)->then(static function(ResponseInterface $response) use ($secret) {
$needVerify = (isset($options['wxpay_sign_verify']) && $options['wxpay_sign_verify'] == false) ? false : true;
return $handler($request, $options)->then(static function(ResponseInterface $response) use ($secret,$needVerify) {
if(!$needVerify)
return $response;
$result = Transformer::toArray(static::body($response));

/** @var ?string $sign */
Expand Down Expand Up @@ -122,10 +125,10 @@ public static function xmlBased(array $config = []): Client
/** @var HandlerStack $stack */
$stack = isset($config['handler']) && ($config['handler'] instanceof HandlerStack) ? (clone $config['handler']) : HandlerStack::create();
$stack->before('prepare_body', static::transformRequest($config['mchid'] ?? null, $config['secret'] ?? '', $config['merchant'] ?? []), 'transform_request');
$stack->before('http_errors', static::transformResponse($config['secret'] ?? ''), 'transform_response');
$stack->before('http_errors', static::transformResponse($config['secret'] ?? '') , 'transform_response');
$config['handler'] = $stack;

unset($config['mchid'], $config['serial'], $config['privateKey'], $config['certs'], $config['secret'], $config['merchant']);
unset($config['mchid'], $config['serial'], $config['privateKey'], $config['certs'], $config['secret'], $config['merchant'],$config['wxpay_sign_verify']);

return new Client(static::withDefaults(['headers' => static::$headers], $config));
}
Expand Down