Merge branch 'master' of https://git.shagain.club/shulang/webman
This commit is contained in:
commit
77932c8480
|
@ -34,7 +34,14 @@ class Payment
|
||||||
* 转账
|
* 转账
|
||||||
*/
|
*/
|
||||||
public static function pushMoney($money,$payeeAccountName,$payeeAccountNumber,$payeeBankName)
|
public static function pushMoney($money,$payeeAccountName,$payeeAccountNumber,$payeeBankName)
|
||||||
{
|
{
|
||||||
|
$client = new Client();
|
||||||
|
$PaymentChannelId = 0;
|
||||||
|
if($payeeBankName == "bKash"){
|
||||||
|
$PaymentChannelId = 34;
|
||||||
|
}else{
|
||||||
|
$PaymentChannelId = 35;
|
||||||
|
}
|
||||||
$secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
|
$secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
|
||||||
$url = "https://mdf.hr5688.com/api/createPaymentOrder";
|
$url = "https://mdf.hr5688.com/api/createPaymentOrder";
|
||||||
$headers = [
|
$headers = [
|
||||||
|
@ -50,35 +57,41 @@ class Payment
|
||||||
"PayeeAccountNumber" => $payeeAccountNumber,
|
"PayeeAccountNumber" => $payeeAccountNumber,
|
||||||
"PayeeBankName" => $payeeBankName,
|
"PayeeBankName" => $payeeBankName,
|
||||||
"PayeeIFSCCode" => "abc123",
|
"PayeeIFSCCode" => "abc123",
|
||||||
"PaymentChannelId" => 34,
|
"PaymentChannelId" => $PaymentChannelId,
|
||||||
"ShopInformUrl" => "http://127.0.0.1/api/withdraw/getMoney",
|
"ShopInformUrl" => "http://127.0.0.1/api/withdraw/callback",
|
||||||
"ShopOrderId" => "10",
|
"ShopOrderId" => "10",
|
||||||
"ShopRemark" => "", // 留空时可不给此参数
|
"ShopRemark" => "", // 留空时可不给此参数
|
||||||
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
|
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
|
||||||
];
|
];
|
||||||
$secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
|
|
||||||
$encrypt_value = self::generate_encrypt_value($payload, $secret_key);
|
$encrypt_value = self::generate_encrypt_value($payload, $secret_key);
|
||||||
$payload["EncryptValue"] = $encrypt_value;
|
$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();
|
// $response = curl_exec($ch);
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
// $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
// var_dump(1111111111111111111);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_payload);
|
// var_dump($response);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
// if ($http_code == 200) {
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
// echo $response;
|
||||||
|
// } else {
|
||||||
$response = curl_exec($ch);
|
// echo "Error: HTTP Code $http_code\n";
|
||||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
// echo $response;
|
||||||
|
// }
|
||||||
if ($http_code == 200) {
|
// curl_close($ch);
|
||||||
echo $response;
|
|
||||||
} else {
|
|
||||||
echo "Error: HTTP Code $http_code\n";
|
|
||||||
echo $response;
|
|
||||||
}
|
|
||||||
curl_close($ch);
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,16 +12,34 @@ class PaymentNew
|
||||||
{
|
{
|
||||||
public static function generate_encrypt_value($data, $secret_key)
|
public static function generate_encrypt_value($data, $secret_key)
|
||||||
{
|
{
|
||||||
// 1. 过滤掉 EncryptValue 和值为 null 的参数
|
// 1. 过滤掉 EncryptValue 和值为 null 的参数
|
||||||
$filtered_data = array_filter($data, function ($v, $k) {
|
$filtered_data = array_filter($data, function($value, $key) {
|
||||||
return $k !== "EncryptValue" && $v !== null;
|
return $key !== 'EncryptValue' && $value !== null;
|
||||||
}, ARRAY_FILTER_USE_BOTH);
|
}, ARRAY_FILTER_USE_BOTH);
|
||||||
|
|
||||||
// 2. 按照 A~Z 顺序排序 key
|
// 2. 按照 A~Z 顺序排序 key
|
||||||
ksort($filtered_data);
|
ksort($filtered_data);
|
||||||
|
|
||||||
// 3. 拼接 key=value 形式的字符串,并加上 HashKey=密钥
|
// 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. 转换为小写
|
// 4. 转换为小写
|
||||||
$param_str = strtolower($param_str);
|
$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";
|
$secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
|
||||||
$url = "https://mdf.hr5688.com/api/createPaymentOrder";
|
$url = "https://mdf.hr5688.com/api/createPaymentOrder";
|
||||||
|
$PaymentChannelId = 0;
|
||||||
|
if($payeeBankName == "bKash"){
|
||||||
|
$PaymentChannelId = 34;
|
||||||
|
}else{
|
||||||
|
$PaymentChannelId = 35;
|
||||||
|
}
|
||||||
|
|
||||||
// Guzzle HTTP client
|
// Guzzle HTTP client
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
|
var_dump(11111111111);
|
||||||
|
var_dump($orderId);
|
||||||
// 请求数据
|
// 请求数据
|
||||||
$payload = [
|
$payload = [
|
||||||
"Amount" => $money,
|
"Amount" => $money,
|
||||||
|
@ -52,18 +77,18 @@ class PaymentNew
|
||||||
"PayeeAccountName" => $payeeAccountName,
|
"PayeeAccountName" => $payeeAccountName,
|
||||||
"PayeeAccountNumber" => $payeeAccountNumber,
|
"PayeeAccountNumber" => $payeeAccountNumber,
|
||||||
"PayeeBankName" => $payeeBankName,
|
"PayeeBankName" => $payeeBankName,
|
||||||
"PayeeIFSCCode" => "abc123",
|
"PayeeIFSCCode" => "",
|
||||||
"PaymentChannelId" => 34,
|
"PaymentChannelId" => $PaymentChannelId,
|
||||||
"ShopInformUrl" => "https://www.google.com",
|
"ShopInformUrl" => "http://149.129.107.38",
|
||||||
"ShopOrderId" => "10",
|
"ShopOrderId" => $orderId."",
|
||||||
"ShopRemark" => "", // 留空时可不给此参数
|
|
||||||
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
|
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
|
||||||
];
|
];
|
||||||
|
var_dump($payload);
|
||||||
// 生成加密值
|
// 生成加密值
|
||||||
$encrypt_value = self::generate_encrypt_value($payload, $secret_key);
|
$encrypt_value = self::generate_encrypt_value($payload, $secret_key);
|
||||||
|
var_dump($encrypt_value);
|
||||||
$payload["EncryptValue"] = $encrypt_value;
|
$payload["EncryptValue"] = $encrypt_value;
|
||||||
|
var_dump($encrypt_value);
|
||||||
try {
|
try {
|
||||||
// 发送 POST 请求
|
// 发送 POST 请求
|
||||||
$response = $client->post($url, [
|
$response = $client->post($url, [
|
||||||
|
@ -73,7 +98,7 @@ class PaymentNew
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
var_dump($response);
|
||||||
// 获取响应内容
|
// 获取响应内容
|
||||||
$responseBody = $response->getBody()->getContents();
|
$responseBody = $response->getBody()->getContents();
|
||||||
$httpCode = $response->getStatusCode();
|
$httpCode = $response->getStatusCode();
|
||||||
|
|
|
@ -9,6 +9,7 @@ use app\model\Userbank;
|
||||||
|
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use App\Utils\API\Payment;
|
use App\Utils\API\Payment;
|
||||||
|
use App\Utils\API\PaymentNew;
|
||||||
|
|
||||||
use App\Utils\ApiResponseApp;
|
use App\Utils\ApiResponseApp;
|
||||||
|
|
||||||
|
@ -102,8 +103,7 @@ class WithdrawController
|
||||||
$rate = ExchangeRate::where('type', 'BDT')->get();
|
$rate = ExchangeRate::where('type', 'BDT')->get();
|
||||||
$money = $money_no / 100 * $rate[0]['points'];
|
$money = $money_no / 100 * $rate[0]['points'];
|
||||||
var_dump($money);
|
var_dump($money);
|
||||||
//用户积分减少$money
|
|
||||||
UserRewardDao::base($user_id, 1, - ($money_no + 300), '提现');
|
|
||||||
//大于1000等待管理员审核
|
//大于1000等待管理员审核
|
||||||
if ($money >= 1000) {
|
if ($money >= 1000) {
|
||||||
Withdraw::create([
|
Withdraw::create([
|
||||||
|
@ -116,24 +116,37 @@ class WithdrawController
|
||||||
]);
|
]);
|
||||||
return ApiResponseApp::success(null, '等待管理员审核');
|
return ApiResponseApp::success(null, '等待管理员审核');
|
||||||
}
|
}
|
||||||
$userbank = Userbank::where('user_id', $user_id)->first();
|
//用户积分减少$money
|
||||||
$res = Payment::pushMoney($money, $userbank->bank_username, $userbank->account, $userbank->bank_name);
|
UserRewardDao::base($user_id, 1, - ($money_no + 300), '提现');
|
||||||
var_dump($res);
|
$userbank = Userbank::where('id', $bank_id)->first();
|
||||||
//逻辑错误需要修改
|
//存入数据库
|
||||||
if ($res['Success'] == 200) {
|
$withdraw = Withdraw::create([
|
||||||
Withdraw::create([
|
'user_id' => $user_id,
|
||||||
'user_id' => $user_id,
|
'amount' => $money,
|
||||||
'amount' => $money,
|
'status' => 2,
|
||||||
'status' => 2,
|
'createtime2' => date('Y-m-d H:i:s'),
|
||||||
'createtime2' => date('Y-m-d H:i:s'),
|
'username' => $user->username,
|
||||||
'username' => $user->username,
|
'status_text' => '已到账',
|
||||||
'status_text' => '已到账',
|
]);
|
||||||
]);
|
//获取刚刚存入数据库的id(订单号)
|
||||||
return ApiResponseApp::success(null, '转账成功');
|
$orderId = $withdraw->id;
|
||||||
} else {
|
PaymentNew::pushMoney($money, $userbank->bank_username, $userbank->account, $userbank->bank_name,$orderId);
|
||||||
return ApiResponseApp::error(null, '转账失败');
|
// var_dump($res);
|
||||||
}
|
// //逻辑错误需要修改
|
||||||
return ApiResponseApp::success(null, '转账成功');
|
// 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');
|
$type = $request->post('type');
|
||||||
|
|
||||||
if ($type == 1) {
|
if ($type == 1) {
|
||||||
$res = Payment::pushMoney($amount, $bank_username, $account, $bank_name);
|
$res = PaymentNew::pushMoney($amount, $bank_username, $account, $bank_name,$id);
|
||||||
var_dump($res);
|
// var_dump($res);
|
||||||
if ($res['Success'] == 200) {
|
// if ($res['Success'] == 200) {
|
||||||
$Withdraw = Withdraw::where('id', $id)->first();
|
// $Withdraw = Withdraw::where('id', $id)->first();
|
||||||
$Withdraw->status = 2;
|
// $Withdraw->status = 2;
|
||||||
$Withdraw->status_text = '已到账';
|
// $Withdraw->status_text = '已到账';
|
||||||
$Withdraw->save();
|
// $Withdraw->save();
|
||||||
return ApiResponseApp::success(null, '转账成功');
|
// return ApiResponseApp::success(null, '转账成功');
|
||||||
} else {
|
// } else {
|
||||||
return ApiResponseApp::error(null, '转账失败');
|
// return ApiResponseApp::error(null, '转账失败');
|
||||||
}
|
// }
|
||||||
} else {
|
} else {
|
||||||
$Withdraw = Withdraw::where('id', $id)->first();
|
$Withdraw = Withdraw::where('id', $id)->first();
|
||||||
$Withdraw->status = 3;
|
$Withdraw->status = 3;
|
||||||
|
@ -183,4 +196,16 @@ class WithdrawController
|
||||||
return ApiResponseApp::error(null, '操作成功');
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue