php.ini
; Enables or disables WSDL caching feature.
; http://php.net/soap.wsdl-cache-enabled
soap.wsdl_cache_enabled=0
php netbeans debug
https://netbeans.org/kb/docs/php/debugging_zh_CN.html
yii webservice(document/literal encoding for WDSL)
https://github.com/yiisoft/yii/issues/94
https://github.com/nineinchnick/yii/commit/a61b6de16ef4044230cca6f54f241ede6b9b5705
<?php
class StockController extends CController
{
public function actions()
{
/*
return array(
'quote'=>array(
'class'=>'CWebServiceAction',
),
);*/
return array(
'wsdl'=>array(
'class'=>'CWebServiceAction',
'serviceOptions' => array(
'generatorConfig' => array(
'class' => 'CWsdlGenerator',
'operationBodyStyle'=>array('use'=>'literal'),
'bindingStyle'=>'document',
),
),
),
);
}
/**
* @param string the symbol of the stock
* @return float the stock price
* @soap
*/
public function getPrice($symbol)
{
$prices=array('IBM'=>100, 'GOOGLE'=>350);
return isset($prices[$symbol])?$prices[$symbol]:0;
//...return stock price for $symbol
}
public function actionView()
{
return "ss"
}
}
http://stackoverflow.com/questions/1523460/ensuring-valid-utf-8-in-php
<?php
class StockController extends CController
{
public function actions()
{
/*
return array(
'quote'=>array(
'class'=>'CWebServiceAction',
),
);*/
return array(
'wsdl'=>array(
'class'=>'CWebServiceAction',
'serviceOptions' => array(
'generatorConfig' => array(
'class' => 'CWsdlGenerator',
'operationBodyStyle'=>array('use'=>'literal'),
'bindingStyle'=>'document',
),
),
),
);
}
/**
* @param string the symbol of the stock
* @return float the stock price
* @soap
*/
public function getPrice($symbol)
{
$prices=array('IBM'=>100, 'GOOGLE'=>350);
return isset($prices[$symbol])?$prices[$symbol]:0;
//...return stock price for $symbol
}
/**
* @param string the symbol of the stock
* @return string the stock price
* @soap
*/
public function createPost($symbol)
{
echo $symbol;
$model=new Post;
$model->title='title';
$model->content='content';
$model->status=2;
$model->create_time=1230952187;
$model->update_time=1230952187;
$model->author_id=1;
$model->tags='test';
if($model->save()){
return '添加一条记录';
}else{
return '添加失败';
}
}
/**
* @param string the symbol of the stock
* @return string the stock price
* @soap
*/
public function sendPost($symbol)
{
$data=base64_decode($symbol);
$temp=bzdecompress($data);
$megObject = json_decode(make_safe_for_utf8_use($temp),true);
$posts = json_decode($megObject['dataBody'],true);
//if(gettype($megObject['dataBody'])=="string"){
//}
//return gettype($posts);
$postSucces=0;
$postFaile=0;
foreach($posts as $value)
{
//return $value;
//return $value["title"];
$model=new Post;
$model->title=$value["title"];
$model->content=$value["content"];
$model->tags=$value["tags"];
$model->create_time=$value["create_time"];
$model->update_time=$value["update_time"];
$model->status=$value["status"];
$model->author_id=$value["author_id"];
if($model->save()){
$postSucces++;
}else{
$postFaile++;
}
}
return "postSucces:".$postSucces.";postFaile".$postFaile;
}
public function actionView()
{
$model=new Post;
$model->title='title';
$model->content='content';
$model->tags='test';
$model->create_time=1230952187;
$model->update_time=1230952187;
$model->status=2;
$model->author_id=1;
if($model->save()){
echo '添加一条记录';
}else{
echo '添加失败';
}
}
public function actionShow()
{
$msg="{\"dataBody\":\"[{\\\"author_id\\\":100,\\\"content\\\":\\\"mytitle0\\\",\\\"create_time\\\":1389071330977,\\\"id\\\":0,\\\"status\\\":1,\\\"tags\\\":\\\"110\\\",\\\"title\\\":\\\"mytitle你好0\\\",\\\"update_time\\\":0},{\\\"author_id\\\":101,\\\"content\\\":\\\"mytitle1\\\",\\\"create_time\\\":1389071330977,\\\"id\\\":1,\\\"status\\\":1,\\\"tags\\\":\\\"110\\\",\\\"title\\\":\\\"mytitle你好1\\\",\\\"update_time\\\":0},{\\\"author_id\\\":102,\\\"content\\\":\\\"mytitle2\\\",\\\"create_time\\\":1389071330977,\\\"id\\\":2,\\\"status\\\":1,\\\"tags\\\":\\\"110\\\",\\\"title\\\":\\\"mytitle你好2\\\",\\\"update_time\\\":0},{\\\"author_id\\\":103,\\\"content\\\":\\\"mytitle3\\\",\\\"create_time\\\":1389071330977,\\\"id\\\":3,\\\"status\\\":1,\\\"tags\\\":\\\"110\\\",\\\"title\\\":\\\"mytitle你好3\\\",\\\"update_time\\\":0},{\\\"author_id\\\":104,\\\"content\\\":\\\"mytitle4\\\",\\\"create_time\\\":1389071330977,\\\"id\\\":4,\\\"status\\\":1,\\\"tags\\\":\\\"110\\\",\\\"title\\\":\\\"mytitle你好4\\\",\\\"update_time\\\":0},{\\\"author_id\\\":105,\\\"content\\\":\\\"mytitle5\\\",\\\"create_time\\\":1389071330977,\\\"id\\\":5,\\\"status\\\":1,\\\"tags\\\":\\\"110\\\",\\\"title\\\":\\\"mytitle你好5\\\",\\\"update_time\\\":0},{\\\"author_id\\\":106,\\\"content\\\":\\\"mytitle6\\\",\\\"create_time\\\":1389071330977,\\\"id\\\":6,\\\"status\\\":1,\\\"tags\\\":\\\"110\\\",\\\"title\\\":\\\"mytitle你好6\\\",\\\"update_time\\\":0},{\\\"author_id\\\":107,\\\"content\\\":\\\"mytitle7\\\",\\\"create_time\\\":1389071330977,\\\"id\\\":7,\\\"status\\\":1,\\\"tags\\\":\\\"110\\\",\\\"title\\\":\\\"mytitle你好7\\\",\\\"update_time\\\":0},{\\\"author_id\\\":108,\\\"content\\\":\\\"mytitle8\\\",\\\"create_time\\\":1389071330977,\\\"id\\\":8,\\\"status\\\":1,\\\"tags\\\":\\\"110\\\",\\\"title\\\":\\\"mytitle你好8\\\",\\\"update_time\\\":0},{\\\"author_id\\\":109,\\\"content\\\":\\\"mytitle9\\\",\\\"create_time\\\":1389071330977,\\\"id\\\":9,\\\"status\\\":1,\\\"tags\\\":\\\"110\\\",\\\"title\\\":\\\"mytitle你好9\\\",\\\"update_time\\\":0}]\",\"sendTime\":1389071331061,\"type\":\"list\"}";
//echo $msg;
$megObject = json_decode($msg);
//echo $megObject->dataBody;
$posts = json_decode($megObject->dataBody);
foreach($posts as $value)
{
echo $value->title;
$model=new Post;
$model->title=$value->title;
$model->content=$value->content;
$model->tags=$value->tags;
$model->create_time=$value->create_time;
$model->update_time=$value->update_time;
$model->status=$value->status;
$model->author_id=$value->author_id;
$model->save();
}
// $model=new Post;
// $model->title='title';
// $model->content='content';
// $model->tags='test';
// $model->create_time=1230952187;
// $model->update_time=1230952187;
// $model->status=2;
// $model->author_id=1;
// if($model->save()){
// echo '添加一条记录';
// }else{
// echo '添加失败';
// }
}
}
function make_safe_for_utf8_use($string) {
if (preg_match('%^(?:
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*$%xs', $string))
return $string;
else
return iconv('gbk', 'UTF-8', $string);
}