This commit is contained in:
lingling 2025-02-18 19:58:01 +08:00
commit 77932c8480
3 changed files with 130 additions and 67 deletions

View File

@ -35,6 +35,13 @@ class Payment
*/
public static function pushMoney($money,$payeeAccountName,$payeeAccountNumber,$payeeBankName)
{
$client = new Client();
$PaymentChannelId = 0;
if($payeeBankName == "bKash"){
$PaymentChannelId = 34;
}else{
$PaymentChannelId = 35;
}
$secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
$url = "https://mdf.hr5688.com/api/createPaymentOrder";
$headers = [
@ -50,35 +57,41 @@ class Payment
"PayeeAccountNumber" => $payeeAccountNumber,
"PayeeBankName" => $payeeBankName,
"PayeeIFSCCode" => "abc123",
"PaymentChannelId" => 34,
"ShopInformUrl" => "http://127.0.0.1/api/withdraw/getMoney",
"PaymentChannelId" => $PaymentChannelId,
"ShopInformUrl" => "http://127.0.0.1/api/withdraw/callback",
"ShopOrderId" => "10",
"ShopRemark" => "", // 留空时可不给此参数
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
];
$secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
$encrypt_value = self::generate_encrypt_value($payload, $secret_key);
$payload["EncryptValue"] = $encrypt_value;
var_dump(111111111111111);
var_dump($payload);
$response = $client->post($url, [
'json' => $payload, // 以 JSON 格式发送数据
'headers' => $headers
]);
var_dump($response);
// $json_payload = json_encode($payload);
$json_payload = json_encode($payload);
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $json_payload);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code == 200) {
echo $response;
} else {
echo "Error: HTTP Code $http_code\n";
echo $response;
}
curl_close($ch);
// $response = curl_exec($ch);
// $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// var_dump(1111111111111111111);
// var_dump($response);
// if ($http_code == 200) {
// echo $response;
// } else {
// echo "Error: HTTP Code $http_code\n";
// echo $response;
// }
// curl_close($ch);
return $response;
}
}

View File

