usdt充值btc网络(非节点钱包地址)

1.此充值具有一定的交易风险(请一定做好判断)

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

下边是数据表设计:

CREATE TABLE `yy_recharge` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL COMMENT '用户id',
  `order_num` varchar(255) DEFAULT NULL COMMENT '充值单号',
  `usdt_order_num` varchar(255) DEFAULT NULL COMMENT 'USDT交易单号',
  `money` decimal(18,8) NOT NULL DEFAULT '0.00000000' COMMENT '充值金额',
  `sender` varchar(255) DEFAULT NULL COMMENT '充值地址',
  `recipient` varchar(255) DEFAULT NULL COMMENT '接受地址',
  `status` tinyint(4) DEFAULT '1' COMMENT '状态:1=确认中,2=确认成功,3=确认失败',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `qr_time` datetime DEFAULT NULL COMMENT '确认时间',
  `block_time` datetime DEFAULT NULL COMMENT '区块交易时间',
  `block_t_time` varchar(255) DEFAULT '' COMMENT '区块交易时间戳',
  `remarks` varchar(255) DEFAULT NULL COMMENT '描述',
  PRIMARY KEY (`id`),
  UNIQUE KEY `ordernum` (`order_num`)
) ENGINE=InnoDB AUTO_INCREMENT=145 DEFAULT CHARSET=utf8;

omni_gettransaction

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

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

    /**
     * 获取交易详情
     * @return mixed
     */
    function gettransaction($txid){
        return $this->usdt->omni_gettransaction($txid);
    }

  ["txid"] => string(64) "c41525d0de0b5d5668f44995570184e6a4c52931a0ebb7e10205676f6bb9a40f"//16进制编码的交易哈希
  ["fee"] => string(10) "0.00015975"//手续费
  ["sendingaddress"] => string(34) "3KeC2JqGHqW6kuUBJKjAHmmfUThj2RiR1F"//发送方
  ["referenceaddress"] => string(34) "18An5WWLHR59NpHdKzPoDjKLKULsMpP1ci"//接受方
  ["ismine"] => bool(true)//交易是否与钱包内某个地址相关
  ["version"] => int(0)
  ["type_int"] => int(0)
  ["type"] => string(11) "Simple Send"
  ["propertyid"] => int(31)
  ["divisible"] => bool(true)
  ["amount"] => string(10) "0.10000000"//转账金额
  ["valid"] => bool(true)//交易是否有效
  ["blockhash"] => string(64) "0000000000000000000158c6c5f5f58f912a03c9b4d6af383e9f727203ab4e1e"
  ["blocktime"] => int(1560766900)//区块时间戳
  ["positioninblock"] => int(931)
  ["block"] => int(581098)
  ["confirmations"] => int(36)//区块确认书

 

 最后就是做个定时器,定时扫描钱包地址,出现新的交易然后存入数据库。

如果不会写定时器,请参考我前段时间写的定时器:https://blog.csdn.net/jmkweb/article/details/89684225

下边附上定时扫描钱包,确认充值成功

<?php
/**
 * Created by PhpStorm.
 * User: 江雪
 * Date: 2019/6/6
 * Time: 17:58
 */

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);
            }
        });
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦夏夜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值