Příklady použití importního RPC-XML rozhraní Import v PHP send($msg); // nactenivysledku $getHash = php_xmlrpc_decode($response->value()); // je dotaz OK ? if ($getHash[’status’] != 200) { die("Chyba privolanigetHash [{$getHash[’status’]}]: {$getHash[’statusMessage’]}"); } // sessionId se vypocte z obdrzeneho (vystup getHash), hesla a SW klice $sessionId = computeSessionId($getHash[’output’][0][’sessionId’], $password, $key); /* Prihlaseni na importserver */ // vytvoreni dotazu pro login a poslani na server $params = array(newxmlrpcval($sessionId)); $msg = newxmlrpcmsg("login", $params); $response = $client->send($msg);
// nactenivysledku $login = php_xmlrpc_decode($response->value()); // pokud je jiny status nez 200, nekde je chyba if ($login[’status’] != 200) { die("Chyba priprihlaseni [{$login[’status’]}]: {$login[’statusMessage’]}"); } /* Ukazkapridaniinzeratu */ // predkazdymdalsimpozadavkem je treba znovu vypocitatsessionId $sessionId = computeSessionId($sessionId, $password, $key); $advert = array( "advert_function" => 1, // prodej "advert_lifetime" => 1, // 7 dni "advert_price" => 10000.0, "advert_price_currency" => 1, // Kc "advert_price_unit" => 2, // za mesic "advert_type" => 1, // byty "description" => "Pekny byt s vyhledem na zahradu.", "locality_city" => "Praha", "locality_inaccuracy_level" => 2, // znepresneni adresy o 1 stupen "floor_number" => 1, // prvni patro "garage" =>false, "loggia" =>false, "balcony" =>false, "terrace" =>false, "ownership" => 1, // osobni vlastnictvi "parking_lots" =>true, "advert_subtype" => 4, // Typ bytu 2+kk "usable_area" => 54, // Plocha bytu 54m^2 "building_type" => 2, // Cihlova budova "building_condition" => 1, // Stav objektu velmi dobry "cellar" =>true, // Ma sklep "heating" =>array(3, 4), // topeni lokalnielektricke a ustredniplynove "telecommunication" =>array(1, 2, 4), // telefon, internet, kabelova televize "seller_id" => 123456, ); $msg = newxmlrpcmsg("addAdvert"); $msg->addParam(php_xmlrpc_encode($sessionId)); $msg->addParam(php_xmlrpc_encode($advert)); $response = $client->send($msg); $result = php_xmlrpc_decode($response->value()); if (floor($result[’status’] / 100) != 2) { die("Chyba priukladaniinzeratu [{$result[’status’]}]: {$result[’statusMessage’]}"); } /* Odhlaseni */ $sessionId = computeSessionId($sessionId, $password, $key); $params = array(newxmlrpcval($sessionId));
$msg = newxmlrpcmsg("logout", $params); $response = $client->send($msg); $result = php_xmlrpc_decode($response->value()); if ($result[’status’] != 200) { die("Chyba priodhlaseni [{$result[’status’]}]: {$result[’statusMessage’]}"); } ?>
Import v Python #!/usr/bin/python import xmlrpclib import hashlib clientId = 1 # ID klienta password = "vlozte-md5-hash-hesla" # heslo zakryptovane pres md5 key = "vlozte-importni-klic" # importniklic defNewSessionId(oldId, password, key): """ Heslo by se melo pouzivatuzzakryptovane pres md5. Heslo i importniklic jsou zjistitelne v adminwebu. """ varPart = hashlib.md5() varPart.update(oldId + password + key) return oldId[0:48] + varPart.hexdigest() # pripojeni na importserver client = xmlrpclib.ServerProxy("http://import.sreality.cz/RPC2") # zavolame metodu getHash pro ziskanipocatecnihosessionId getHash = client.getHash(clientId) ifgetHash["status"] / 100 == 2: # vypoctenisessionId pro dalsi dotaz sessionId = NewSessionId(getHash["output"][0]["sessionId"], password, key) # prihlaseni na importserver response = client.login(sessionId) if response["status"] / 100 == 2: print "logged in." # vlozeniinzeratu sessionId = NewSessionId(sessionId, password, key) advert = { "advert_function": 1, # prodej "advert_lifetime": 1, # 7 dni "advert_price": 10000.0, "advert_price_currency": 1, # Kc "advert_price_unit": 2, # za mesic "advert_type": 1, # byty "description": "Pekny byt s vyhledem na zahradu.",
"locality_city": "Praha", "locality_inaccuracy_level": 2, # znepresneni adresy o 1 stupen "floor_number": 1, # prvni patro "garage": False, "loggia": False, "balcony": False, "terrace": False, "ownership": 1, # osobni "parking_lots": True, "advert_subtype": 4, # Typ bytu 2+kk "usable_area": 54, # Plocha bytu 54m^2 "building_type": 2, # Cihlova budova "building_condition": 1, # Stav objektu velmi dobry "cellar": True, # Ma sklep "heating": (3, 4), # topeni lokalnielektricke a ustredniplynove "telecommunication": (1, 2, 4), # telefon, internet, kabelova televize "seller_id": 123456, } response = client.addAdvert(sessionId, advert) if response["status"] / 100 == 2: print "Advertsuccessfullyadded." else: print "addAdvert: %d %s" % (response["status"], response["statusMessage"]) # odhlaseni sessionId = NewSessionId(sessionId, password, key) client.logout(sessionId) else: print "login: %d %s" % (response["status"], response["statusMessage"]) else: print "getHash: %d %s" % (getHash["status"], getHash["statusMessage"])
Import v .NET Vytvoříme si proxy třídu s metodami volání API Imports System Imports System.Collections.Generic Imports System.Web Imports System.Reflection Imports CookComputing.XmlRpc Imports System.Xml ''' <summary> ''' Summary description for Proxy ''' <XmlRpcUrl("http://www.aaaornapuda.cz/import/rpc.ashx")> _ PublicClass rpcProxy Inherits XmlRpcClientProtocol
<XmlRpcMethod("getHash")> _ PublicFunction getHash(ByVal client_id As Int32) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {client_id}), XmlRpcStruct) EndFunction <XmlRpcMethod("login")> _ PublicFunction login(ByVal session_id AsString) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id}), XmlRpcStruct) EndFunction <XmlRpcMethod("logout")> _ PublicFunction logout(ByVal session_id AsString) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id}), XmlRpcStruct) EndFunction <XmlRpcMethod("addAdvert")> _ PublicFunction addAdvert(ByVal session_id AsString, ByVal InputData As XmlRpcStruct) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id, InputData}), XmlRpcStruct) EndFunction <XmlRpcMethod("delAdvert")> _ PublicFunction delAdvert(ByVal session_id AsString, ByVal advert_id AsInteger, ByVal advert_rkid AsString) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id, advert_id, advert_rkid}), XmlRpcStruct) EndFunction <XmlRpcMethod("topAdvert")> _ PublicFunction topAdvert(ByVal session_id AsString, ByVal advert_id AsInteger, ByVal advert_rkid AsString) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id, advert_id, advert_rkid}), XmlRpcStruct) EndFunction <XmlRpcMethod("listAdvert")> _ PublicFunction listAdvert(ByVal session_id AsString) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id}), XmlRpcStruct) EndFunction <XmlRpcMethod("addPhoto")> _ PublicFunction addPhoto(ByVal session_id AsString, ByVal advert_id AsInteger, ByVal advert_rkid AsString, ByVal InputData As XmlRpcStruct) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id, advert_id, advert_rkid, InputData}), XmlRpcStruct) EndFunction <XmlRpcMethod("delPhoto")> _ PublicFunction delPhoto(ByVal session_id AsString, ByVal photo_id AsInteger, ByVal photo_rkid AsString) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id, photo_id, photo_rkid}), XmlRpcStruct) EndFunction <XmlRpcMethod("listPhoto")> _ PublicFunction listPhoto(ByVal session_id AsString, ByVal advert_id AsInteger, ByVal advert_rkid AsString) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id, advert_id, advert_rkid}), XmlRpcStruct) EndFunction <XmlRpcMethod("addSeller")> _ PublicFunction addSeller(ByVal session_id AsString, ByVal seller_id AsInteger, ByVal seller_rkid AsString, ByVal InputData As XmlRpcStruct) As XmlRpcStruct
ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id, seller_id, seller_rkid, InputData}), XmlRpcStruct) EndFunction <XmlRpcMethod("delSeller")> _ PublicFunction delSeller(ByVal session_id AsString, ByVal seller_id AsInteger, ByVal seller_rkid AsString, ByVal InputData As XmlRpcStruct) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id, seller_id, seller_rkid, InputData}), XmlRpcStruct) EndFunction <XmlRpcMethod("listSeller")> _ PublicFunction listSeller(ByVal session_id AsString) As XmlRpcStruct ReturnCType(Invoke(MethodBase.GetCurrentMethod, NewObject() {session_id}), XmlRpcStruct) EndFunction EndClass
Vytvoříme si obslužnou metodu události při stisku tlačítka ProtectedSub bnt_getHash_Login_Logout_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles bnt_getHash_Login_Logout.Click Dim md5Hash As MD5 = MD5.Create() Dim tmpUserId AsInteger Dim tmpUserImportPassword AsString Dim tmpUserImportKey AsString Dim tmpUserPasswordHash AsString tmpUserId = "2" tmpUserImportPassword = "CAX-4I4-VIX-GSM-3MQ-IX5" tmpUserImportKey = "6LI-LKX-TCA-FX1-GEU-KXN" tmpUserPasswordHash = GetMd5Hash(md5Hash, tmpUserImportPassword) Dim Dim Dim Dim
url AsString = HttpContext.Current.Request.Url.AbsoluteUri tmpSessionIdObject As XmlRpcStruct IsAutorized AsBoolean bf As rpcProxy = New rpcProxy tmpSessionIdObject = bf.getHash(tmpUserId)
If tmpSessionIdObject.Item("status").ToString = "200"Then 'tak je to OK a pokracujeme Dim tmpSessionId AsString tmpSessionId = tmpSessionIdObject.Item("output")(0)("sessionId").ToString Me.txt_SessionId.Text = tmpSessionId.ToString 'vypocitame novou session a odesleme login tmpSessionId = GenerateNewSessionId(tmpSessionId, tmpUserPasswordHash, tmpUserImportKey) Dim tmpLogin As XmlRpcStruct tmpLogin = bf.login(tmpSessionId) If tmpLogin.Item("status").ToString = "200"Then IsAutorized = True Else IsAutorized = False EndIf Me.txt_Status.Text = ""
Me.txt_Status.Text = tmpLogin.Item("status").ToString &"-"& tmpLogin.Item("statusMessage").ToString 'vypocitame novou session a odesleme login tmpSessionId = GenerateNewSessionId(tmpSessionId, tmpUserPasswordHash, tmpUserImportKey) Dim tmpLogout As XmlRpcStruct tmpLogout = bf.logout(tmpSessionId) Else 'neni OK, vypiseme hlasku Me.txt_Status.Text = "" Me.txt_Status.Text = tmpSessionIdObject.Item("status").ToString &"-"& tmpSessionIdObject.Item("statusMessage").ToString ExitSub EndIf EndSub
ProtectedSub btn_addAdvert_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btn_addAdvert.Click Dim tmp_advert_id AsInteger Dim tmp_advert_rkid AsString Try tmp_advert_id = System.Convert.ToInt32(Me.txt_advert_id.Text.ToString) Catch ex As Exception tmp_advert_id = 0 EndTry Try tmp_advert_rkid = System.Convert.ToString(Me.txt_advert_rkid.Text.ToString) Catch ex As Exception tmp_advert_rkid = "" EndTry Dim tmp_seller_id AsInteger Dim tmp_seller_rkid AsString Try tmp_seller_id = System.Convert.ToInt32(Me.txt_seller_id.Text.ToString) Catch ex As Exception tmp_seller_id = 0 EndTry tmp_seller_rkid = Me.txt_seller_rkid.Text.ToString Dim Dim Dim Dim Dim
md5Hash As MD5 = MD5.Create() tmpUserId AsInteger tmpUserImportPassword AsString tmpUserImportKey AsString tmpUserPasswordHash AsString tmpUserId = "2" tmpUserImportPassword = "CAX-4I4-VIX-GSM-3MQ-IX5" tmpUserImportKey = "6LI-LKX-TCA-FX1-GEU-KXN" tmpUserPasswordHash = GetMd5Hash(md5Hash, tmpUserImportPassword)
'verifikace hesla a zahesovaneho hesla
Dim IsOk AsBoolean IsOk = VerifyMd5Hash(md5Hash, tmpUserImportPassword, tmpUserPasswordHash) Dim Dim Dim Dim
url AsString = HttpContext.Current.Request.Url.AbsoluteUri tmpSessionIdObject As XmlRpcStruct IsAutorized AsBoolean bf As rpcProxy = New rpcProxy tmpSessionIdObject = bf.getHash(tmpUserId) Dim tmpSessionId AsString tmpSessionId = tmpSessionIdObject.Item("output")(0)("sessionId").ToString Me.txt_SessionId.Text = tmpSessionId.ToString 'vypocitame novou session a odesleme login tmpSessionId = GenerateNewSessionId(tmpSessionId, tmpUserPasswordHash, tmpUserImportKey) Dim tmpLogin As XmlRpcStruct tmpLogin = bf.login(tmpSessionId)
If tmpLogin.Item("statusMessage").ToString = "OK"Then IsAutorized = True Else IsAutorized = False EndIf If (IsAutorized = True) Then 'vypocitame novou session a odesleme login tmpSessionId = GenerateNewSessionId(tmpSessionId, tmpUserPasswordHash, tmpUserImportKey) Dim InputData As XmlRpcStruct = New XmlRpcStruct InputData.Add("advert_function", 1) 'pronajem InputData.Add("advert_lifetime", 4) '90 dní InputData.Add("advert_price", "1500000") 'prodejni cena InputData.Add("advert_price_currency", "1") 'Kč InputData.Add("advert_price_unit", "1") 'za nemovitost InputData.Add("advert_type", 3) 'Pozemky InputData.Add("description", "Nějaký popis objektu prodeje") 'Popis InputData.Add("locality_city", "Praha") 'Město InputData.Add("advert_id", tmp_advert_id) 'ID inzeratu u AAAOP(Seznamu) InputData.Add("advert_rkid", tmp_advert_rkid) 'ID inzeratu v systemu inzerenta InputData.Add("advert_room_count", 4) 'Velikost(pocet pokoju) InputData.Add("advert_subtype", 20) 'Podkategorie - Pozemky - pole InputData.Add("balcony", False) 'balkon
InputData.Add("basin", False) 'bazen InputData.Add("building_condition", 2) 'stav objektu - Dobry InputData.Add("building_type", 2) 'Stavba - cihlova InputData.Add("cellar", True) 'sklep InputData.Add("estate_area", 1650) 'Plocha pozemku InputData.Add("floor_number", 1) 'patro InputData.Add("garage", True) 'garaz InputData.Add("locality_latitude", 155.5) 'Zeměpisná šířka InputData.Add("locality_longitude", 166.6) 'Zeměpisná délka InputData.Add("loggia", True) 'lodžie InputData.Add("object_type", 1) 'Typ domu - Přízemní InputData.Add("ownership", 1) 'vlastnictvi - osobni InputData.Add("parking_lots", True) 'Parkování InputData.Add("project_id", 1) 'ID projektu u srealit InputData.Add("project_rkid", "") 'ID projektu u realitky InputData.Add("seller_id", tmp_seller_id) 'ID maklere u srealit InputData.Add("seller_rkid", tmp_seller_rkid) 'ID maklere u realitky InputData.Add("terrace", True) 'terasa InputData.Add("usable_area", 120) 'Užitná plocha InputData.Add("acceptance_year", 2001) 'Rok kolaudace InputData.Add("advert_code", 999) 'ID zakázky InputData.Add("advert_low_energy", False) 'Nízkoenergetický InputData.Add("advert_price_charge", 1) 'poplatky - vcetne poplatku InputData.Add("advert_price_commission", 1) 'Provize - vcetne provize InputData.Add("advert_price_legal_services", 1) 'Právní servis - vcetne právního servisu InputData.Add("advert_price_negotiation", True) 'Cena k jednání InputData.Add("advert_price_text_note", "Poznámka k cene") 'Poznámka k cene InputData.Add("advert_price_text_note_en", "Poznámka k cene v AJ") 'Poznámka k cene v Anglictine InputData.Add("advert_price_text_note_ru", "Poznámka k cenev RJ") 'Poznámka k cene v Rustine InputData.Add("advert_price_vat", 1) 'DPH - vcetne DPH
InputData.Add("annuity", 50000) 'Anuita InputData.Add("balcony_area", 20) 'Plocha balkónu InputData.Add("basin_area", 20) 'Plocha bazénu InputData.Add("beginning_date", System.Convert.ToDateTime("1.1.2010")) 'Datum zahájení výstavby InputData.Add("building_area", 150) 'Plocha zastavená InputData.Add("ceiling_height", 2.5) 'Vyska stropu InputData.Add("cellar_area", 5) 'Plocha sklepu InputData.Add("cost_of_living", 5000) 'Náklady na bydlení InputData.Add("description_en", "Anglický popis") 'popis Anglicky InputData.Add("description_ru", "Ruský popis") 'popis Rusky InputData.Add("easy_access", 2) 'Bezbariérový - Ne 'pridani multiselect pole hodnot Dim electricity_array AsInteger() = NewInteger() {1, 2, 4} 'nebo 'Dim electricity_array2(2) As Integer 'electricity_array2(0) = 1 'electricity_array2(1) = 2 'electricity_array2(2) = 4 InputData.Add("electricity", electricity_array) 'Elektrina - 230V InputData.Add("elevator", 2) 'Vytah - Ne InputData.Add("energy_efficiency_rating", 3) 'Energetická nárocnost budovy - Úsporná InputData.Add("energy_performance_attachment", "base64") 'Energetický prukaz v PDF/JPG InputData.Add("energy_performance_certificate", 0) 'podle vyhlášky InputData.Add("energy_performance_summary", 0) 'Ukazatel energetické nárocnosti budovy InputData.Add("extra_info", 0) 'Stav InputData.Add("finish_date", System.Convert.ToDateTime("1.1.2012")) 'Datum ukoncení výstavby InputData.Add("first_tour_date", System.Convert.ToDateTime("1.1.2012 11:00")) 'Datum prohlídky InputData.Add("first_tour_date_to", System.Convert.ToDateTime("1.3.2012 11:00")) 'Datum prohlídky do InputData.Add("flat_class", 1) 'Typ bytu - Mezonet InputData.Add("floor_area", 75) 'Plocha podlahová InputData.Add("floors", 1) 'Podlaží pocet InputData.Add("furnished", 3) 'Vybavení - Cástecne
InputData.Add("garage_count", 1) 'Pocet garáží InputData.Add("garden_area", 700) 'Plocha zahrady InputData.Add("garret", False) 'Pudní vestavba 'pridani multiselect pole hodnot Dim gas_array AsInteger() = NewInteger() {1, 2} InputData.Add("gas", gas_array) 'Plyn - Plynovod 'pridani multiselect pole hodnot Dim gully_array AsInteger() = NewInteger() {1, 2, 3, 4} InputData.Add("gully", gully_array) 'Odpad - Verejná kanalizace 'pridani multiselect pole hodnot Dim heating_array AsInteger() = NewInteger() {1, 2, 3, 4, 5, 6, 7, 8} InputData.Add("heating", heating_array) 'Topení - Ústrední plynové InputData.Add("locality_citypart", "Háje") 'Mestská ˇcást InputData.Add("locality_co", "1546") 'Cislo orientacni InputData.Add("locality_cp", "25") 'Cislo popisne InputData.Add("locality_street", "Jesmínová") 'Ulice InputData.Add("loggia_area", 5) 'Plocha lodžie InputData.Add("mortgage", False) 'Hypotéka InputData.Add("mortgage_percent", 15.5) 'Hypotéka - procenta InputData.Add("nolive_total_area", 55) 'Plocha nebytových prostor InputData.Add("object_age", 25) 'Stari objektu InputData.Add("object_kind", 4) 'Poloha domu - Samostatný InputData.Add("object_location", 2) 'Umístení objektu - Klidná cást obce InputData.Add("offices_area", 0) 'Plocha kancelárí InputData.Add("parking", 1) 'Míst k parkování InputData.Add("personal", 1) 'Prevod do OV - Ano InputData.Add("ready_date", System.Convert.ToDateTime("1.3.2012 11:00")) 'Datum nastehovani InputData.Add("reconstruction_year", 2015) 'Rok rekonstrukce 'pridani multiselect pole hodnot Dim road_type_array AsInteger() = NewInteger() {1, 2, 3, 4} InputData.Add("road_type", road_type_array) 'Komunikace - Asfaltová
InputData.Add("sale_date", System.Convert.ToDateTime("1.3.2012 11:00")) 'Datum zahajeni prodeje InputData.Add("shop_area", 0) 'Obchodní plocha InputData.Add("store_area", 0) 'Plocha skladů InputData.Add("surroundings_type", 1) 'Zástavba - Obytná 'pridani multiselect pole hodnot Dim telecommunication_array AsInteger() = NewInteger() {1, 2, 3, 4, 5, 6} InputData.Add("telecommunication", telecommunication_array) 'Telekomunikace - Telefon InputData.Add("terrace_area", 10) 'Plocha terasy 'pridani multiselect pole hodnot Dim transport_array AsInteger() = NewInteger() {1, 2, 3, 4, 5} InputData.Add("transport", transport_array) 'Doprava InputData.Add("underground_floors", 1) 'Podlaží podzemní InputData.Add("usable_area_ground", 60) 'Užitná plocha prízemí InputData.Add("user_status", True) 'Aktivní 'pridani multiselect pole hodnot Dim water_array AsInteger() = NewInteger() {1, 2} InputData.Add("water", water_array) 'Voda - Dálkový vodovod InputData.Add("workshop_area", 0) 'Plocha dílen Dim tmpOutput As XmlRpcStruct tmpOutput = bf.addAdvert(tmpSessionId, InputData) Me.txt_advert_id.Text = "" Me.txt_Status.Text = "" Me.txt_advert_id.Text = System.Convert.ToInt32(tmpOutput.Item("output")(0)("advert_id")).ToString Me.txt_Status.Text = tmpOutput.Item("status").ToString &"-"& tmpOutput.Item("statusMessage").ToString 'vypocitame novou session a odesleme logout tmpSessionId = GenerateNewSessionId(tmpSessionId, tmpUserPasswordHash, tmpUserImportKey) bf.logout(tmpSessionId) Else 'vypocitame novou session a odesleme logout tmpSessionId = GenerateNewSessionId(tmpSessionId, tmpUserPasswordHash, tmpUserImportKey) bf.logout(tmpSessionId) EndIf EndSub
SharedFunction GetMd5Hash(ByVal md5Hash As MD5, ByVal input AsString) AsString ' Convert the input string to a byte array and compute the hash. Dim data AsByte() = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)) ' Create a new Stringbuilder to collect the bytes ' and create a string. Dim sBuilder AsNew StringBuilder() ' Loop through each byte of the hashed data ' and format each one as a hexadecimal string. Dim i AsInteger For i = 0 To data.Length - 1 sBuilder.Append(data(i).ToString("x2")) Next i ' Return the hexadecimal string. Return sBuilder.ToString() EndFunction'GetMd5Hash ' Verify a hash against a string. SharedFunction VerifyMd5Hash(ByVal md5Hash As MD5, ByVal input AsString, ByVal hash AsString) AsBoolean ' Hash the input. Dim hashOfInput AsString = GetMd5Hash(md5Hash, input) ' Create a StringComparer an compare the hashes. Dim comparer As StringComparer = StringComparer.OrdinalIgnoreCase If 0 = comparer.Compare(hashOfInput, hash) Then ReturnTrue Else ReturnFalse EndIf EndFunction'VerifyMd5Hash PublicFunction GetImage(ByVal img AsObject) AsString Return ("data:image/png;base64," + Convert.ToBase64String(CType(img, Byte()))) EndFunction PublicFunction Base64ToImage(ByVal base64String AsString) As System.Drawing.Image ' Convert Base64 String to byte[] Dim imageBytes() AsByte = Convert.FromBase64String(base64String) Dim ms As MemoryStream = New MemoryStream(imageBytes, 0, imageBytes.Length) ' Convert byte[] to Image ms.Write(imageBytes, 0, imageBytes.Length) Dim image As System.Drawing.Image = image.FromStream(ms, True) Return image EndFunction PublicFunction ImageToBase64(ByVal image As System.Drawing.Image, ByVal format As System.Drawing.Imaging.ImageFormat) AsString Dim ms As MemoryStream = New MemoryStream ' Convert Image to byte[] image.Save(ms, format) Dim imageBytes() AsByte = ms.ToArray ' Convert byte[] to Base64 String Dim base64String AsString = Convert.ToBase64String(imageBytes) Return base64String
EndFunction PublicFunction GenerateNewSessionId(ByVal OldSessionId AsString, ByVal PasswordHash AsString, ByVal ImportKey AsString) AsString Dim md5Hash As MD5 = MD5.Create() Dim NewSession_id AsString Dim fixedPart AsString Dim varPart AsString Dim software_key AsString Dim tmpUserPasswordHash AsString software_key = ImportKey.ToString tmpUserPasswordHash = PasswordHash.ToString
fixedPart = Left(OldSessionId, 48) varPart = GetMd5Hash(md5Hash, (OldSessionId & tmpUserPasswordHash & software_key)) NewSession_id = fixedPart & varPart Return NewSession_id EndFunction