@ -13,15 +13,33 @@ class PaymentNew
public static function generate_encrypt_value($data, $secret_key)
{
// 1. 过滤掉 EncryptValue 和值为 null 的参数
$filtered_data = array_filter($data, function ($v, $k) {
return $k !== "EncryptValue" && $v !== null;
$filtered_data = array_filter($data, function($value, $key) {
return $key !== 'EncryptValue' && $value !== null;
}, ARRAY_FILTER_USE_BOTH);
// 2. 按照 A~Z 顺序排序 key
ksort($filtered_data);
// 3. 拼接 key=value 形式的字符串,并加上 HashKey=密钥
$param_str = http_build_query($filtered_data) . "&HashKey=$secret_key";
$param_str = '';
foreach ($filtered_data as $key => $value) {
// 确保键名和值没有多余的空格
$key = trim($key);
// 处理布尔值
if (is_bool($value)) {
$value = $value ? 'true' : 'false';
} else {
$value = trim($value);
}
$param_str .= "$key=$value&";
}
// 移除最后一个多余的 &
$param_str = rtrim($param_str, '&');
// 添加 HashKey
$param_str .= "&HashKey=" . trim($secret_key);
// 输出拼接后的字符串以供调试(可选)
echo "Lowercase string: $param_str\n";
// 4. 转换为小写
$param_str = strtolower($param_str);
@ -36,14 +54,21 @@ class PaymentNew
/**
* 转账
*/
public static function pushMoney($money, $payeeAccountName, $payeeAccountNumber, $payeeBankName)
public static function pushMoney($money, $payeeAccountName, $payeeAccountNumber, $payeeBankName,$orderId)
{
$secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
$url = "https://mdf.hr5688.com/api/createPaymentOrder";
$PaymentChannelId = 0;
if($payeeBankName == "bKash"){
$PaymentChannelId = 34;
}else{
$PaymentChannelId = 35;
}
// Guzzle HTTP client
$client = new Client();
var_dump(11111111111);
var_dump($orderId);
// 请求数据
$payload = [
"Amount" => $money,
@ -52,18 +77,18 @@ class PaymentNew
"PayeeAccountName" => $payeeAccountName,
"PayeeAccountNumber" => $payeeAccountNumber,
"PayeeBankName" => $payeeBankName,
"PayeeIFSCCode" => "abc123",
"PaymentChannelId" => 34,
"ShopInformUrl" => "https://www.google.com",
"ShopOrderId" => "10",
"ShopRemark" => "", // 留空时可不给此参数
"PayeeIFSCCode" => "",
"PaymentChannelId" => $PaymentChannelId,
"ShopInformUrl" => "http://149.129.107.38",
"ShopOrderId" => $orderId."",
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
];
var_dump($payload);
// 生成加密值
$encrypt_value = self::generate_encrypt_value($payload, $secret_key);
var_dump($encrypt_value);
$payload["EncryptValue"] = $encrypt_value;
var_dump($encrypt_value);
try {
// 发送 POST 请求
$response = $client->post($url, [
@ -73,7 +98,7 @@ class PaymentNew
'Content-Type' => 'application/json',
]
]);
var_dump($response);
// 获取响应内容
$responseBody = $response->getBody()->getContents();
$httpCode = $response->getStatusCode();

View File

@ -9,6 +9,7 @@ use app\model\Userbank;
use support\Request;
use App\Utils\API\Payment;
use App\Utils\API\PaymentNew;
use App\Utils\ApiResponseApp;
@ -102,8 +103,7 @@ class WithdrawController
$rate = ExchangeRate::where('type', 'BDT')->get();
$money = $money_no / 100 * $rate[0]['points'];
var_dump($money);
//用户积分减少$money
UserRewardDao::base($user_id, 1, - ($money_no + 300), '提现');
//大于1000等待管理员审核
if ($money >= 1000) {
Withdraw::create([
@ -116,12 +116,11 @@ class WithdrawController
]);
return ApiResponseApp::success(null, '等待管理员审核');
}
$userbank = Userbank::where('user_id', $user_id)->first();
$res = Payment::pushMoney($money, $userbank->bank_username, $userbank->account, $userbank->bank_name);
var_dump($res);
//逻辑错误需要修改
if ($res['Success'] == 200) {
Withdraw::create([
//用户积分减少$money
UserRewardDao::base($user_id, 1, - ($money_no + 300), '提现');
$userbank = Userbank::where('id', $bank_id)->first();
//存入数据库
$withdraw = Withdraw::create([
'user_id' => $user_id,
'amount' => $money,
'status' => 2,
@ -129,11 +128,25 @@ class WithdrawController
'username' => $user->username,
'status_text' => '已到账',
]);
return ApiResponseApp::success(null, '转账成功');
} else {
return ApiResponseApp::error(null, '转账失败');
}
return ApiResponseApp::success(null, '转账成功');
//获取刚刚存入数据库的id(订单号)
$orderId = $withdraw->id;
PaymentNew::pushMoney($money, $userbank->bank_username, $userbank->account, $userbank->bank_name,$orderId);
// var_dump($res);
// //逻辑错误需要修改
// if ($res['Success'] == 200) {
// Withdraw::create([
// 'user_id' => $user_id,
// 'amount' => $money,
// 'status' => 2,
// 'createtime2' => date('Y-m-d H:i:s'),
// 'username' => $user->username,
// 'status_text' => '已到账',
// ]);
// return ApiResponseApp::success(null, '转账成功');
// } else {
// return ApiResponseApp::error(null, '转账失败');
// }
// return ApiResponseApp::success(null, '转账成功');
}
/**
@ -157,17 +170,17 @@ class WithdrawController
$type = $request->post('type');
if ($type == 1) {
$res = Payment::pushMoney($amount, $bank_username, $account, $bank_name);
var_dump($res);
if ($res['Success'] == 200) {
$Withdraw = Withdraw::where('id', $id)->first();
$Withdraw->status = 2;
$Withdraw->status_text = '已到账';
$Withdraw->save();
return ApiResponseApp::success(null, '转账成功');
} else {
return ApiResponseApp::error(null, '转账失败');
}
$res = PaymentNew::pushMoney($amount, $bank_username, $account, $bank_name,$id);
// var_dump($res);
// if ($res['Success'] == 200) {
// $Withdraw = Withdraw::where('id', $id)->first();
// $Withdraw->status = 2;
// $Withdraw->status_text = '已到账';
// $Withdraw->save();
// return ApiResponseApp::success(null, '转账成功');
// } else {
// return ApiResponseApp::error(null, '转账失败');
// }
} else {
$Withdraw = Withdraw::where('id', $id)->first();
$Withdraw->status = 3;
@ -183,4 +196,16 @@ class WithdrawController
return ApiResponseApp::error(null, '操作成功');
}
}
/**
* @Apidoc\Title("请求回调")
* @Apidoc\Url("api/withdraw/callback")
* @Apidoc\Method("GET")
*/
public function callback(Request $request)
{
var_dump(22222222222222222222);
var_dump($request->all());
// Log::info('Withdraw callback received:', $request->all());
}
}