receive - 生成收款地址
使用receive
调用生成一个新的收款地址。
API调用
GET v2/receive
查询参数:
- xpub:用于生成地址的扩展公钥
- callback_url:收到支付时的回调URL,注意要先将该URL进行url编码处理
- key:blockchain.info的v2支付api密钥,点击这里申请密钥:https://api.blockchain.info/v2/apikey/request/
- gap_limit:地址序号间隔上限,即在出错前允许多少个未用地址。可选
API返回值
返回新生成的收款地址信息,包含如下字段:
- address:新生成的收款地址
- index:地址对应的序号
- callback:到款通知回调URL
示例代码
使用curl调用receive
的示例代码如下:
curl "https://api.blockchain.info/v2/receive?xpub=xpub6CWiJoiwxPQni3DFbrQNHWq8kwrL2J1HuBN7zm4xKPCZRmEshc7Dojz4zMah7E4o2GEEbD6HgfG7sQid186Fw9x9akMNKw2mu1PjqacTJB2&callback=https%3A%2F%2Fmystore.com%3Finvoice_id%3D058921123&key=[yourkeyhere]"
返回值:
{
"address":"19jJyiC6DnKyKvPg38eBE8R6yCSXLLEjqw",
"index":23,
"callback":"https://mystore.com?invoice_id=058921123"
}
使用receive
调用的PHP示例代码如下:
<?php
$secret = 'ZzsMLGKe162CfA5EcG6j';
$my_xpub = '{YOUR XPUB ADDRESS}';
$my_api_key = '{YOUR API KEY}';
$my_callback_url = 'https://mystore.com?invoice_id=058921123&secret='.$secret;
$root_url = 'https://api.blockchain.info/v2/receive';
$parameters = 'xpub=' .$my_xpub. '&callback=' .urlencode($my_callback_url). '&key=' .$my_api_key;
$response = file_get_contents($root_url . '?' . $parameters);
$object = json_decode($response);
echo 'Send Payment To : ' . $object->address;