http://www.oschina.net/action/api/login_validate/ 和这个做了个一样的,但不知道他们的代码是什么我做出来post提交会301有什么办法可以不用更改客户端直接200提交
服务端是discuz
<?php
require '../config/config.php';
if (! function_exists ( 'uc_user_login' )) { loaducenter (); } $username = urldecode ( getgpc ( 'username' ) ); $password = getgpc ( 'pwd' ); $username = htmlspecialchars ( trim ( $username ) ); $password = htmlspecialchars ( trim ( $password ) );
if (strtoupper ( $_G ['charset'] ) != "UTF-8") { require_once libfile ( 'class/chinese' ); $chs = new Chinese ( 'utf-8', CHARSET ); $username = $chs->convert ( $username ); } // elseif(checkUid($username)){ // $result = uc_user_login($username, $password, 1, 1, '', ''); // } if (checkEmailLogin ( $username )) { $result = uc_user_login ( $username, $password, 2, 1, '', '' ); } else { $result = uc_user_login ( $username, $password, 0, 0, '', '' ); } $uid = $result ["0"]; $email = $result ["3"];
/* * 用PHP的DOM控件来创建XML输出 * 设置输出内容的类型为xml */ header ( 'Content-Type: text/xml;' ); // 创建新的xml文件 $dom = new DOMDocument ( '1.0', 'utf-8' );
// 建立<response>元素 $response = $dom->createElement ( 'oschina' ); $dom->appendChild ( $response );
// 建立<books>元素并将其作为<response>的子元素 $books = $dom->createElement ( 'result' ); $response->appendChild ( $books );
$errorCode = $dom->createElement ( 'errorCode' );
$books->appendChild ( $errorCode ); // 为book创建标题 if (! isset ( $uid ) || $uid <= 0) { $errorCodeText = $dom->createTextNode ( "0" ); $errorCode->appendChild ( $errorCodeText ); $title = $dom->createCDATASection ( "用户名或口令错" ); } else { $errorCodeText = $dom->createTextNode ( "1" ); $errorCode->appendChild ( $errorCodeText ); $title = $dom->createCDATASection ( "登录成功" ); }
// 为book创建isbn元素 /* * $isbn = $dom->createElement('isbn'); * $isbnText = $dom->createTextNode('1-21258986'); * $isbn->appendChild($isbnText); */
// 创建book元素 $errorMessage = $dom->createElement ( 'errorMessage' ); $errorMessage->appendChild ( $title );
// 将<book>作为<books>子元素 $books->appendChild ( $errorMessage ); if ($uid > 0) { $user = $dom->createElement ( 'user' ); $response->appendChild ( $user ); $uidElement = $dom->createElement ( 'uid' ); $uidText = $dom->createTextNode ( $uid ); $uidElement->appendChild ( $uidText ); $addressElement = $dom->createElement ( 'location' ); $addressdata = USER::getUserprofile ( $uid ); $addresstitle = $dom->createCDATASection ( $addressdata ["address"] ); $user->appendChild ( $uidElement ); $addressElement->appendChild ( $addresstitle ); $user->appendChild ( $addressElement ); $usernameElement = $dom->createElement ( 'name' ); $usernameText = $dom->createCDATASection ( $result[1] ); $usernameElement->appendChild ( $usernameText ); $user->appendChild ( $usernameElement ); $flowers=$dom->createElement("followers"); $flowersText=$dom->createTextNode("0"); $flowers->appendChild($flowersText); $user->appendChild($flowers); $fans=$dom->createElement("fans"); $fansText=$dom->createTextNode("10"); $fans->appendChild($fansText); $user->appendChild($fans); $score=$dom->createElement("score"); $scoreText=$dom->createTextNode("0"); $score->appendChild($scoreText); $user->appendChild($score); $portrait=$dom->createElement("portrait"); $user->appendChild($portrait); $favoritecount = $dom->createElement ( "favoritecount" ); $favoritecountText = $dom->createTextNode ( "1" ); $favoritecount->appendChild ( $favoritecountText ); $user->appendChild ( $favoritecount ); $gender = $dom->createElement ( "gender" ); $genderText = $dom->createTextNode ( USER::getUserprofile ( $uid )["gender"] ); $gender->appendChild ( $genderText ); $user->appendChild ( $gender ); } $notice=$dom->createElement("notice"); $response->appendChild($notice); $atmeCount=$dom->createElement("atmeCount"); $atmeCountText=$dom->createTextNode("0"); $atmeCount->appendChild($atmeCountText); $notice->appendChild($atmeCount); $msgCount=$dom->createElement("msgCount"); $msgCountText=$dom->createTextNode("0"); $msgCount->appendChild($msgCountText); $notice->appendChild($msgCount); $reviewCount=$dom->createElement("reviewCount"); $reviewCountText=$dom->createTextNode("0"); $reviewCount->appendChild($reviewCountText); $notice->appendChild($reviewCount); $newFansCount=$dom->createElement("newFansCount"); $newFansCountText=$dom->createTextNode("0"); $newFansCount->appendChild($newFansCountText); $notice->appendChild($newFansCount); // 在一字符串变量中建立XML结构 $xmlString = $dom->saveXML ();
// 输出XML字符串 echo $xmlString;
?>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。