嘀咕接口示范
浏览:2591次 出处信息
一共有三个文件。分别用于“登录”、“跳转”和“更新嘀咕”。如下:
index.php文件
01 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
02 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
03 |
<head> |
04 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
05 |
<title>请登录</title> |
06 |
</head> |
07 |
<body> |
08 |
<form method="post" name="mblog" action="redirect.php"> |
09 |
<p>用名:<input name="username"/></p> |
10 |
<p>密码:<input name="password" type="password"/></p> |
11 |
<p><input type="checkbox" name="m[digu]" value="1" checked="checked"/> 嘀咕</p> |
12 |
<p><input type="submit" value="发布"/></p> |
13 |
</form> |
14 |
</body> |
15 |
</html> |
redirect.php文件
01 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
02 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
03 |
<head> |
04 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
05 |
<title>验证中</title> |
06 |
</head> |
07 |
<body> |
08 |
<? |
09 |
if(isset($_POST['username']) && $_POST['username']!=''&& isset($_POST['password']) && $_POST['password']!=''){ |
10 |
|
11 |
$user=$_POST['username']; |
12 |
$pass=$_POST['password']; |
13 |
|
14 |
$mblog="http://api.minicloud.com.cn/account/verify.xml?isAllInfo=false";//嘀咕接口地址,以XML格式返回 |
15 |
|
16 |
$curl=curl_init();//curl初始化 |
17 |
|
18 |
//curl请求 |
19 |
curl_setopt($curl,CURLOPT_URL,$mblog); |
20 |
curl_setopt($curl,CURLOPT_USERPWD,$user.":".$pass); |
21 |
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); |
22 |
|
23 |
$s=curl_exec($curl); |
24 |
|
25 |
curl_close($curl); |
26 |
|
27 |
if(strpos($s,"true")!==false){ |
28 |
echo "正在跳转……"; |
29 |
setcookie("user",$user);//可以用md5()等进行加密保护 |
30 |
setcookie("psd",$pass); |
31 |
header("location:update.php"); |
32 |
} |
33 |
else{ |
34 |
echo "密码错误。"; |
35 |
} |
36 |
} |
37 |
else{ |
38 |
echo "请填写完整"; |
39 |
} |
40 |
?> |
41 |
</body> |
42 |
</html> |
update.php文件
01 |
<? |
02 |
if(isset($_COOKIE['user'])&&isset($_COOKIE['psd'])){//验证身份 |
03 |
|
04 |
$user= $_COOKIE['user']; |
05 |
$pass= $_COOKIE['psd']; |
06 |
} |
07 |
else{ |
08 |
header("location:index.php"); |
09 |
} |
10 |
|
11 |
$result = ''; |
12 |
|
13 |
if(isset($_POST['content']) && $_POST['content']!=''){ |
14 |
|
15 |
$mblog="http://api.minicloud.com.cn/statuses/update.xml"; |
16 |
|
17 |
$data='content='.urlencode($_POST['content']).'';//URL转义 |
18 |
|
19 |
$s=postMblog($mblog,$user,$pass,$data);//调用函数,得到返回值 |
20 |
|
21 |
if(strpos($s,"true")!==false){//更新成功则会返回“true”字样 |
22 |
$result = "更新成功!"; |
23 |
} |
24 |
else{ |
25 |
$result = "更新失败!"; |
26 |
} |
27 |
|
28 |
} |
29 |
|
30 |
function postMblog($mblog,$user,$pass,$data){ |
31 |
$curl=curl_init();//( |
32 |
curl_setopt($curl,CURLOPT_URL,$mblog); |
33 |
curl_setopt($curl,CURLOPT_USERPWD,$user.":".$pass); |
34 |
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); |
35 |
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);//发送数据 |
36 |
$s=curl_exec($curl); |
37 |
curl_close($curl); |
38 |
return $s; |
39 |
} |
40 |
|
41 |
?> |
42 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
43 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
44 |
<head> |
45 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
46 |
<title>更新状态</title> |
47 |
</head> |
48 |
<body> |
49 |
<form method="post" action="update.php"> |
50 |
<input id="content" name="content" type="text" /> |
51 |
<input type="submit" value="发布"/> |
52 |
</form> |
53 |
<?php echo $result?> |
54 |
|
55 |
</body> |
56 |
</html> |
参考资料
1 嘀咕接口文档 http://code.google.com/p/digu-api/wiki/DiguApi
2 http://www.cnblogs.com/fdszlzl/archive/2009/06/16/1504231.html
建议继续学习:
- 一个典型支付系统的设计与实现 (阅读:8679)
- 使用PHP创建一个面向对象的博客 (阅读:4866)
- 关于架构的一句话,还有一个实例 (阅读:4209)
- 如何保证一个程序在单台服务器上只有唯一实例(linux) (阅读:3989)
- 如何让Perl脚本同时只运行一个实例 (阅读:3228)
- 人人都是交互设计师 (阅读:2612)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
扫一扫订阅我的微信号:IT技术博客大学习
<< 前一篇:简单工厂模式:计算器类
后一篇:Mediawiki扩展编写实战 >>
文章信息
- 作者:崔凯(小轰) 来源: 时光立方
- 标签: 嘀咕 实例
- 发布时间:2010-07-21 23:34:10
建议继续学习
近3天十大热文
-
[939] WordPress插件开发 -- 在插件使用 -
[117] 解决 nginx 反向代理网页首尾出现神秘字 -
[50] 如何保证一个程序在单台服务器上只有唯一实例( -
[48] 整理了一份招PHP高级工程师的面试题 -
[48] 用 Jquery 模拟 select -
[48] 海量小文件存储 -
[47] ps 命令常见用法 -
[47] Innodb分表太多或者表分区太多,会导致内 -
[46] 全站换域名时利用nginx和javascri -
[45] find命令的一点注意事项
