超实用教程|USDT-TRC20波场链自动充值上分教程

分类:教程/文档 时间: 2024-11-10 14:14 浏览:0

USDT自动上分是通过官方 https://api.trongrid.io 查询接口实现的

在给一个客户做大富彩票自动充值的时候保存的代码,分享给有需要的朋友,不用再去找网上那些带后门的程序了,当然前提是 你得会PHP

只是一个前端充值自动查询并处理的代码,仅供参考,需要前端传参(订单号)后才能进行处理,同样数据库字段也得处理

image.png

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">timibbs_usdtautopay</span>(<span class="hljs-params"><span class="hljs-variable">$apiparam</span>=<span class="hljs-keyword">array</span>(<span class="hljs-params"></span>)</span>)</span>{

    <span class="hljs-variable">$apiparam</span> = <span class="hljs-built_in">self</span>::<span class="hljs-title function_ invoke__">_cheacktoken</span>(<span class="hljs-variable">$apiparam</span>);

    <span class="hljs-keyword">if</span>(!<span class="hljs-variable">$apiparam</span>[<span class="hljs-string">'sign'</span>])<span class="hljs-keyword">return</span> <span class="hljs-variable">$apiparam</span>;

    <span class="hljs-variable">$trano</span> = <span class="hljs-variable">$apiparam</span>[<span class="hljs-string">'trano'</span>];

    <span class="hljs-variable">$payorder</span> = <span class="hljs-title function_ invoke__">M</span>(<span class="hljs-string">'recharge'</span>)-><span class="hljs-title function_ invoke__">where</span>([<span class="hljs-string">'trano'</span>=><span class="hljs-variable">$trano</span>,<span class="hljs-string">'state'</span>=><span class="hljs-number">0</span>])-><span class="hljs-title function_ invoke__">find</span>();

 

        <span class="hljs-comment">//查询平台收款地址</span>

        <span class="hljs-variable">$usdtpayaddress</span> = <span class="hljs-title function_ invoke__">M</span>(<span class="hljs-string">'payset'</span>)-><span class="hljs-title function_ invoke__">field</span>(<span class="hljs-string">"ftitle"</span>)-><span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">"isonline=-1 AND state=1 AND paytype='USDT'"</span>)-><span class="hljs-title function_ invoke__">find</span>();

        <span class="hljs-variable">$to_address</span> = <span class="hljs-variable">$usdtpayaddress</span>[<span class="hljs-string">'ftitle'</span>];

     

    <span class="hljs-comment">//获取地址交易记录</span>

        <span class="hljs-variable">$url</span> = <span class="hljs-string">"https://api.trongrid.io/v1/accounts/<span class="hljs-subst">$to_address</span>/transactions/trc20?limit=10&contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"</span>;

        <span class="hljs-variable">$getData</span> = <span class="hljs-title function_ invoke__">file_get_contents</span>(<span class="hljs-variable">$url</span>);

        <span class="hljs-variable">$jsonData</span> = <span class="hljs-title function_ invoke__">json_decode</span>(<span class="hljs-variable">$getData</span>,<span class="hljs-literal">true</span>);

 

        <span class="hljs-comment">//循环查询链上记录</span>

        <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$jsonData</span>[<span class="hljs-string">"data"</span>] <span class="hljs-keyword">as</span> <span class="hljs-variable">$k</span>=><span class="hljs-variable">$v</span>){

            <span class="hljs-comment">//这里注释掉了,单一订单查询没必要循环所有订单</span>

            <span class="hljs-comment">// foreach ($payorder as $a=>$b){</span>

                <span class="hljs-variable">$from_address</span> = <span class="hljs-variable">$payorder</span>[<span class="hljs-string">"from_address"</span>];

            <span class="hljs-variable">$usdtnum</span> = <span class="hljs-variable">$payorder</span>[<span class="hljs-string">"usdtnum"</span>];

 

                <span class="hljs-comment">//转账时间必须大于创建订单时间</span>

                <span class="hljs-keyword">if</span>(<span class="hljs-variable">$v</span>[<span class="hljs-string">'block_timestamp'</span>]/<span class="hljs-number">1000</span> > <span class="hljs-variable">$payorder</span>[<span class="hljs-string">'oddtime'</span>]){

 

                    <span class="hljs-comment">//转账地址、数量完全匹配</span>

                    <span class="hljs-keyword">if</span>(<span class="hljs-variable">$v</span>[<span class="hljs-string">'to'</span>] == <span class="hljs-variable">$to_address</span> && <span class="hljs-variable">$v</span>[<span class="hljs-string">'from'</span>] == <span class="hljs-variable">$from_address</span> && <span class="hljs-variable">$v</span>[<span class="hljs-string">'value'</span>]/<span class="hljs-number">1000000</span> == <span class="hljs-variable">$usdtnum</span>){

                        <span class="hljs-variable">$userinfo</span> = <span class="hljs-title function_ invoke__">M</span>(<span class="hljs-string">'member'</span>)-><span class="hljs-title function_ invoke__">where</span>([<span class="hljs-string">'id'</span>=><span class="hljs-variable">$payorder</span>[<span class="hljs-string">'uid'</span>]])-><span class="hljs-title function_ invoke__">find</span>();

                        <span class="hljs-variable">$add</span>[<span class="hljs-string">'oldaccountmoney'</span>] = <span class="hljs-variable">$userinfo</span>[<span class="hljs-string">"balance"</span>];

                        <span class="hljs-variable">$add</span>[<span class="hljs-string">'newaccountmoney'</span>] = <span class="hljs-variable">$userinfo</span>[<span class="hljs-string">"balance"</span>] + <span class="hljs-variable">$payorder</span>[<span class="hljs-string">'amount'</span>];

                        <span class="hljs-variable">$add</span>[<span class="hljs-string">'state'</span>] = <span class="hljs-number">1</span>;

                        <span class="hljs-variable">$add</span>[<span class="hljs-string">'transaction_id'</span>] = <span class="hljs-variable">$v</span>[<span class="hljs-string">"transaction_id"</span>];<span class="hljs-comment">//哈希值</span>

                        <span class="hljs-title function_ invoke__">M</span>(<span class="hljs-string">'recharge'</span>)-><span class="hljs-title function_ invoke__">where</span>([<span class="hljs-string">'trano'</span>=><span class="hljs-variable">$trano</span>])-><span class="hljs-title function_ invoke__">setField</span>(<span class="hljs-variable">$add</span>);

 

                        <span class="hljs-comment">//如果上链有数据了就增加余额</span>

                        <span class="hljs-title function_ invoke__">M</span>(<span class="hljs-string">'member'</span>)-><span class="hljs-title function_ invoke__">where</span>([<span class="hljs-string">'id'</span>=><span class="hljs-variable">$payorder</span>[<span class="hljs-string">'uid'</span>]])-><span class="hljs-title function_ invoke__">setInc</span>(<span class="hljs-string">'balance'</span>,<span class="hljs-variable">$payorder</span>[<span class="hljs-string">'amount'</span>]);

 

                        <span class="hljs-comment">//返回</span>

                    <span class="hljs-variable">$return</span>[<span class="hljs-string">'sign'</span>] = <span class="hljs-literal">true</span>;

                    <span class="hljs-variable">$return</span>[<span class="hljs-string">'state'</span>] = <span class="hljs-number">1</span>;

                    <span class="hljs-variable">$return</span>[<span class="hljs-string">'message'</span>] = <span class="hljs-string">'充值成功!'</span>;

                    <span class="hljs-keyword">return</span> <span class="hljs-variable">$return</span>;<span class="hljs-keyword">exit</span>;

                    }

                }<span class="hljs-keyword">else</span>{

                    <span class="hljs-variable">$return</span>[<span class="hljs-string">'sign'</span>] = <span class="hljs-literal">false</span>;

                <span class="hljs-variable">$return</span>[<span class="hljs-string">'message'</span>] = <span class="hljs-string">'未发现订单!'</span>;

                <span class="hljs-keyword">return</span> <span class="hljs-variable">$return</span>;

                }

            <span class="hljs-comment">// }</span>

        } 

}

1. 本站所有资源来源于用户上传或网络,仅作为参考研究使用,如有侵权请邮件联系站长!
2. 本站积分货币获取途径以及用途的解读,想在本站混的好,请务必认真阅读!
3. 本站强烈打击盗版/破解等有损他人权益和违法作为,请各位会员支持正版!
4. 教程/文档 > 超实用教程|USDT-TRC20波场链自动充值上分教程