You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

73 lines
2.5 KiB

<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Models\Mongodb\UdunTrade;
use App\Models\Withdraw;
use Illuminate\Http\Request;
class UdunWalletController extends ApiController
{
// 优盾钱包回调
public function notify(Request $request)
{
$res = $request->all();
$res = array(
'timestamp' => (string) $_POST['timestamp'],
'nonce' => (string) $_POST['nonce'],
'sign' => (string) $_POST['sign'],
'body' => (string) $_POST['body'],
);
file_put_contents("storage/call_back_data.txt", "\n" . date('Y-m-d H:i:s') . $res['body'] . "\n", FILE_APPEND);
if (blank($res)) {
info('=====优盾钱包回调通知验签失败1======', $res);
return;
}
// 先验签
$sign = md5($res['body'] . config('coin.api_key', '9157063a15a3bc133ee2c6866057d77f') . $res['nonce'] . $res['timestamp']);
if ($res['sign'] != $sign) {
info('=====优盾钱包回调通知验签失败2======', $res);
}
$trade = json_decode($res['body'], true);
//TODO 业务处理
if ($trade['tradeType'] == 1) {
info('=====收到充币通知======', $trade);
if ($trade['status'] == 3) {
// 交易成功
\App\Jobs\UdunDeposit::dispatch($trade)->onQueue('UdunDeposit'); // 充值
}
} elseif ($trade['tradeType'] == 2) {
info('=====收到提币通知======', $trade);
$withdrawId = str_before($trade['businessId'], '-');
$withdraw = Withdraw::query()->find($withdrawId);
if (blank($withdraw)) {
info('===优盾钱包提币记录找不到===');
} else {
if ($trade['status'] == 1) {
// 审核通过,转账中
$withdraw->update(['status' => Withdraw::status_pass]);
} elseif ($trade['status'] == 2) {
// 审核不通过
$withdraw->update(['status' => Withdraw::status_reject]);
} elseif ($trade['status'] == 3) {
// 提币已到账
$withdraw->update(['status' => Withdraw::status_success]);
} elseif ($trade['status'] == 4) {
// 交易失败
$withdraw->update(['status' => Withdraw::status_failed]);
}
}
}
return "success";
}
}