/** |
* 统一API接口调用 |
* |
* @param array $req_params 请求的参数数组 |
* @param string $url_path 调用的接口PHP路径,不保含主机地址 |
* @return array |
*/ |
static public function api( $req_params , $url_path ) |
{ |
$req = array ( 'sid' => self:: $api_cfg [ 'sid' ], 'appkey' => self:: $api_cfg [ 'appkey' ], 'timestamp' => time()); |
$appSecret = self:: $api_cfg [ 'appsecret' ]; |
$pre_dir = self:: $api_cfg [ 'predir' ]; |
$req = array_merge ( $req , $req_params ); |
self::makeSign( $req , $appSecret ); |
Log::LOG( 'wdt_api' , "req param:" . print_r( $req , true)); |
$service_url = "http://" . self:: $api_cfg [ 'host' ] . $pre_dir . $url_path . '?' . http_build_query( $req ); |
$response = file_get_contents ( $service_url ); |
Log::LOG( 'wdt_api' , "req url:" . $service_url ); |
Log::LOG( 'wdt_api' , $response ); |
if ( $response === false) return false; |
$json = json_decode( $response , true); |
Log::LOG( 'wdt_api' , "response:" . print_r( $json , true)); |
return $json ; |
} |
中级程序员
by: 浩骅 发表于:2016-09-07 14:41:51 顶(0) | 踩(0) 回复
代码不够全,仅供参考把
回复评论