用php编写一个以太坊支付系统
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">php以太坊,<span style="color: black;">重点</span>是介绍<span style="color: black;">运用</span>php进行智能合约<span style="color: black;">研发</span>交互,进行账号创建、交易、转账、代币<span style="color: black;">研发</span>以及过滤器和事件等内容。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">当我<span style="color: black;">第1</span>次<span style="color: black;">思虑</span><span style="color: black;">经过</span>加密货币实施支付时,我查看了像Stripe<span style="color: black;">这般</span>的可用<span style="color: black;">处理</span><span style="color: black;">方法</span>。我觉得Stripe的问题在于,它只<span style="color: black;">准许</span><span style="color: black;">运用</span>美国商家帐户进行比特币支付,<span style="color: black;">因此</span>这对我<span style="color: black;">来讲</span>不是一个<span style="color: black;">选取</span>。在以太坊世界,它看起来更糟糕。有<span style="color: black;">有些</span>较新的服务,但<span style="color: black;">她们</span><span style="color: black;">皆想</span>要分享蛋糕。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">那样</span>从头<span style="color: black;">起始</span>构建以太坊支付系统,<span style="color: black;">咱们</span><span style="color: black;">必须</span>什么?</p>运行PHP的Web服务器。启用了RPC的专用网络中<span style="color: black;">最少</span>有一个Parity节点。网络服务器上的虚拟<span style="color: black;">位置</span>生成器,如vanity-eth。<h3 style="color: black; text-align: left; margin-bottom: 10px;">那它是<span style="color: black;">怎样</span>工作的?</h3><span style="color: black;">运用</span>coinbase或kraken API中的当前价格计算ETH的价格。<span style="color: black;">运用</span>虚拟生成器生成<span style="color: black;">位置</span>对,并将私钥加密或转移到另一个服务器。<span style="color: black;">表示</span>生成的<span style="color: black;">位置</span>给客户,<span style="color: black;">倘若</span>收到付款,则每隔几秒<span style="color: black;">检测</span>一次<span style="color: black;">位置</span>。<h3 style="color: black; text-align: left; margin-bottom: 10px;">理论上似乎是<span style="color: black;">无</span>问题的,那让<span style="color: black;">咱们</span>构建它。</h3>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">第1步:设置服务器</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>将<span style="color: black;">运用</span>nodejs中的vanity-eth来生成<span style="color: black;">位置</span>。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">npm</span> <span style="color: black;">install</span> <span style="color: black;">-</span><span style="color: black;">g</span> <span style="color: black;">vanity</span><span style="color: black;">-</span><span style="color: black;">eth</span><span style="color: black;">@</span><span style="color: black;">1.0</span><span style="color: black;">.</span><span style="color: black;">4</span><span style="color: black;">"
</span></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在Windows上安装vanity-eth后:</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic2.zhimg.com/80/v2-69cde892c769daee39dedcfc656e15c5_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">还<span style="color: black;">必须</span><span style="color: black;">有些</span>Etherum节点。我正在<span style="color: black;">运用</span>Parity,<span style="color: black;">由于</span>它快速<span style="color: black;">靠谱</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">运用</span>这些参数<span style="color: black;">起步</span>它,但不要将节点直接暴露给Internet,将它们<span style="color: black;">保存</span>在防火墙后面而不进行端口转发。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">parity --jsonrpc-interface 0.0.0.0 --jsonrpc-hosts="all" --auto-update=all --jsonrpc-cors null</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">完成同步的奇偶校验日志:</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic2.zhimg.com/80/v2-1f0420d614d216d392a02bf834a67139_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">为了更快地<span style="color: black;">安排</span>,您<span style="color: black;">能够</span><span style="color: black;">运用</span>Parity Docker容器。还<span style="color: black;">能够</span><span style="color: black;">保留</span>数据,<span style="color: black;">这般</span>每次重新制作容器时都不必重新同步。</p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">第2步:编写付款类</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">首要</span>创建一个名为libs的文件夹,<span style="color: black;">而后</span>将php-ethereum repo克隆到其中。ethereum-php项目是json-rpc类的一个很好的封装。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">而后</span><span style="color: black;">咱们</span><span style="color: black;">运用</span>以下类并将其另存为ethpay.php。这是支付处理的<span style="color: black;">重点</span><span style="color: black;">规律</span>。你<span style="color: black;">能够</span>用它来:</p>生成<span style="color: black;">位置</span>对<span style="color: black;">检测</span>余额(待定的和已完成的)从WEI转换为ETH<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><?</span><span style="color: black;">php</span>
<span style="color: black;">define</span><span style="color: black;">(</span><span style="color: black;">RPC_IP</span><span style="color: black;">,</span><span style="color: black;">127.0.0.1</span><span style="color: black;">);</span>
<span style="color: black;">define</span><span style="color: black;">(</span><span style="color: black;">RPC_PORT</span><span style="color: black;">,</span><span style="color: black;">8545</span><span style="color: black;">);</span>
<span style="color: black;">require</span> <span style="color: black;">libs/ethereum-php/ethereum.php</span><span style="color: black;">;</span>
<span style="color: black;">$e</span> <span style="color: black;">=</span> <span style="color: black;">new</span> <span style="color: black;">EthPay</span><span style="color: black;">();</span>
<span style="color: black;">class</span> <span style="color: black;">EthPay</span>
<span style="color: black;">{</span>
<span style="color: black;">private</span> <span style="color: black;">$eth</span><span style="color: black;">;</span>
<span style="color: black;">//让<span style="color: black;">咱们</span><span style="color: black;">创立</span>与parity节点的连接
</span> <span style="color: black;">function</span> <span style="color: black;">__construct</span><span style="color: black;">()</span>
<span style="color: black;">{</span>
<span style="color: black;">$thi</span>
</div>
一看到楼主的气势,我就觉得楼主同在社区里灌水。
页:
[1]