v2board/library/PayTaro.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2020-01-12 19:48:13 +08:00
<?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);
2020-01-12 22:38:29 +08:00
$str = http_build_query($params) . $this->appSecret;
2020-01-12 19:48:13 +08:00
$params['sign'] = md5($str);
$curl = new Curl();
$curl->post('http://api.paytaro.com/v1/gateway/fetch', http_build_query($params));
2020-01-12 22:38:29 +08:00
var_dump($str, $params, $curl->response);exit;
2020-01-12 19:48:13 +08:00
if ($curl->error) {
abort(500, '接口请求失败');
}
$result = json_decode($curl->response);
$curl->close();
if ($result->code !== 1) {
abort(500, '接口请求失败');
}
return $result->code_url;
}
public function verify($params)
{
$sign = $params['sign'];
unset($params['sign']);
ksort($params);
reset($params);
2020-01-12 22:38:29 +08:00
$str = http_build_query($params) . $this->appId;
2020-01-12 19:48:13 +08:00
if ($sign !== md5($str)) {
return false;
}
return true;
}
}