Api + MD5

Api + MD5

Hello anyone I'm very new at

The API tell:

Client -> Server
http://192.168.1.150/goform/apicmd?cmd=0&user=admin

Server -> Client
<?xml version="1.0"encoding="UTF-8" ?>
<Configuration>
<ResCode>0</ResCode>
<RetMsg></RetMsg>
<ChallengeCode>5c0e1f55b54be2d0c56004ba349fb726</ChallengeCode>
<IDCode>UM1NWDJYC19LOEYQRWNA</IDCode>
</Configuration>

Client -> Server
http://192.168.1.150/goform/apicmd?cmd=1&user=admin&authcode=<authcodes
tring>&idcode=<idcodestring>&type=opt_type

authcodestring = md5(ChallengeString:remote_pin:password);
idcodestring = The node value of “IDCode”
opt_type = 1: open door, 2: close door

I make this (bad) code but not working:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Home</title>
    <meta charset="utf-8">
  
    <script src="js\jquery\dist\jquery.js" type="text/javascript"></script>
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>   
    <script src="js\jquery\dist\md5.js" type="text/javascript"></script>

</head>
<body>
<div class="main">
<!--==============================header=================================-->
<header>
    <div class="row-1">
      
    </div>
</header>
<!--==============================content================================-->
<div class="content-box">
   
</div>
<!--==============================aside=================================-->

<!--==============================footer=================================-->
</div>
<script>
    var ip = "192.168.1.150";
    var urlLink = "http://" + ip + "/goform/apicmd?cmd=0&user=admin"
    var urlink2= "http://" + ip + "/goform/apicmd?cmd=1&user=admin"
    var ChallengeCodeValue = "";
    var IDCodeValue = "";
    var password = "0000"
    var remotepin="1234";
    var authcodestring = "";
    $(document).ready(function () {      
        $.ajax({
            type: "GET",          
            url: urlLink,
            dataType: "xml",
            success: function (xml) {
                xmlDoc = $.parseXML(xml);
                ChallengeCodeValue = $xml.find("ChallengeCode").text();
                IDCodeValue = $xml.find("IDCode").text();
                if (ChallengeCodeValue != null && IDCodeValue != null) {
                    authcodestring = md5(ChallengeCodeValue + ":" + remotepin + ":" + password);
                    alert(authcodestring);
                    if (authcodestring != null)
                    {
                        $.ajax({
                            type: "POST",
                            url: urlink2,
                            data: {
                                'authcode': authcodestring,
                                'idcode': IDCodeValue,
                                'type':1
                            },
                            success: function (response) {
                                alert(response.status);

                            },
                            error: function () {
                                alert("error");
                            }
                        });
                    }
                }
                else {
                    alert("ChallengeCodeValue:" + ChallengeCodeValue + " e IDCodeValue" + IDCodeValue);
                }
            },
            error: function() {
                alert("An error occurred while processing XML file.");
            }
        });

    });
</script>
</body>
</html>

Any Help ?

The xml of the link http://192.168.1.150/goform/apicmd?cmd=0&user=admin got this:

<Configuration>
<ResCode>0</ResCode>
<RetMsg/>
<ChallengeCode>81b84a7c349ba351d7a98ca1ac57bf8b</ChallengeCode>
<IDCode>JXUQZYPUTRQO7TE8SZLL</IDCode>
</Configuration>

ChallengeCode and IDCode change every 5 seconds.

Thank you very much for every help.