PHP筆記-PHP中Web Service.

來源:互聯網
上載者:User

標籤:

這幾天工作需要.net網站免登陸訪問PHP的Wiki網站。

PHP不熟,感覺很苦逼。任務下來了,必須搞定。準備用SSO,太麻煩了,要改寫別人很多代碼,這個是第三方CMS,封裝的很厲害,不好改。最後我的解決方案是,採取我有把握的解決方案:

1) .net系統中使用者,添加一個角色, WikiAdmin, 授權EPRG系統的外鏈。有這個角色的使用者才能在ePRG系統上看到Wiki的連結。

2) 使用者&角色名稱資料從Wellmed同步到Wiki資料庫。[Wiki中需要提供添加使用者的介面,手動寫web service,.NET通過HTTP Web方式調用Web Service]

3)點擊Wiki連結的時候,跳轉到.net的頁面eTools/Wiki,Controller的代碼中去調用Wiki的service, 添加使用者到Wiki系統,完成候reuturn view,在view中自動發post請求到wiki登入頁面,登入之後,和之前一樣,跳轉到首頁,整個過程使用者看不到。

 

在配置PHP Service時候,花了很多時間。按照網上方法,做這個測試之前,要確認你的php設定檔中已經將soap擴充開啟,即extension=php_soap.dll;發現php_soap.dll項目中都沒有。要去下載一個可用的,問朋友說,要下載和當前php版本相同的,否則可能不能用。liense中是3.1,可是php官方都沒有這個版本,懷疑liense中不代表php版本。最後通過搜尋引擎知道Phpinfo();方法可用列印出PHP的環境變數資訊,得知我的版本是是5.4.25。

在php.net官方下載php,複製php_soap.dll到\php\ext\檔案夾。

修改\php\php.ini添加一行代碼,extension=php_soap.dll,支援soap擴充。

寫server.php的服務端代碼,client端測試調用。成功。

 

嘗試用.net調用。發現php自己調用自己不需要wsdl檔案,.net調用必須有wsdl檔案。想辦法產生wsdl檔案。

最後花了很久,用zend studio,參考網上wsdl格式,終於完成了。

發現.net中添加引用方式,也能成功調用。

 

然後完善具體的UserManager方法。資料儲存在.php的源檔案中。最後通過以下方法實現。

<?phpclass test {    public function __construct()    {    }    public function updateUser($userName,$pwd,$fullName,$email,$groups)    {        $file = ‘conf/users.auth.php‘;        $content = file_get_contents($file);        $array = explode("\n", $content);        $newUserInfo=$userName.‘:‘.md5($pwd).‘:‘.$fullName.‘:‘.$email.‘:‘.$groups;        $myfile = fopen("conf/users.auth.php", "w") or die("Unable to open file!");        $isUserExists=false;                for($i=0; $i<count($array); $i++)        {            if(strlen($array[$i])>5)            {                //foreach each user info                $arrUserInfo = explode(":", $array[$i]);                //user exists, update user;                 $rs=strcasecmp($arrUserInfo[0],$userName);                                     if($rs==0)                {                        $isUserExists=true;                    $content=str_replace($array[$i],$newUserInfo,$content);                    break;                }                    }        }        //not exists, add user, append to last.        if($isUserExists==false)        {            $content=$content."\n".$newUserInfo;        }        fwrite($myfile, $content);        fclose($myfile);        return "success";    }    public function getlist($type)    {        $result = array(            array(‘name‘=>‘Zhangsan‘,‘age‘=>18),            array(‘name‘=>‘Lisi‘,‘age‘=>20)        );        $result = json_encode($result);        return $result;    }}?>
View Code

 

還需要添加安全認證。

 

參考資料:http://www.cnblogs.com/mbailing/p/3998821.html

http://www.cnblogs.com/zzxbest/archive/2011/09/21/2184252.html

 

PHP筆記-PHP中Web Service.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.