开发示例与开发包
官方 SDK 下载
PHP SDK下载 V1 (最后修改于 2012.7.16)
.NET SDK下载 V1 (最后修改于 2013.3.26)
JAVA SDK下载 V1 (最后修改于 2013.4.18)
PHP调用示例
//用户查看API调用示例
$method='user/view';
//设置操作所需的参数
$paras=array('username'=>'123@qq.com');
//设置公司的域名和密钥
$yourDomain='name***.kf5.com';
$secretKey='60a03****007fcd123461c5ad1df2';
//创建签名
$mysign=Sign::mySign($paras,$secretKey);
//生成url请求
$url = 'http://'.$yourDomain.'/api/v1/'.$method.'?'.http_build_query($paras).'&sign='.$mysign;
//发送请求,并获取请求结果
$result=file_get_contents($url);
print_r(json_decode($result));
.NET调用示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KF5API;
namespace KF5SDK
{
class Program
{
static void Main(string[] args)
{
//查看用户信息示例
string method = "user/view";
IDictionary<string, string> param = new Dictionary<string, string>();
param.Add("username", "123456789@qq.com");
Console.WriteLine("返回结果:" + Sign.Post(method, param));
Console.Read();
}
}
}
JAVA调用示例
package util;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
public class Test {
public static String testUserGet(){
TreeMap<String, String> apiparamsMap = new TreeMap<String, String>();
apiparamsMap.put("yourname", "yourname@163.com");
//生成签名
String sign = Sdk.md5Signature(apiparamsMap);
apiparamsMap.put("sign", sign);
StringBuilder param = new StringBuilder();
for (Iterator<Map.Entry<String, String>> it = apiparamsMap.entrySet()
.iterator(); it.hasNext();) {
Map.Entry<String, String> e = it.next();
param.append("&").append(e.getKey()).append("=").append(e.getValue());
}
return param.toString().substring(1);
}
public static void main(String[] args) {
String result = Sdk.getResult("user/view",testUserGet());
System.out.print(result);
}
}