如何保存json的所有响应并在我的api响应中使用我的soap api中的nusoap显示

时间:2016-12-15 13:04:48

标签: php json api soap

嗨伙计们,我是新编码和制作肥皂api及其运行,但我想在肥皂api响应中显示整个json响应我正在使用nusoap 我希望像这样显示一个完整的响应{“user”:“Exists”,“user_id”:2440} 但在我的api中它只显示一个 这是我的肥皂api代码

require 'nusoap/lib/nusoap.php';
header('Content-Type: text/xml');
$server = new soap_server();
$params = array("identity"=> array("name" => "identity", "type" =>"xsd:string"));
$response = array("response"=> array("name" => "user", "type" => "xsd:string"),array("name" => "user_id", "type" => "xsd:string")),array("message"=> array("name" => "user", "type" =>"xsd:string"),);
$server->configureWSDL("authcode","http://23.97.56.249/WSDLWrapper/authcode.php?wsdl");
$server->wsdl->addComplexType('credentials', 'complexType', 'struct', 'all', '', $params);
$server->wsdl->addComplexType('response', 'complexType', 'struct', 'all', '', $response);

$server->register("authcode",array('userCredentials' => 'tns:credentials'),  array("userResponse"=>"tns:response"),"http://23.97.56.249/WSDLWrapper/authcode.php","http://23.97.56.249/WSDLWrapper/authcode.php","rpc","encoded","authcode");
$server->service(isset($HTTP_RAW_POST_DATA) ?
$HTTP_RAW_POST_DATA : '');

function authcode($credentials) {
    // Get cURL resource
    $curl = curl_init();
    // Set some options - we are passing in a useragent too here
    curl_setopt_array($curl, array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => 'https://api.forimazdoori.com/auth/request',
        CURLOPT_USERAGENT => 'WSDL Wrapper Internal Call',
        CURLOPT_POST => 1,
        CURLOPT_POSTFIELDS => $credentials
    ));
    // Send the request & save response to $resp
    $resp = curl_exec($curl);
    if ($resp === false) {
        //$response['response'] = $result['message'];
        $resp = curl_error($curl);
        //$response['Code'] = "1111";
        $response['response'] = "error";
    } else {
        $result = json_decode($resp, true);
        $response['response'] = $result['message'];
        if(array_key_exists('user', $result)) {
            // $response['Code'] = '0000';
            $response['response'] = $result['user_id'];
        } else {
            //$response['Code'] = '1111';
            $response['response'] = $result['message'];
        }
    }

    // Close request to clear up some resources
    curl_close($curl);
    //$response['response'] = $result['message'];
    return $result;
}

0 个答案:

没有答案