Autor | Zpráva | ||
---|---|---|---|
pavel88 Profil * |
#1 · Zasláno: 17. 2. 2009, 11:29:32
Zdravim,
nedari se mi predavat objedavky do systemu sveho dodavatele pomoci Socket. mam tvorit neco takoveho s posilat k nim na server: POST /VOISWebService/VOISGate.asmx HTTP/1.1 Host: www.gpd.cz Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Header> <AuthHeader xmlns="http://example.com/"> <UserName>string</UserName> <Password>string</Password> </AuthHeader> </soap12:Header> <soap12:Body> <OrderSaleDelivery xmlns="http://example.com/"> <request>xml</request> </OrderSaleDelivery> </soap12:Body> </soap12:Envelope> mel bych dostat zpet neco takoveho: HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <OrderSaleDeliveryResponse xmlns="http://example.com/"> <OrderSaleDeliveryResult>xml</OrderSaleDeliveryResult> </OrderSaleDeliveryResponse> </soap12:Body> </soap12:Envelope> a delam to takhle: <?php header("Expires: Mon, 26 Jul 1999 05:00:00 GMT"); // Date in the past header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); //header( "Content-Type: text/xml"); //nastaveni promennych $ws_host = "ssl://www.example.com"; //$ws_host = "https://www.example.com/VOISWebService/VOISGate.asmx"; $ws_port = 443; $ws_soap_url = "/VOISWebService/VOISGate.asmx"; $ws_soap_action = "http://example.com"; $ws_user = ""; $ws_password = ""; $eol = "\r\n"; $ws_test = 1; // 1 = test; 0 = naostro // extrhujeme namespace z $ws_soap_action preg_match('/(http?:\/\/.*\/)(.*)/', $ws_soap_action, $vysledek); $soap_ns = $vysledek[1]; $soap_action = $vysledek[2]; // dokument $XML_obsah = ''; $XML_obsah = '<xs:schema id="OrderSaleDelivery" targetNamespace="..." elementFormDefault="qualified" xmlns="..." xmlns:mstns="..." xmlns:xs="..." attributeFormDefault="unqualified"> <xs:element name="Document"> <xs:complexType> <xs:all> <xs:element name="Partner" maxOccurs="1" minOccurs="1"> <xs:complexType> <xs:all> <xs:element name="Address" maxOccurs="1" minOccurs="1"> <xs:complexType> <xs:sequence /> <!-- GUID partnera --> <xs:attribute name="ID" type="xs:string" use="optional" /> </xs:complexType> </xs:element> <xs:element name="InvoiceAddress" maxOccurs="1" minOccurs="0" form="qualified"> <xs:complexType> <xs:sequence /> <!-- fakturacni adresa zakaznika - nepovinna --> <xs:attribute name="Name" type="xs:string" use="required" /> <xs:attribute name="Street" type="xs:string" use="required" /> <xs:attribute name="City" type="xs:string" use="required" /> <xs:attribute name="ZIP" type="xs:string" use="required" /> <!-- ICO --> <xs:attribute name="NumID" type="xs:string" use="optional" /> <!-- DIC --> <xs:attribute name="VATID" type="xs:string" use="optional" /> <!-- Telefon --> <xs:attribute name="Phone" type="xs:string" use="optional" /> <!-- Mobil --> <xs:attribute name="Mobile" type="xs:string" use="optional" /> <!-- Email --> <xs:attribute name="Email" type="xs:string" use="optional" /> </xs:complexType> </xs:element> <xs:element name="DeliveryAddress" maxOccurs="1" minOccurs="1"> <xs:complexType> <xs:sequence /> <!-- dodaci adresa zakaznika --> <xs:attribute name="Name" type="xs:string" use="required" /> <xs:attribute name="Street" type="xs:string" use="optional" /> <xs:attribute name="City" type="xs:string" use="required" /> <xs:attribute name="ZIP" type="xs:string" use="required" /> <xs:attribute name="Phone" type="xs:string" use="optional" /> </xs:complexType> </xs:element> </xs:all> </xs:complexType> </xs:element> <xs:element name="Items" maxOccurs="1" minOccurs="1"> <xs:complexType> <xs:sequence> <xs:element name="Item" minOccurs="1" maxOccurs="unbounded" form="qualified"> <xs:complexType> <xs:sequence /> <!-- poradove cislo polozky v ramci dokladu --> <xs:attribute name="Index" type="xs:int" use="optional" /> <!-- jednoznacna identifikace rezervovaneho radku, pomoci IDTrans se muze partner dotazovat na stav --> <xs:attribute name="IDTrans" type="xs:string" use="optional" /> <!-- ID zbozi, musi byt vyplnene ID nebo MATCH nebo EAN nebo PartnerCode --> <xs:attribute name="ID" type="xs:int" use="optional" /> <!-- kod polozky, musi byt vyplnene ID nebo MATCH nebo EAN nebo PartnerCode --> <xs:attribute name="Match" type="xs:string" use="optional" /> <!-- kod polozky, musi byt vyplnene ID nebo MATCH nebo EAN nebo PartnerCode --> <xs:attribute name="EAN" type="xs:string" use="optional" /> <!-- kod polozky, musi byt vyplnene ID nebo MATCH nebo EAN nebo PartnerCode --> <xs:attribute name="PartnerCode" type="xs:string" use="optional" /> <!-- mnozstvi --> <xs:attribute name="Amount" type="xs:decimal" use="required" /> <!-- cena dobirky za jednotku vcetne DPH --> <xs:attribute name="UnitVatPrice" type="xs:decimal" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:all> <!-- zpusob platby --> <xs:attribute name="PayType" type="PayTypes" use="optional" /> <!-- evidencni cislo objednavky --> <xs:attribute name="IDOrder" type="xs:string" use="optional" /> <!-- datum dodani --> <xs:attribute name="DeliveryDate" type="xs:date" use="optional" /> <!-- delka splatnosti (v celych dnech) --> <xs:attribute name="DueDays" type="xs:int" use="optional" /> <!-- poznamka --> <xs:attribute name="Note" type="xs:string" use="optional" /> <!-- pokud je hodnota Test=1, provedou se vsechny akce jako pri objednavani zbozi, vrati se vysledek, ale nakonec se provede ROLLBACK --> <xs:attribute name="Test" type="SWITCH" use="optional" /> </xs:complexType> </xs:element> <xs:simpleType name="SWITCH"> <xs:restriction base="xs:byte"> <xs:enumeration value="0" /> <xs:enumeration value="1" /> </xs:restriction> </xs:simpleType> <xs:simpleType name="PayTypes"> <xs:restriction base="xs:string"> <!-- hotove --> <xs:enumeration value="Cash" /> <!-- prevodem --> <xs:enumeration value="Bank" /> <!-- platebni karta --> <xs:enumeration value="Card" /> </xs:restriction> </xs:simpleType> </xs:schema>'; //vytvorime obalku a vlozime vytvorene XML pro zaslani do SOAP $SOAP_obsah = "<?xml version=\"1.0\" encoding=\"utf-8\"?>".$eol; $SOAP_obsah .= "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">".$eol; $SOAP_obsah .= " <soap:Header>".$eol; $SOAP_obsah .= " <AuthHeader xmlns=\"http://example.com/\">".$eol; $SOAP_obsah .= " <UserName>".$ws_user."</UserName>".$eol; $SOAP_obsah .= " <Password>".$ws_password."</Password>".$eol; $SOAP_obsah .= " </AuthHeader>".$eol; $SOAP_obsah .= " </soap:Header>".$eol; $SOAP_obsah .= " <soap:Body |
||
pavel88 Profil * |
#2 · Zasláno: 17. 2. 2009, 11:31:19
pokracovani ...
$SOAP_obsah .= " <soap:Body>".$eol; $SOAP_obsah .= " <OrderSaleDeliveryResponse xmlns=\"http://example.com/\">".$eol; $SOAP_obsah .= " <OrderSaleDeliveryResult>".$XML_obsah."</OrderSaleDeliveryResult>".$eol; $SOAP_obsah .= " </OrderSaleDeliveryResponse >".$eol; $SOAP_obsah .= " </soap:Body>".$eol; $SOAP_obsah .= " </soap:Envelope>".$eol; //prekonvertujeme na UTF-8 a zjistime delku SOAP //$SOAP_obsah = iconv("windows-1250", "UTF-8", $SOAP_obsah); $SOAP_obsah_delka = strlen($SOAP_obsah); //pripravime spojeni, zacneme nastavenim hlavicek $spojeni_headers = "POST ".$ws_soap_url." HTTP/1.1".$eol; $spojeni_headers.= "Host: ".str_replace("ssl://","", $ws_host).$eol; $spojeni_headers.= "Connection: close".$eol; $spojeni_headers.= "Content-Type: text/xml; charset=utf-8".$eol; $spojeni_headers.= "Content-Length: ".$SOAP_obsah_delka.$eol; $spojeni_headers.= "SOAPAction: \"".$soap_ns.$soap_action."\"".$eol.$eol; //otevreme spojeni se serverem $fp = fsockopen($ws_host, $ws_port, $errno, $errstr, 20); //posleme otevrenym spojenim hlavicky a obsah fputs($fp, $spojeni_headers); fputs($fp, $SOAP_obsah); //die($SOAP_obsah); //nastavime timeout stream_set_timeout($fp, 20); //ziskame odpoved $SOAP_data = ""; $status = socket_get_status($fp); var_dump($status); //musime vypnout varovani, protoze fgets u ssl spojeni vraci varovani (bug PHP) error_reporting(E_ALL^E_WARNING); error_reporting(1); //vytahneme data ze spojeni while(!feof($fp) && !$status['timed_out']) { $SOAP_data .= fgets($fp, 1024); $status = socket_get_status($fp); } //uzavreme spojeni fclose($fp); //prekonvertujem do windows 1250 $SOAP_data = iconv("UTF-8", "windows-1250", $SOAP_data); //vyseparujeme z odpovedi XML //1. zjistime pozici $pos = strpos ($SOAP_data, "<Document"); $vracene_XML = substr($SOAP_data, $pos); $pos = strpos ($vracene_XML, "</Document>"); $vracene_XML = substr($vracene_XML, 0, $pos); //ted pridame hlavicku a konec document $vracene_XML = "<?xml version=\"1.0\" encoding=\"windows-1250\" ?>\n".($vracene_XML)."</Document>\n"; //zpracujeme XML ?> vraci se mi tohle: array(7) { ["stream_type"]=> string(14) "tcp_socket/ssl" ["mode"]=> string(2) "r+" ["unread_bytes"]=> int(0) ["seekable"]=> bool(false) ["timed_out"]=> bool(false) ["blocked"]=> bool(true) ["eof"]=> bool(false) } takze dospel jsem k zaveru ze neco delam blbe smiling smiley, na server se mi pry nepovedlo ani plyvnout zkousel sem to odesialt i pres SOAP, ale neslo mi to. Pokud nekdo muze poradit budu rad, pokud nekdo za rady ktere povedou k reseni chce adekvatni prepocet na CZK, tak ho bude mit taky apod. dik za kazdy kop spravnym smerem. pavel |
||
bohyn Profil |
#3 · Zasláno: 17. 2. 2009, 14:10:44 · Upravil/a: bohyn
Jak Oteviras spojeni a jak odesilas dotaz? Melo byt zhruba takto:
<? $f = fsockopen("www.gpd.cz", 80); if($f) { // $request = tvuj HTTP dotaz fwrite($f, $request); $response = ""; while(!eof($f)) { $response .= fgets($f); } fclose($f); echo $response; } ?> |
||
nightfish Profil |
#4 · Zasláno: 17. 2. 2009, 15:26:45
1) no nevím nevím, ale zřejmě bych použil nějakou hotovou SOAP implementaci (třeba PEARový SOAP)
2) pokud chceš, aby se v tom kódu někdo zkusil zorientovat, obal jej do [pre ] a [/pre ] |
||
Časová prodleva: 16 let
|
0