$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); // 5. 计算 sha256 哈希 $hash_value = hash('sha256', $param_str); // 6. 转换为大写返回 return strtoupper($hash_value); } /** * 转账 */ 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(); // 请求数据 $payload = [ "Amount" => $money, "CurrencyId" => 11, "IsTest" => false, "PayeeAccountName" => $payeeAccountName, "PayeeAccountNumber" => $payeeAccountNumber, "PayeeBankName" => $payeeBankName, "PayeeIFSCCode" => "", "PaymentChannelId" => $PaymentChannelId, "ShopInformUrl" => "http://149.129.107.38/", "ShopOrderId" => $orderId, "ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95" ]; // 生成加密值 $encrypt_value = self::generate_encrypt_value($payload, $secret_key); $payload["EncryptValue"] = $encrypt_value; try { // 发送 POST 请求 $response = $client->post($url, [ 'json' => $payload, 'headers' => [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', ] ]); var_dump($response); // 获取响应内容 $responseBody = $response->getBody()->getContents(); $httpCode = $response->getStatusCode(); if ($httpCode == 200) { echo $responseBody; } else { echo "Error: HTTP Code $httpCode\n"; echo $responseBody; } return $responseBody; } catch (\GuzzleHttp\Exception\RequestException $e) { echo "Request failed: " . $e->getMessage(); } } }