Skip to content

Instantly share code, notes, and snippets.

@eight
Created November 6, 2009 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eight/227572 to your computer and use it in GitHub Desktop.
Save eight/227572 to your computer and use it in GitHub Desktop.
<?php
//XML-RPC IXR_Library.inc.php 使用サンプル
if (isset($_GET['show_source'])) {
highlight_file('sample2.php');
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>XML-RPC IXR_Library.inc.php 使用サンプル - 郵便専門ネット</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
</head>
<body>
<a href="http://yubin.senmon.net/service/xmlrpc.html">XML-RPCを使うへ戻る</a><br>
<h1>XML-RPC IXR_Library.inc.php 使用サンプル</h1>
<p>郵便番号を入力して送信ボタンをクリックしてください。</p>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
郵便番号 <input type="text" size="40" name="postcode" value="<?php echo $_GET['postcode']; ?>"><br>
<input type="submit" value="XML-RPCリクエストを送信">
</form>
<?php
include_once('IXR_Library.inc.php');
$_GET['data_type'] = "";
echo "<h2>yubin.getVersion()</h2>";
$client = new IXR_Client('http://yubin.senmon.net/service/xmlrpc/');
if (!$client->query('yubin.getVersion')) {
echo ('Something went wrong - '.$client->getErrorCode().' : '.$client->getErrorMessage());
} else {
$resp = $client->getResponse();
if ($resp) {
echo "全国郵便番号一覧の現在のバージョンは $resp です";
} else {
echo "郵便番号 '" .$_GET['postcode'] . "'は見つかりませんでした。";
}
}
echo "<h2>yubin.postcodeExists()</h2>";
$client = new IXR_Client('http://yubin.senmon.net/service/xmlrpc/');
if (!$client->query('yubin.postcodeExists', $_GET['postcode'])) {
echo ('Something went wrong - '.$client->getErrorCode().' : '.$client->getErrorMessage());
} else {
$resp = $client->getResponse();
if ($resp) {
echo "郵便番号 '" .$_GET['postcode'] . "'が見つかりました。ちゃんと存在してます。";
} else {
echo "郵便番号 '" .$_GET['postcode'] . "'は見つかりませんでした。";
}
}
echo "<h2>yubin.fetchAddressByPostcode()</h2>";
$client = new IXR_Client('http://yubin.senmon.net/service/xmlrpc/');
if (!$client->query('yubin.fetchAddressByPostcode', $_GET['postcode'])) {
echo ('Something went wrong - '.$client->getErrorCode().' : '.$client->getErrorMessage());
} else {
$resp = $client->getResponse();
if ($resp) {
echo "郵便番号 '" .$_GET['postcode'] . "'が見つかりました。" . count($resp) ."件ありました。<br>\n";
foreach($resp AS $k => $v) {
echo '<h3>No.' . ($k+1) . '</h3>';
foreach($v AS $k2 => $v2) {
echo sprintf('%s is %s',$k2,mb_convert_encoding($v2,'EUC-JP','auto')) . "<br>\n";
}
}
} else {
echo "郵便番号 '" .$_GET['postcode'] . "'は見つかりませんでした。";
}
}
?>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment