首页 > PHP > ecshp soap接口示例
2010二月6

ecshp soap接口示例

为其他网站推广调取本公司手机数据,提供的简单soap接口,如下:
服务端:server.php
(注释部分请忽略)

<?php
define('IN_ECS', true);
require_once '../../includes/init.php';
class getGoods{
// public  $Authentication;
	//身份认证
	public function init($key){
//		if ($key==8750){
//			$this->Authentication = 1;
//		}else {
//		$this->Authentication = 0;
//		}
	}
	public function getGoodsByCat($cat_id){
		global $db;
		global $ecs;
//		$this->check();
		$where = " WHERE `shop_price`>100";
		if (isset($cat_id)){
			$where .= " AND `cat_id`=".$cat_id;
		}
		$sql = "SELECT `goods_id`,`cat_id`, `goods_desc`, `goods_name`, `shop_price`, `goods_img`,`goods_para_desc`,`brand_id`,`goods_para_desc` FROM ". $ecs->table("goods").$where;
		$goods = $db->getAll($sql);
		if (!empty($goods)){
			return $goods;
		}else
		    return "empty result!";
	}
//	public function check(){
//		if ($this->Authentication !=1){
//			return "Access Denied!";
//			exit(1);
//		}
	}
}
//$a = new getGoods();

ini_set("soap.wsdl_cache_enabled", "0");
$server=new SoapServer('ecshop.wsdl',array('soap_version' => SOAP_1_2));
$server->setClass("getGoods");
$server->handle();

?>

调取方法:
client.php

<?php
ini_set ( "soap.wsdl_cache_enabled", "0" );
$a = new SoapClient ( "http://www.xxxx.com/api/soapapi/ecshop.wsdl" );
//$a->init(87501);
$data = $a->getGoodsByCat (24);

print_r($data);exit;
?>

下面内容或许对你有帮助:

本文地址:http://www.zeevin.com/?p=379 , 转载请保留.

本文目前尚无任何评论.

发表评论