PHP cURLによるGETリクエスト
http://php.net/manual/ja/function.curl-setopt.php
リクエスト先はBloclchaininfoのAPI用アドレス
Blockchaininfo API
必要なパラメータは、
xpub - Your xPub (where you would like the payment to be sent)
callback_url - The callback URL to be notified when a payment is received. Remember to URL Encode the callback url when calling the create method.
key - Your blockchain.info receive payments v2 api key. Request an API key.
gap_limit - Optional. How many unused addresses are allowed before erroring out.
暗号化されたトークンとカートIDからビットコインアドレスを取得する。
戻り値にはアドレスとレスポンスコード(200,500など)を含む。
public function getNewAddress($token, $cartid)
{
$my_xpub = Configuration::get('BLOCKCHAININFOBTC_XPUB_ADDR');
$my_api_key = Configuration::get('BLOCKCHAININFOBTC_API_KEY');
$my_callback_url = urlencode($this->context->link->getModuleLink(
$this->name,
'callback',
array('bci_token' => $token,
'cart_id' => $cartid
)
));
$root_url = Configuration::get('BLOCKCHAININFOBTC_NEW_ADDRESS_URL');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $root_url. '?xpub=' .$my_xpub. '&callback=' .$my_callback_url. '&key=' .$my_api_key. '&gap_limit=100');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$addressObj = Tools::jsonDecode($data);
if (!isset($addressObj)) {
$addressObj = new stdClass();
}
$addressObj->{'response_code'} = $httpcode;
return $addressObj;
}