Here's a practical example with php/MySQL.
Lets say for the sake of argument you have a MySQL database table like this:
CREATE TABLE `bitcoin_payments` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`bitcoin_address` varchar(34) NOT NULL,
`payment_in_satoshi` bigint(20) unsigned NOT NULL DEFAULT '0',
`transaction_hash` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
);
And in this table you have a list of payments to be made. If the payment has already been made then the
transaction_hash field contains the transaction hash the payment was made with, otherwise it's empty.
<?php
$guid="GUID_HERE";
$firstpassword="PASSWORD_HERE";
$secondpassword="PASSWORD_HERE";
// Your MySQL database login credentials here
$host="localhost"; // MySQL host
$user=""; // MySQL user
$pass=""; // MySQL password for user above
$db=""; // MySQL database to use
mysql_select_db($db, mysql_connect($host, $user, $pass));
$result=mysql_query("SELECT `id`, `bitcoin_address`, `payment_in_satoshi` FROM `bitcoin_payments` WHERE `transaction_hash`='' ORDER BY `id` ASC");
$recipient_list=array();
$new_paid_ids="";
if(mysql_num_rows($result)>0)
{
while($row=mysql_fetch_assoc($result))
{
$new_paid_ids.=$row["id"].",";
$recipient_list[$row["bitcoin_address"]]=$row["payment_in_satoshi"];
}
$new_paid_ids=trim($new_paid_ids, ",");
}
if(count($recipient_list)>0)
{
$recipients=urlencode(json_encode($recipient_list));
$json_url = "http://blockchain.info/merchant/$guid/sendmany?password=$firstpassword&second_password=$secondpassword&recipients=$recipients";
$json_data = file_get_contents($json_url);
if($http_response_header[0]=="HTTP/1.1 200 OK")
{
$json_feed = json_decode($json_data);
$error = $json_feed->error;
if(is_null($error))
{
$message = $json_feed->message;
$txid = $json_feed->tx_hash;
mysql_query("UPDATE `bitcoin_address` SET `transaction_hash`='".mysql_real_escape_string($txid)."' WHERE `id` IN(".$new_paid_ids.")");
echo $message." - <a href='https://blockchain.info/tx/".$txid."'>".$txid."</a>";
}
else
echo $error;
}
else
echo "bitchain.info returned the following http error:<br /><br />".$http_response_header[0];
}
?>
Please note the above is not tested but it should work in theory. So this old thread is the closest I can find to a working PHP example of sendmany using Blockchain's API. I cannot get it to work, it's driving me completely batty. I've got the right passwords and guid and I'm using the code posted above and I get back "Unknown Error" from the API. Can anyone take a moment to look at the code, maybe you can see something I missed?
Very much appreciated!