function test_post() { $url = $this->get_test_server_url(); $request_headers = array('Content-type' => 'application/x-www-form-urlencoded'); $response_headers = array(); $response_body = ''; $request_body = 'name=value123'; p2mixi_http_post($url, $request_headers, $request_body, $response_headers, $response_body); Assert::equals($response_body, $request_body, $request_body); }
function p2mixi_publish_to_mixi() { global $p2mixi_debug; // Using variable number of parameters. $args = func_get_args(); $username = $args[0]; $password = $args[1]; $id = $args[2]; $title = $args[3]; $content = $args[4]; if (func_num_args() == 6) { $images = $args[5]; } // WSSE Authentication $nonce = ""; if (function_exists('posix_getpid')) { $nonce = pack('H*', sha1(md5(time() . rand() . posix_getpid()))); } else { // Use uniqid() in case of windows. $nonce = pack('H*', sha1(md5(time() . rand() . uniqid()))); } $created = date('Y-m-d\\TH:i:s\\Z'); $digest = base64_encode(pack('H*', sha1($nonce . $created . $password))); $wsse_text = 'UsernameToken Username="******", PasswordDigest="%s", Nonce="%s", Created="%s"'; $wsse_header = sprintf($wsse_text, $username, $digest, base64_encode($nonce), $created); // mixi POST URL $url = 'http://mixi.jp/atom/diary/member_id=' . $id; $request_headers = array(); $request_headers['X-WSSE'] = $wsse_header; $request_headers['Accept'] = '*/*'; $request_headers["Connection"] = "Close"; //------------------------------------------------------------ // Post Image //------------------------------------------------------------ if ($p2mixi_debug) { error_log("p2mixi_publish_to_mixi: # of images : " . sizeof($images)); } if (sizeof($images) > 0) { if ($p2mixi_debug) { error_log("p2mixi_publish_to_mixi: Uploading images to Mixi."); } $response_headers = array(); $response_body = ''; $request_headers['Content-Type'] = 'image/jpeg'; p2mixi_http_post($url, $request_headers, $images[0], $response_headers, $response_body); $location = $response_headers['Location']; if ($p2mixi_debug) { error_log("p2mixi_publish_to_mixi: Finished uploading images to Mixi."); } if ($p2mixi_debug) { error_log("p2mixi_publish_to_mixi: Location: {$location}"); } if ($location != '') { $url = $location; } } //------------------------------------------------------------ // Post Text //------------------------------------------------------------ $request_body = "<?xml version='1.0' encoding='utf-8'?>" . "<entry xmlns='http://www.w3.org/2007/app'>" . "<title>{$title}</title>" . "<summary>{$content}</summary>" . "</entry>"; $request_headers['Content-Type'] = 'application/atom+xml'; if ($p2mixi_debug) { error_log("p2mixi_publish_to_mixi: Uploading text to Mixi."); } p2mixi_http_post($url, $request_headers, $request_body, $response_headers, $response_body); if ($p2mixi_debug) { error_log("p2mixi_publish_to_mixi: Finished uploading text to Mixi."); } }