demo示例/下载

您可以使用http、Curl、Socket等形式请求接口.

助手接口PHP Demo下载 纯API接口PHP Demo下载

PHP简单例子
//-------下面是相关配置-------//
$server = "127.0.0.1"; // 软件所在的外网IP
$key = "123456"; // ApiKey
$port = "8887"; // 软件的端口,注意开启防火墙

//-------下面是请求的例子,具体请看接口文档-------//

//转链
$pid = "mm_88888888_55555555_6868686868"; // 你的联盟PID
$id = urlencode("547838047292"); //商品链接/淘口令/商品ID
$send_data = 'api?Key=' . $key . '&getname=link&id=' . $id . '&pid=' . $pid;

echo socket_alimama ($server, $port, $send_data);//socket请求.(推荐)
//echo curl_alimama ($server, $port, $send_data);//curl请求

//-------下面是请求方法(socket和curl)-------//

/**
 * socket方式获取
 */
function socket_alimama($server, $port, $send_data) {
try {
$socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP);
if (!$socket) {
return "请检查socket扩展是否开启";
}
$result = @socket_connect ($socket, $server, $port);
if (!$result) {
return "socket连接失败";
}
$output = '';
socket_write ($socket, $send_data, strlen ($send_data));
while ($out = socket_read ($socket, 1024 * 64)) {
$output .= $out;
}
socket_close ($socket);
return $output;
}
catch(Exception $e) {
return $e;
}
}
/**
 * CURL方式获取
 */
function curl_alimama($server, $port, $send_data) {
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, "http://$server:$port/$send_data");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 6); //超时时间,自行按情况而定
$output = curl_exec ($ch);
curl_close ($ch);
return $output;
}