master
parent
4c82631c41
commit
e3db44c4c4
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
namespace Org\OuterPay;
|
||||||
|
|
||||||
|
class AlipayApi
|
||||||
|
{
|
||||||
|
public static function pay($data, $userInfo, $notifyUrl, $returnUrl) {
|
||||||
|
|
||||||
|
$url = "";
|
||||||
|
|
||||||
|
$params = [];
|
||||||
|
$params['user_id'] = (int)$data["user_id"];
|
||||||
|
$params['user_account'] = $userInfo["account"];
|
||||||
|
$params['game_id'] = (int)$data["game_id"];
|
||||||
|
$params['game_name'] = $data['game_name'];
|
||||||
|
$params['server_id'] = $data["server_id"];
|
||||||
|
$params['server_name'] = $data["server_name"];
|
||||||
|
$params['role_id'] = $data["game_player_id"];
|
||||||
|
$params['role_name'] = $data["game_player_name"];
|
||||||
|
$params['promote_id'] = (int)$userInfo["promote_id"];
|
||||||
|
$params['promote_account'] = $userInfo["promote_account"];
|
||||||
|
$params['order_no'] = $data["pay_order_number"];
|
||||||
|
$params['pay_amount'] = (int)($data["price"] * 100);
|
||||||
|
$params['notify_url'] = $notifyUrl;
|
||||||
|
$params['return_url'] = $returnUrl;
|
||||||
|
$params['subject'] = '消费#' . $data["pay_order_number"] . "#";
|
||||||
|
return self::request($url, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function request($url, $params): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$response = self::post($url, $params);
|
||||||
|
Log::write('REQUEST_RESPONSE: ' . $response);
|
||||||
|
return json_decode($response, true);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::write('REQUEST_ERROR: ' . $e->getMessage());
|
||||||
|
return [
|
||||||
|
'code' => -999,
|
||||||
|
'message' => '网络错误',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static 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);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
}
|
||||||
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($curl, CURLOPT_POST, true);
|
||||||
|
$headers = ['Content-type: application/json'];
|
||||||
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
|
||||||
|
$response = curl_exec($curl);
|
||||||
|
curl_close($curl);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
namespace Org\OuterPay;
|
||||||
|
|
||||||
|
use Think\Log as ThinkLog;
|
||||||
|
|
||||||
|
class Log
|
||||||
|
{
|
||||||
|
public static function write($message, $level = ThinkLog::INFO) {
|
||||||
|
$destination = C('LOG_PATH'). 'outer_pay/' . date('y_m_d').'.log';
|
||||||
|
ThinkLog::write($message, $level, '', $destination);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue