From c02820f59e97c1595651a01c974ed609ebf884a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=8B=BC?= <2468023037@qq.com> Date: Tue, 18 Feb 2025 17:22:37 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E8=BD=AC=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Utils/API/Payment.php | 57 +++++++++++++--------- app/Utils/API/PaymentNew.php | 47 ++++++++++++++---- app/controller/api/WithdrawController.php | 58 +++++++++++++++-------- 3 files changed, 110 insertions(+), 52 deletions(-) diff --git a/app/Utils/API/Payment.php b/app/Utils/API/Payment.php index 4abcf77..face383 100644 --- a/app/Utils/API/Payment.php +++ b/app/Utils/API/Payment.php @@ -34,7 +34,14 @@ 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; } } diff --git a/app/Utils/API/PaymentNew.php b/app/Utils/API/PaymentNew.php index 2371cfc..202e7f7 100644 --- a/app/Utils/API/PaymentNew.php +++ b/app/Utils/API/PaymentNew.php @@ -12,16 +12,34 @@ 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; + // 1. 过滤掉 EncryptValue 和值为 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); @@ -40,6 +58,12 @@ class PaymentNew { $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(); @@ -52,18 +76,20 @@ class PaymentNew "PayeeAccountName" => $payeeAccountName, "PayeeAccountNumber" => $payeeAccountNumber, "PayeeBankName" => $payeeBankName, - "PayeeIFSCCode" => "abc123", - "PaymentChannelId" => 34, - "ShopInformUrl" => "https://www.google.com", + "PayeeIFSCCode" => "", + "PaymentChannelId" => $PaymentChannelId, + "ShopInformUrl" => "http://127.0.0.1:8787/api/withdraw/callback", "ShopOrderId" => "10", - "ShopRemark" => "", // 留空时可不给此参数 "ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95" ]; // 生成加密值 $encrypt_value = self::generate_encrypt_value($payload, $secret_key); $payload["EncryptValue"] = $encrypt_value; - + var_dump($payload); + var_dump(111111111); + + var_dump($payload["EncryptValue"]); try { // 发送 POST 请求 $response = $client->post($url, [ @@ -73,7 +99,8 @@ class PaymentNew 'Content-Type' => 'application/json', ] ]); - + var_dump(11111111111111); + var_dump($response); // 获取响应内容 $responseBody = $response->getBody()->getContents(); $httpCode = $response->getStatusCode(); diff --git a/app/controller/api/WithdrawController.php b/app/controller/api/WithdrawController.php index 3f94bb2..ede26e6 100644 --- a/app/controller/api/WithdrawController.php +++ b/app/controller/api/WithdrawController.php @@ -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,24 +116,30 @@ 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([ - '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, '转账成功'); + //用户积分减少$money + // UserRewardDao::base($user_id, 1, - ($money_no + 300), '提现'); + $userbank = Userbank::where('id', $bank_id)->first(); + var_dump($money); + var_dump($userbank->bank_username); + var_dump($userbank->account); + var_dump($userbank->bank_name); + $res = PaymentNew::pushMoney($money, $userbank->bank_username, $userbank->account, $userbank->bank_name); + // 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, '转账成功'); } /** @@ -183,4 +189,16 @@ class WithdrawController return ApiResponseApp::error(null, '操作成功'); } } + + /** + * @Apidoc\Title("请求回调") + * @Apidoc\Url("api/withdraw/callback") + * @Apidoc\Method("POST") + */ + public function callback(Request $request) + { + var_dump(22222222222222222222); + var_dump($request->all()); + // Log::info('Withdraw callback received:', $request->all()); + } } From c77b941c91725d18a3dd71bc907c35455fb394c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=8B=BC?= <2468023037@qq.com> Date: Tue, 18 Feb 2025 17:27:56 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Utils/API/PaymentNew.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Utils/API/PaymentNew.php b/app/Utils/API/PaymentNew.php index 202e7f7..7962885 100644 --- a/app/Utils/API/PaymentNew.php +++ b/app/Utils/API/PaymentNew.php @@ -78,7 +78,7 @@ class PaymentNew "PayeeBankName" => $payeeBankName, "PayeeIFSCCode" => "", "PaymentChannelId" => $PaymentChannelId, - "ShopInformUrl" => "http://127.0.0.1:8787/api/withdraw/callback", + "ShopInformUrl" => "http://149.129.107.38/", "ShopOrderId" => "10", "ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95" ]; From ebb195aacb60583811a3fd17f52540a0087efd46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=8B=BC?= <2468023037@qq.com> Date: Tue, 18 Feb 2025 17:45:10 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=E8=BD=AC=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Utils/API/PaymentNew.php | 7 +------ app/controller/api/WithdrawController.php | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/Utils/API/PaymentNew.php b/app/Utils/API/PaymentNew.php index 7962885..33e4db0 100644 --- a/app/Utils/API/PaymentNew.php +++ b/app/Utils/API/PaymentNew.php @@ -79,17 +79,13 @@ class PaymentNew "PayeeIFSCCode" => "", "PaymentChannelId" => $PaymentChannelId, "ShopInformUrl" => "http://149.129.107.38/", - "ShopOrderId" => "10", + "ShopOrderId" => "11", "ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95" ]; // 生成加密值 $encrypt_value = self::generate_encrypt_value($payload, $secret_key); $payload["EncryptValue"] = $encrypt_value; - var_dump($payload); - var_dump(111111111); - - var_dump($payload["EncryptValue"]); try { // 发送 POST 请求 $response = $client->post($url, [ @@ -99,7 +95,6 @@ class PaymentNew 'Content-Type' => 'application/json', ] ]); - var_dump(11111111111111); var_dump($response); // 获取响应内容 $responseBody = $response->getBody()->getContents(); diff --git a/app/controller/api/WithdrawController.php b/app/controller/api/WithdrawController.php index ede26e6..bac89da 100644 --- a/app/controller/api/WithdrawController.php +++ b/app/controller/api/WithdrawController.php @@ -163,7 +163,7 @@ class WithdrawController $type = $request->post('type'); if ($type == 1) { - $res = Payment::pushMoney($amount, $bank_username, $account, $bank_name); + $res = PaymentNew::pushMoney($amount, $bank_username, $account, $bank_name); var_dump($res); if ($res['Success'] == 200) { $Withdraw = Withdraw::where('id', $id)->first(); @@ -193,7 +193,7 @@ class WithdrawController /** * @Apidoc\Title("请求回调") * @Apidoc\Url("api/withdraw/callback") - * @Apidoc\Method("POST") + * @Apidoc\Method("GET") */ public function callback(Request $request) { From e21ca4d47cbb11b196390c6dfe100300c7682456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=8B=BC?= <2468023037@qq.com> Date: Tue, 18 Feb 2025 17:50:13 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Utils/API/PaymentNew.php | 4 +-- app/controller/api/WithdrawController.php | 43 +++++++++++++---------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/app/Utils/API/PaymentNew.php b/app/Utils/API/PaymentNew.php index 33e4db0..0d09b1c 100644 --- a/app/Utils/API/PaymentNew.php +++ b/app/Utils/API/PaymentNew.php @@ -54,7 +54,7 @@ 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"; @@ -79,7 +79,7 @@ class PaymentNew "PayeeIFSCCode" => "", "PaymentChannelId" => $PaymentChannelId, "ShopInformUrl" => "http://149.129.107.38/", - "ShopOrderId" => "11", + "ShopOrderId" => $orderId, "ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95" ]; diff --git a/app/controller/api/WithdrawController.php b/app/controller/api/WithdrawController.php index bac89da..295a2ea 100644 --- a/app/controller/api/WithdrawController.php +++ b/app/controller/api/WithdrawController.php @@ -117,13 +117,20 @@ class WithdrawController return ApiResponseApp::success(null, '等待管理员审核'); } //用户积分减少$money - // UserRewardDao::base($user_id, 1, - ($money_no + 300), '提现'); - $userbank = Userbank::where('id', $bank_id)->first(); - var_dump($money); - var_dump($userbank->bank_username); - var_dump($userbank->account); - var_dump($userbank->bank_name); - $res = PaymentNew::pushMoney($money, $userbank->bank_username, $userbank->account, $userbank->bank_name); + UserRewardDao::base($user_id, 1, - ($money_no + 300), '提现'); + $userbank = Userbank::where('id', $bank_id)->first();\ + //存入数据库 + Withdraw::create([ + 'user_id' => $user_id, + 'amount' => $money, + 'status' => 2, + 'createtime2' => date('Y-m-d H:i:s'), + 'username' => $user->username, + 'status_text' => '已到账', + ]); + //获取刚刚存入数据库的id(订单号) + $orderId = $withdraw->id; + PaymentNew::pushMoney($money, $userbank->bank_username, $userbank->account, $userbank->bank_name,$orderId); // var_dump($res); // //逻辑错误需要修改 // if ($res['Success'] == 200) { @@ -163,17 +170,17 @@ class WithdrawController $type = $request->post('type'); if ($type == 1) { - $res = PaymentNew::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; From 9fc94bcd9154acc50426ad95dfaad05901fe2b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=8B=BC?= <2468023037@qq.com> Date: Tue, 18 Feb 2025 19:44:57 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E8=BD=AC?= =?UTF-8?q?=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Utils/API/PaymentNew.php | 11 +++++++---- app/controller/api/WithdrawController.php | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Utils/API/PaymentNew.php b/app/Utils/API/PaymentNew.php index 0d09b1c..3f8761f 100644 --- a/app/Utils/API/PaymentNew.php +++ b/app/Utils/API/PaymentNew.php @@ -67,7 +67,8 @@ class PaymentNew // Guzzle HTTP client $client = new Client(); - + var_dump(11111111111); + var_dump($orderId); // 请求数据 $payload = [ "Amount" => $money, @@ -78,14 +79,16 @@ class PaymentNew "PayeeBankName" => $payeeBankName, "PayeeIFSCCode" => "", "PaymentChannelId" => $PaymentChannelId, - "ShopInformUrl" => "http://149.129.107.38/", - "ShopOrderId" => $orderId, + "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, [ diff --git a/app/controller/api/WithdrawController.php b/app/controller/api/WithdrawController.php index 295a2ea..6863d01 100644 --- a/app/controller/api/WithdrawController.php +++ b/app/controller/api/WithdrawController.php @@ -118,9 +118,9 @@ class WithdrawController } //用户积分减少$money UserRewardDao::base($user_id, 1, - ($money_no + 300), '提现'); - $userbank = Userbank::where('id', $bank_id)->first();\ + $userbank = Userbank::where('id', $bank_id)->first(); //存入数据库 - Withdraw::create([ + $withdraw = Withdraw::create([ 'user_id' => $user_id, 'amount' => $money, 'status' => 2,