usdt 充值购买实现(下单再转入USDT形式)

时间:2020-07-30作者:klpeng分类:区块链技术浏览:1476评论:0

步骤:用户绑定其他交易所的地址,往平台充值(只能使用用户绑定的钱包地址充值,否则无法确认充值成功),用户先填写充值金额->生成充值订单->通过平台设置的收币钱包地址充值->填写充值产生的hash值->根据hash值查询转账是否确认成功


主要利用

omni_gettransaction

omni_gettransaction调用获取指定Omni交易的详细信息。

 txid:交易哈希,字符串,必需

定时扫描脚本:

<?php
 
namespace app\common\controller;
 
#充值扫描
use app\admin\controller\usdts\Coins;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Exception;
 
class Recharge extends Command
{
    protected function configure()
    {
        $this->setName('recharge')
            ->setDescription('usdt充值');
    }
 
    protected function execute(Input $input, Output $output)
    {
        //每隔1000ms触发一次
        $id = \swoole_timer_tick(5000, function ($timer_id) {
            try{
//                file_put_contents('recharge.log',date('Y-m-d H:i:s').'进入定时'.PHP_EOL,FILE_APPEND);
                $recharge=Db::name('recharge')->where(['status'=>1,'usdt_order_num'=>['<>','']])->select();
                foreach ($recharge as $v){
                    file_put_contents('recharge.log',date('Y-m-d H:i:s').'进入充值--'.$v['user_id'].'--ID--'.$v['id'].PHP_EOL,FILE_APPEND);
//                    $post['query']=$v['usdt_order_num'];
                    $usdt=(new Coins())->getCoins();
                    $rc=$usdt->omni_gettransaction($v['usdt_order_num']);
                    if (!is_array($rc)){
                        $message='交易hash错误';
                        goto STOP;
                        continue;
                    }
                    file_put_contents('recharge.log',date('Y-m-d H:i:s').json_encode($rc).PHP_EOL,FILE_APPEND);
                    $message='';
                    if (!empty($rc)){
                        if ($rc['amount']!=$v['money']){
                            $message='充值金额错误';
                            goto STOP;
                            continue;
                        }
                        #判断充值时间是否大于创建时间
                        $create_time=strtotime($v['create_time']);
                        if ($rc['blocktime']<$create_time){
                            $message='充值时间异常';
                            goto STOP;
                            continue;
                        }
                        if (!$rc['valid']){
                            $message='区块确认异常';
                            goto STOP;
                            continue;
                        }
//                        if ($rc['sendingaddress']!=$v['sender']){
//                            $message='充值地址异常';
//                            goto STOP;
//                            continue;
//                        }
                        if ($rc['referenceaddress']!=$v['recipient']){
                            $message='接受地址异常';
                            goto STOP;
                            continue;
                        }
                        #判断交易是否有效
//                    if (!$rc->valid){
//                        continue;
//                    }
                        if ($rc['valid']){
                            file_put_contents('recharge.log',date('Y-m-d H:i:s').'充值成功--'.$v['user_id'].'--ID--'.$v['id'].PHP_EOL,FILE_APPEND);
                            #交易成功
                            Db::name('recharge')->where(['id'=>$v['id']])->update(['status'=>2,'qr_time'=>date('YmdHis'),'block_t_time'=>$rc['blocktime'],'block_time'=>date('Y-m-d H:i:s',$rc['blocktime'])]);
                            Db::name('users_asset')->where(['user_id'=>$v['user_id']])->setInc('usdt',$v['money']);
                            $log=[
                                'user_id'=>$v['user_id'],
                                'money'=>$v['money'],
                                'type'=>1,
                                'message'=>'充值',
                                'status'=>2,
                                'class'=>2,
                                'create_time'=>date('YmdHis')
                            ];
                            Db::name('users_account_log')->insert($log);
                        }else{
                            STOP:
                            file_put_contents('recharge.log',date('Y-m-d H:i:s').'--'.$message.'--充值失败--'.$v['user_id'].'--ID--'.$v['id'].PHP_EOL,FILE_APPEND);
                            Db::name('recharge')->where(['id'=>$v['id']])->update(['status'=>3,'remarks'=>$message]);
                        }
                    }
                }
//                file_put_contents('recharge.log',date('Y-m-d H:i:s').'退出定时'.PHP_EOL,FILE_APPEND);
            }catch (Exception $exception){
                file_put_contents('recharge.log',date('Y-m-d H:i:s').$exception->getMessage().PHP_EOL,FILE_APPEND);
            }
        });
    }
}


打赏
文章版权声明:除非注明,否则均为彭超的博客原创文章,转载或复制请以超链接形式并注明出处。
相关推荐

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

猜你喜欢