Api

生成唯一地址時如何放置二維碼?塊.io API

  • March 5, 2018

大家好,正如標題所說。每當 block_io.php 生成唯一地址時,如何生成二維碼?每當我回顯它時,我似乎在呼叫 $newAddressInfo 或 $newAddressInfo->data->address 時遇到問題。請忽略缺少的字元,因為它可以正常工作。這就是整個腳本。

來自 Kyle 的比特幣地址驗證器:HIS YOUTUBE CHANNEL

QR GENERATOR FROM:TERRAGON

我剛剛調整了凱爾的腳本。

腳本 :

require_once ("block_io.php");


$apiKey = "myAPIkey"; <br>
$version = 2; // API version <br>
$pin = "myPin";<br>
$block_io = new BlockIo($apiKey, $pin, $version);<br>

if(isset($_POST['submit'])){
   $newAddressInfo = $block_io->get_new_address();
   $address = $_POST['addr'];
   $decoded = decodeBase58($address);

   $d1 = hash("sha256", substr($decoded,0,21), true);
   $d2 = hash("sha256", $d1, true);

   if(substr_compare($decoded, $d2, 21, 4)){
       $message = "Invalid Bitcoin Address";
   } else {
       $message1 = "Valid Address";
       $message2 = "Your Receiving Address : ";
   }
}


function decodeBase58($input) {
   $alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

   $out = array_fill(0, 25, 0);
   for($i=0;$i<strlen($input);$i++){
       if(($p=strpos($alphabet, $input[$i]))===false){
               throw new \Exception("invalid character found");
       }
       $c = $p;
       for ($j = 25; $j--; ) {
               $c += (int)(58 * $out[$j]);
               $out[$j] = (int)($c % 256);
               $c /= 256;
               $c = (int)$c;
       }
       if($c != 0){
           throw new \Exception("address too long");
       }
   }

   $result = "";
   foreach($out as $val){
           $result .= chr($val);
   }

   return $result;
}

</form method="post">
   <input style="width: 100%;" name="addr" type="text">
<center><input name="submit" type="submit"><br>


if (isset($message)){ echo $message; } <br>
if (isset($message2)){ echo " Your Unique Deposit Address: " .$newAddressInfo->data->address."<br>"; } <br>
if (isset($message2)) $str = "Your Receiving Address : ";
$str ; echo $address = $_POST['addr']; <br>
if (isset($message2)){ echo img src='qr/qr_img.php?d=$newAddressInfo->data->address'> ; } <br>


</form>

地址驗證腳本其實來自 RosettaCode <https://rosettacode.org/wiki/Bitcoin/address_validation#PHP>

您需要做的就是創建新地址,然後將地址放入二維碼中。您可以使用 Google Charts API

&lt;?php 
require_once("block_io.php");

$block_io = new BlockIo($apiKey, $pin, $version);
$createAddress = $block_io-&gt;get_new_address();
$address = $createAddress-&gt;data-&gt;address;
?&gt;

&lt;html&gt;
This is your new address: &lt;br&gt;
&lt;img src="http://chart.googleapis.com/chart?chs=125x125&cht=qr&chl=&lt;?php echo $address; ?&gt;"&gt;
&lt;/html&gt;

引用自:https://bitcoin.stackexchange.com/questions/50073