<?php
header("content-type:text/html;charset=utf-8");
$header = array("X-LC-Id: xxx",
"X-LC-Key: xxxx",
"Content-Type: application/json" );
$x=1;
if($x==1){
$url1 = "https://api.leancloud.cn/1.1/verifySmsCode/955824";
$rs = request($url1,'POST','{"mobilePhoneNumber": "18812121212"}',$header);
}else{
$url1 = 'https://api.leancloud.cn/1.1/requestSmsCode';
$rs = request($url1,'POST','{"mobilePhoneNumber": "18812121212"}',$header);
}
var_dump($rs);
function request($url, $method, $postfields = NULL, $headers = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
switch ($method)
{
case 'POST' :
curl_setopt($curl, CURLOPT_POST, TRUE);
if ($postfields)
{
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
}
break;
case 'DELETE' :
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
if ($postfields)
{
$url = "{$url}?{$postfields}";
}
break;
}
//$headers[] = 'API-RemoteIP: ' . fetch_ip();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLINFO_HEADER_OUT, TRUE);
if (substr($url, 0, 8) == 'https://')
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
}
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
?>测试代码