Compare commits
2 Commits
ce8a9ee864
...
0f69802c25
Author | SHA1 | Date |
---|---|---|
|
0f69802c25 | |
|
3ace17af4d |
|
@ -9,15 +9,40 @@ use GuzzleHttp\Client;
|
||||||
*/
|
*/
|
||||||
class Payment
|
class Payment
|
||||||
{
|
{
|
||||||
|
function generate_encrypt_value($data, $secret_key) {
|
||||||
|
// 1. 过滤掉 EncryptValue 和值为 null 的参数
|
||||||
|
$filtered_data = array_filter($data, function($v, $k) {
|
||||||
|
return $k !== "EncryptValue" && $v !== 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";
|
||||||
|
|
||||||
|
// 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)
|
public static function pushMoney($money,$payeeAccountName,$payeeAccountNumber,$payeeBankName)
|
||||||
{
|
{
|
||||||
$client = new Client(); // 创建 Guzzle 客户端
|
$secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
|
||||||
|
$url = "https://mdf.hr5688.com/api/createPaymentOrder";
|
||||||
|
$headers = [
|
||||||
|
"accept" => "application/json",
|
||||||
|
"content-type" => "application/json"
|
||||||
|
];
|
||||||
// 请求数据
|
// 请求数据
|
||||||
$data = [
|
$payload = [
|
||||||
"Amount" => $money,
|
"Amount" => $money,
|
||||||
"CurrencyId" => 11,
|
"CurrencyId" => 11,
|
||||||
"IsTest" => false,
|
"IsTest" => false,
|
||||||
|
@ -31,15 +56,29 @@ class Payment
|
||||||
"ShopRemark" => "", // 留空时可不给此参数
|
"ShopRemark" => "", // 留空时可不给此参数
|
||||||
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
|
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
|
||||||
];
|
];
|
||||||
|
$secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
|
||||||
|
$encrypt_value = Payment::generate_encrypt_value($payload, $secret_key);
|
||||||
|
$payload["EncryptValue"] = $encrypt_value;
|
||||||
|
|
||||||
// 发送 POST 请求
|
$json_payload = json_encode($payload);
|
||||||
$response = $client->post('https://example.com/api/createPaymentOrder', [
|
|
||||||
'json' => $data, // 以 JSON 格式发送数据
|
|
||||||
]);
|
|
||||||
|
|
||||||
// 获取响应体内容
|
$ch = curl_init();
|
||||||
$body = $response->getBody();
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
return $responseData;
|
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);
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue