v2board/library/PayTaro.php
2020-01-25 23:04:52 +08:00

49 lines
1.1 KiB
PHP

<?php
namespace Library;
use \Curl\Curl;
class PayTaro
{
private $appId;
private $appSecret;
public function __construct($appId, $appSecret)
{
$this->appId = $appId;
$this->appSecret = $appSecret;
}
public function pay($params)
{
ksort($params);
$str = http_build_query($params) . $this->appSecret;
$params['sign'] = md5($str);
$curl = new Curl();
$curl->post('https://api.paytaro.com/v1/gateway/fetch', http_build_query($params));
if ($curl->error) {
abort(500, '接口请求失败');
}
$result = $curl->response;
$curl->close();
if (!isset($result->data->trade_no)) {
abort(500, '接口请求失败');
}
return $result->data->pay_url;
}
public function verify($params)
{
$sign = $params['sign'];
unset($params['sign']);
ksort($params);
reset($params);
$str = http_build_query($params) . $this->appSecret;
if ($sign !== md5($str)) {
return false;
}
return true;
}
}