You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
3.2 KiB
PHP
65 lines
3.2 KiB
PHP
<?php
|
|
namespace Org\OuterPay;
|
|
|
|
class AlipayApi
|
|
{
|
|
public static function pay($data, $userInfo, $notifyUrl, $returnUrl) {
|
|
|
|
$url = "http://pay.hexidongkeji.top/pay";
|
|
|
|
$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;
|
|
var_dump(urldecode('https://openapi.alipay.com/gateway.do?app_id=2021004129619376&biz_content=%7B%22subject%22%3A%22%E6%B6%88%E8%B4%B9_SP_20231212143602pGYx%22%2C%22out_trade_no%22%3A%22SP_20231212143602pGYx%22%2C%22total_amount%22%3A%226E%2B00%22%2C%22product_code%22%3A%22%22%7D&charset=utf-8&format=JSON&method=alipay.trade.wap.pay¬ify_url=http%3A%2F%2Fpay.hexidongkeji.top%2Fnotify&return_url=http%3A%2F%2Fpay.hexidongkeji.top%2Freturn&sign=H44Ll1KLmiE8ogbypyHb1cw7kHTmefLgN6vOOcTS1yxSRMaKHIpdT8e%2F030Bok2bQQiueVXzymEVeMUFs5NS9bvc7m6%2FoyaWpmmIUwNuqYJDgx8hof6qFVEsifWEhRTBgPbzVU9NPuwzP84FTqsVtahfSEaPVkdIcaBao8RC7pgoXCwcNGCG4JK6J0ZQNgIwWdccpKWWmMlXVNaXCJoAdnYTb3VUucBL3o7osRShFP3Z8UTFBW1Uo1jQ2wIuF%2BREQwj3til3CWCU6PEvkIbq4NPRmMxy4sEJGWE8gdjV0Y5pSsXOp1xwq125YqS%2BcGufgtmx7P5%2FlKL99drZEy%2FC7Q%3D%3D&sign_type=RSA2×tamp=2023-12-12+14%3A36%3A03&version=1.0'));
|
|
}
|
|
} |