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()); + } }