diff --git a/extend/pay/Epay.php b/extend/pay/Epay.php index 9de924b..521349a 100644 --- a/extend/pay/Epay.php +++ b/extend/pay/Epay.php @@ -131,10 +131,14 @@ class Epay /** * API 模式下单(mapi.php) * + * @param string $clientIp 下单用户的 IP(mapi.php 必填,否则报 "用户IP地址(clientip)不能为空") * @return array|null */ - public function createOrderApi($orderNo, $type, $amount, $name, $notifyUrl, $returnUrl = '', $param = '') + public function createOrderApi($orderNo, $type, $amount, $name, $notifyUrl, $returnUrl = '', $param = '', $clientIp = '') { + if ($clientIp === '' || $clientIp === null) { + $clientIp = \think\Request::instance()->ip(); + } $params = [ 'pid' => strval($this->config['pid'] ?? ''), 'type' => $type, @@ -144,6 +148,7 @@ class Epay 'name' => $name, 'money' => strval($amount), 'param' => $param, + 'clientip' => strval($clientIp), 'sign_type' => 'MD5', ]; $params['sign'] = $this->generateSign($params);