problem with integration with affinityassistencia (Curl + php + xml)

Asked

Viewed 164 times

2

Well, I’ve got Curl up and running. I’m trying to integrate with the site: https://www.affinityassistencia.com.br/ws/examples/? usuario=teste&password=teste&button=Log in getplano method.

i send the xml via Curl and returns that the parameters were not informed

Name: Getplanos (available)

Purpose: Return all available plans.

Request parameters: Login, password

Response parameters: Plan code, plan name

example: https://www.affinityassistencia.com.br/ws/exemplos/getPlanos.asp

$input_xml="<?xml version='1.0' encoding='UTF-8' ?> 
<requisicao>
    <login>xml28</login>
    <senha>15028</senha>

</requisicao>";

$url = 'https://www.affinityassistencia.com.br/ws/getPlanosLista/';

  //setting the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
    curl_setopt($ch, CURLOPT_HTTPHEADER,
            array('Content-type: application/xml',
                'Content-length: '. strlen($input_xml)) );

    curl_setopt($ch, CURLOPT_POSTFIELDS,
                 $input_xml);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "xml28:15028");
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    $data = curl_exec($ch);
    curl_close($ch);


    //convert the XML result into array
//        $array_data = json_decode(json_encode(simplexml_load_string($data)), true);

    print_r('<pre>');
    print_r($data);
    print_r('</pre>');

So does anyone have any suggestions? Att Gustavo

1 answer

2

There are several errors in the code, but I believe it must have been his attempts to find a correction. Your question is very vague, no exact documentation, but let’s go in pieces, as Jack used to say.


TL;DR:

Do a GET using the parameter mensagem, that is to say:

https://www.affinityassistencia.com.br/ws/getPlanosLista/?mensagem='.urlencode($input_xml)

Using the CURLOPT_POSTFIELDS you’re gonna make a POST (and not a GET). But you say you want to use the endpoint of "Getplanos", if the name has GET, because you are doing a POST?!

  1. Use GET.
    • Remove the CURLOPT_POSTFIELDS.
    • Remove the header from Content-length.

Now we need to know why CURLOPT_USERPWD, this is done for login using the HTTP Authentication, this is those login/password fields that appear inside an Alert, you’ve probably seen some around. :P

  1. Remove the CURLOPT_USERPWD.

We have a non-existent report. Which parameter name should be sent, example site.com?x=y, we have the y but we don’t have the x.

Let’s analyze the sent page:

inserir a descrição da imagem aqui

  1. Utilize mensagem to send the XML, as long as the chave changes with each session, so it doesn’t seem important.

In the end:

// Sua chave:
$parametrosURL['chave'] = '0';

// Sua mensagem:
$parametrosURL['mensagem'] = "<?xml version='1.0' encoding='UTF-8' ?> 
<requisicao>
    <login>xml28</login>
    <senha>15028</senha>
</requisicao>";

$parametrosURL = http_build_query($parametrosURL);

$url = 'https://www.affinityassistencia.com.br/ws/getPlanosLista/?'.$parametrosURL;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-type: application/xml']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$data = curl_exec($ch);
curl_close($ch);

print_r('<pre>');
print_r($data);
print_r('</pre>');

If the key is not important, you can use the example mentioned above:

$mensagem = "<?xml version='1.0' encoding='UTF-8' ?> 
    <requisicao>
        <login>xml28</login>
        <senha>15028</senha>
    </requisicao>";

$url = 'https://www.affinityassistencia.com.br/ws/getPlanosLista/?mensagem='.urlencode($mensagem);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.