-
Notifications
You must be signed in to change notification settings - Fork 1
/
yunjiekou.class.php
executable file
·58 lines (48 loc) · 1.14 KB
/
yunjiekou.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
if(!defined("YJK_API_HOST"))
{
define("YJK_API_HOST", "http://api.yunjiekou.com/");
define("YJK_API_VERSION", "1.0");
define("YJK_APP_KEY", "Your App Key");
define("YJK_APP_SECRET", "Your App Secret");
}
class YunJieKou
{
public function req($api_name,$params= array(),$format = "json",$req_type = "post")
{
$p = $params;
$p["appkey"] = YJK_APP_KEY;
$p["v"] = YJK_API_VERSION;
$p["timestamp"] = time();
$p["format"] = $format;
$sign = $this->sign($p,$api_name);
$url = YJK_API_HOST.$api_name."?".http_build_query($p)."&sign=".$sign;
$data = json_decode( $this->getData($url));
return $data;
}
private function sign($p,$api_name)
{
$s = '';
ksort($p);
foreach($p as $k=>$v)
{
$s.=($k.$v);
}
return md5(YJK_APP_SECRET.$s.$api_name.YJK_APP_SECRET);
}
private function getData($url,$params = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if($params)
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
}
?>