定义调用接口函数:
<?php
function MYMODULE_FUNCTIONNAME($url, $post) {
if(isset($post)){
$postData = $post;
// Setup cURL
$ch = curl_init($url); // 短信接口URL
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
//'Authorization: '.$authToken,
'Content-Type: application/json' // header中定义的接口参数等
),
CURLOPT_POSTFIELDS => json_encode($postData) //json格式化
));
// 执行
$response = curl_exec($ch);
// Check for errors
if($response === FALSE){
die(curl_error($ch));
}
//打印调试
// Decode the response
$responseData = json_decode($response, TRUE);
// Print the date from the response
echo $responseData;
//print $ch;
} else {
//return flase;
print 'error';
}
}
?>
调用:
<?php
$url = 'YOURURL'; //接口URL
$post = array(
"uid"=>$uid,
"firstname"=>$firstname,
"lastname"=>$lastname,
"zip"=>$zip
);
MYMODULE_FUNCTIONNAME($url, $post);
?>
Drupal 版本
正好再做短信注册
刚开始,一点都不懂,都不知道怎么把短信验证加到注册页面中去,哪里还有更详细的介绍么