php调用第三方api接口 PHP可以开发APP吗?
PHP可以开发APP吗?PHP是WEB后端语言,最好用于APP的后端数据接口编写。当然,也可用html php混合写web程序,最后封装成web app,但性能不如原生app。PHP如何调用API接口
PHP可以开发APP吗?
PHP是WEB后端语言,最好用于APP的后端数据接口编写。当然,也可用html php混合写web程序,最后封装成web app,但性能不如原生app。
PHP如何调用API接口?
通过php模拟post请求即可调用。
php 模拟POST提交的方法:
通过curl函数
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)