Skip to content

Commit

Permalink
修复调用失败
Browse files Browse the repository at this point in the history
  • Loading branch information
midsmr committed Mar 27, 2022
1 parent b050183 commit c3c89ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/SimplePay.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function submit(
?array $extends = []
): string
{
return $this->create('submit', $type, $out_trade_no, $notify_url, $return_url, $name, $money, $extends);
return $this->create('submit', $type, $out_trade_no, $notify_url, $return_url, $name, $money, extends: $extends);
}

/**
Expand All @@ -57,10 +57,12 @@ public function mapi(
string $return_url,
string $name,
string $money,
string $clientip,
string $device,
?array $extends = []
): string
{
return $this->create('mapi', $type, $out_trade_no, $notify_url, $return_url, $name, $money, $extends);
return $this->create('mapi', $type, $out_trade_no, $notify_url, $return_url, $name, $money, $clientip, $device, $extends);
}

/**
Expand All @@ -84,6 +86,8 @@ protected function create(
string $return_url,
string $name,
string $money,
?string $clientip = '',
?string $device = '',
?array $extends = []
): string
{
Expand All @@ -102,20 +106,21 @@ protected function create(
'extends' => json_encode($extends)
];

$params['sign'] = $this->sign($params);
$params['sign_type'] = 'MD5';

$query = http_build_query($params);

if ($method == 'submit') {
$file = 'submit.php';
} elseif ($method == 'mapi') {
$file = 'mapi.php';
$params['clientip'] = $clientip;
$params['device'] = $device;
} else {
throw new \LogicException("错误的提交方式:{$method}");
}

return "{$this->gateway}?{$query}";
$params['sign'] = $this->sign($params);
$params['sign_type'] = 'MD5';

$query = http_build_query($params);
return "{$this->gateway}{$file}?{$query}";
}

public function verify(array $params): bool
Expand Down
2 changes: 1 addition & 1 deletion tests/submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

$simplePay = new \Midsmr\SimplePay\SimplePay(GATEWAY, PID, KEY);

$url = $simplePay->create('alipay', time(), 'call', 'call', 'te', '0.01');
$url = $simplePay->mapi('alipay', time(), 'call', 'call', 'te', '0.01', '123.234.123.222', 'mobile');

header("Location: {$url}");

0 comments on commit c3c89ee

Please sign in to comment.