跳转到主要内容
cloudio 提交于 21 July 2014

定义调用接口函数:

<?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 版本