USDT自动上分是通过官方 https://api.trongrid.io 查询接口实现的
在给一个客户做大富彩票自动充值的时候保存的代码,分享给有需要的朋友,不用再去找网上那些带后门的程序了,当然前提是 你得会PHP
只是一个前端充值自动查询并处理的代码,仅供参考,需要前端传参(订单号)后才能进行处理,同样数据库字段也得处理
代码如下:
<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.我们不作任何承诺,也不保证100%可使用,开通会员或充值后,本站不支持任何退款理由.
THE END