master
elf 2 years ago
parent b47336085f
commit f26738ec08

@ -11,7 +11,9 @@ class Client
$response = '';
try {
$response = $this->post($request->getUrl(), $request->getParams());
Log::write('REQUEST_RESPONSE: ' . $response);
} catch (Exception $e) {
Log::write('REQUEST_ERROR: ' . $e->getMessage());
$response = json_encode([
'code' => -999,
'msg' => '网络错误',
@ -25,6 +27,8 @@ class Client
public function post($url, $params): string
{
Log::write('REQUEST_URL: ' . json_encode($url));
Log::write('REQUEST_DATA: ' . json_encode($params));
$curl = curl_init();
if (stripos($url, 'https://') !== false){
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

@ -4,6 +4,7 @@ namespace Org\Kudian;
class Config
{
private static $params = [
'base_url' => 'https://pay.kudianvip.com',
'mch_id' => 'KP10009694',
'secret_key' => 'q5zZyyA071zS0SZR6xcz0gP0fFhtojqq',
];

@ -0,0 +1,12 @@
<?php
namespace Org\Kudian;
use Think\Log as ThinkLog;
class Log
{
public static function write($message, $level = ThinkLog::INFO) {
$destination = C('LOG_PATH'). 'kudian/' . date('y_m_d').'.log';
ThinkLog::write($message, $level, '', $destination);
}
}

@ -59,6 +59,6 @@ class Request
}
public function getUrl() {
return $this->url;
return Config::get('base_url') . $this->url;
}
}

@ -24,8 +24,10 @@ class Response
{
$data = null;
if (is_array($response)) {
Log::write('RESPONSE_ARRAY: ' . json_encode($response));
$data = $response;
} else {
Log::write('RESPONSE_STR: ' . $response);
$data = json_decode($response);
}
if (!$data) {

@ -7,6 +7,7 @@ class Sign
public static function generate($params, $secretKey)
{
Log::write('SIGN_PARAMS: ' . json_encode($params));
unset($params[self::SIGN_KEY]);
ksort($params);
$signStr = '';
@ -14,6 +15,7 @@ class Sign
$signStr .= $key . "=" . $value . "&";
}
$signStr = rtrim($signStr, '&') . "&secret_key=" . $secretKey;
Log::write('SIGN_STR: ' . $signStr);
$sign = md5($signStr);
$sign = strtoupper($sign);
return $sign;

Loading…
Cancel
Save