ดาวน์โหลด Library ของ NuSoap
https://sourceforge.net/projects/nusoap/
Web Service ฝั่ง Server
WebServiceServer.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
<?php require_once("lib/nusoap.php"); //Connect db require_once('../../config.inc.php'); $mysqli = new mysqli($dbconfig['db_server'],$dbconfig['db_username'],$dbconfig['db_password'],$dbconfig['db_name']); if($mysqli->connect_errno){ die( "Failed to connect to MySQL : (" . $mysqli->connect_errno . ") " . $mysqli->connect_error); } $mysqli->set_charset("utf8"); // //Create a new soap server $server = new soap_server(); //Define our namespace $namespace = "https://seenual.com/nusoap/WebServiceServer.php"; $server->wsdl->schemaTargetNamespace = $namespace; //Configure our WSDL $server->configureWSDL("Leads"); //Add ComplexType $server->wsdl->addComplexType( 'DataList', 'complexType', 'struct', 'all', '', array( 'leadid' => array('name' => 'leadid', 'type' => 'xsd:int'), 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'), 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'), 'company' => array('name' => 'company', 'type' => 'xsd:string'), 'email' => array('name' => 'email', 'type' => 'xsd:string'), 'industry' => array('name' => 'industry', 'type' => 'xsd:string') ) ); //Add ComplexType $server->wsdl->addComplexType( 'DataListResult', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array( array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DataList[]') ), 'tns:DataList' ); #####getLeadsByCampaign //Register our method and argument parameters $varname = array( 'campaignid' => "xsd:int" ); // Register service and method $server->register('getLeadsByCampaign', // method name $varname, // input parameters array('return' => 'tns:DataListResult')); #####getCustomerById //Register our method and argument parameters $varname = array( 'leadid' => "xsd:int" ); // Register service and method $server->register('getLeadById', // method name $varname, // input parameters array('return' => 'tns:DataListResult')); function getLeadsByCampaign($campaignid) { global $mysqli; $resultArray = array(); $query = "SELECT lead_no, vtiger_leaddetails.leadid, email, firstname, salutation, lastname, company, industry FROM vtiger_leaddetails INNER JOIN vtiger_leadaddress ON vtiger_leadaddress.leadaddressid = vtiger_leaddetails.leadid INNER JOIN vtiger_leadscf ON vtiger_leadscf.leadid = vtiger_leaddetails.leadid INNER JOIN vtiger_crmentity ON vtiger_leaddetails.leadid = vtiger_crmentity.crmid LEFT JOIN vtiger_campaignleadrel ON vtiger_campaignleadrel.leadid = vtiger_leaddetails.leadid WHERE vtiger_crmentity.deleted=0 AND vtiger_campaignleadrel.campaignid='".$campaignid."' "; $res = $mysqli->query($query); $field = array(); while ($finfo = $res->fetch_field()) { $field[$finfo->name] = $finfo->name; } while($row = $res->fetch_array()){ $arrCol = array(); foreach($field as $value){ $arrCol[$value] = $row[$value]; } array_push($resultArray,$arrCol); } $mysqli->close(); return $resultArray; } function getLeadById($leadid) { global $mysqli; $resultArray = array(); $query = "SELECT lead_no, vtiger_leaddetails.leadid, email, firstname, salutation, lastname, company, industry FROM vtiger_leaddetails INNER JOIN vtiger_leadaddress ON vtiger_leadaddress.leadaddressid = vtiger_leaddetails.leadid INNER JOIN vtiger_leadscf ON vtiger_leadscf.leadid = vtiger_leaddetails.leadid INNER JOIN vtiger_crmentity ON vtiger_leaddetails.leadid = vtiger_crmentity.crmid LEFT JOIN vtiger_campaignleadrel ON vtiger_campaignleadrel.leadid = vtiger_leaddetails.leadid WHERE vtiger_crmentity.deleted=0 AND vtiger_leaddetails.leadid='".$leadid."' "; $res = $mysqli->query($query); $field = array(); while ($finfo = $res->fetch_field()) { $field[$finfo->name] = $finfo->name; } while($row = $res->fetch_array()){ $arrCol = array(); foreach($field as $value){ $arrCol[$value] = $row[$value]; } array_push($resultArray,$arrCol); } $mysqli->close(); return $resultArray; } // Get our posted data if the service is being consumed // otherwise leave this data blank. $POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : ''; // pass our posted data (or nothing) to the soap service $server->service($POST_DATA); exit(); ?> |
Web Service ฝั่ง Client
WebServiceClient.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php header('Content-Type: text/html; charset=UTF-8'); require_once("lib/nusoap.php"); $client = new nusoap_client("https://seenual.com/nusoap/WebServiceServer.php?wsdl",true); $params = array( 'campaignid' => 517089 ); $result = $client->call("getLeadsByCampaign",$params); // Check for a fault if ($client->fault) { echo '<h2>Fault</h2><pre>'; print_r($result); echo '</pre>'; }else{ // Check for errors $err = $client->getError(); if ($err) { // Display the error echo '<h2>Error</h2><pre>' . $err . '</pre>'; } else { // Display the result echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>'; } } ?> |
ผลลัพธ์
อ้างอิง