php調(diào)用第三方api接口 PHP可以開發(fā)APP嗎?
PHP可以開發(fā)APP嗎?PHP是WEB后端語言,最好用于APP的后端數(shù)據(jù)接口編寫。當(dāng)然,也可用html php混合寫web程序,最后封裝成web app,但性能不如原生app。PHP如何調(diào)用API接口
PHP可以開發(fā)APP嗎?
PHP是WEB后端語言,最好用于APP的后端數(shù)據(jù)接口編寫。當(dāng)然,也可用html php混合寫web程序,最后封裝成web app,但性能不如原生app。
PHP如何調(diào)用API接口?
通過php模擬post請求即可調(diào)用。
php 模擬POST提交的方法:
通過curl函數(shù)
Php代碼:
$post_data = array()
$post_data["clientname"] = "test08"
$post_data["clientpasswd"] = "test08"
$post_data["submit"] = "submit"
$url="
http://xxx.xxx.xxx.xx/xx/xxx/top.php"
$o=""
foreach ($post_data as $k=>$v)
{
$o.= "$k=".urlencode($v)."&"
}
$post_data=substr($o,0,-1)
$ch = curl_init()
curl_setopt($ch, CURLOPT_POST, 1)
curl_setopt($ch, CURLOPT_HEADER, 0)
curl_setopt($ch, CURLOPT_URL,$url)
//為了支持cookie
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt")
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data)
$result = curl_exec($ch)