master
elf 2 years ago
parent b47336085f
commit f26738ec08

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

@ -4,6 +4,7 @@ namespace Org\Kudian;
class Config class Config
{ {
private static $params = [ private static $params = [
'base_url' => 'https://pay.kudianvip.com',
'mch_id' => 'KP10009694', 'mch_id' => 'KP10009694',
'secret_key' => 'q5zZyyA071zS0SZR6xcz0gP0fFhtojqq', '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() { public function getUrl() {
return $this->url; return Config::get('base_url') . $this->url;
} }
} }

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

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

Loading…
Cancel
Save