$reqMsg]); $json = json_decode($ret,true); if(!empty($json) && $json['success']){ return_ok('成功',$json['data']); }else{ return_wrong('请求失败'); } }catch (Exception $e){ return_wrong('请求失败'.$e->getMessage()); } function curl_post($url, $data) { $ch = curl_init (); $header = array ("Accept-Charset: utf-8",'Expect:' ); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header ); curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)' ); curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 ); curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 ); curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 ); // 最好加上http_build_query 转换,防止有些服务器不兼容 curl_setopt ( $ch, CURLOPT_POSTFIELDS, http_build_query ( $data ) ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); $result = curl_exec ( $ch ); curl_close ( $ch ); return $result; } function xmltoarr($str){ return json_decode(json_encode(simplexml_load_string($str, null, LIBXML_NOCDATA)),true); } function return_ok($msg = '成功',$data = ''){ header('Content-Type:application/json; charset=utf-8'); $result['status'] = 1; $result['msg'] = $msg ; $result['data'] = $data; exit(json_encode($result,JSON_UNESCAPED_UNICODE)); } function return_wrong($msg = '失败'){ header('Content-Type:application/json; charset=utf-8'); $result['status'] = 0; $result['msg'] = $msg ; exit(json_encode($result,JSON_UNESCAPED_UNICODE)); } ?>