params['ctrip']['soap'];
$version = $params['Version'];
}
$this->bodyName = $bodyName;
$this->data = $data;
$this->RequestTypeName = $RequestTypeName;
$this->version = $version;
}
/**
* Des:执行并返回结果
* Name: exec
* @param int $type 1:标准模式如mapping、订单推送 2:UpdateRoomQuantity(更新保留房数量) 3. 房价房态推送
* @return array
* @author 倪宗锋
*/
public function exec($type = 1, $user_id = 1)
{
$this->user_id = $user_id;
$startTime = microtime(TRUE);
if ($type == 1) {
$return = $this->doExecForCommon();
} elseif ($type == 2) {
$return = $this->doExecForRoomQuantity();
} elseif ($type == 3) {
$return = $this->doExecForPrice();
} else {
$return = $this->reTu(false, 'type is error');
}
$endTime = microtime(TRUE);
$this->scTime = round(floatval($endTime - $startTime), 3);//时间差
return $return;
}
/**
* Des:标准模式调用并处理
* Name: doExecForCommon
* @return array
* @author 倪宗锋
*/
public function doExecForCommon()
{
$this->soap = \Yii::$app->soapClient;
$this->setXml();
if (Yii::$app->params['ctrip']['flag']) {
$re = $this->soap->AdapterRequest(['requestXml' => $this->send]);
$this->getRe = $re->AdapterRequestResult;
$result = Utils::xml_to_array($this->getRe);
} else {
$result = '<>';
}
return $this->reTu(true, 'OK', $result);
}
/**
* Des:房价房态推送
* Name: doExecForCommon
* @return array
* @author 王雷刚
* 2018-12-7 14:10:35
*/
public function doExecForPrice()
{
$this->soap = \Yii::$app->soapClientPrice;
$this->setXml();
if (Yii::$app->params['ctrip']['flag']) {
$re = $this->soap->AdapterRequest(['requestXml' => $this->send]);
$this->getRe = $re->AdapterRequestResult;
$result = Utils::xml_to_array($this->getRe);
} else {
$result = '<>';
}
return $this->reTu(true, 'OK', $result);
}
/**
* User:Steven
* Desc:更新保留房
* @return array
*/
public function doExecForRoomQuantity()
{
$this->soap = \Yii::$app->soapClientRemain;
$this->setXmlNs();
if (Yii::$app->params['ctrip']['flag']) {
$re = $this->soap->RoomQuantityReceive(['receiveRoomQuantityXml' => $this->send]);
$this->getRe = $re->RoomQuantityReceiveResult;
$result = Utils::xml_to_array($this->getRe);
} else {
$result = '<>';
}
return $this->reTu(true, 'OK', $result);
}
/**
* Des:设置xml报文
* Name: setXml
* @author 倪宗锋
*/
private function setXml()
{
$params = \Yii::$app->params['ctrip']['soap'];
$timeStamp = date("Y-m-d H:i:s", time());
$xml = "";
$xml .= "RequestTypeName\" Version=\"" . $this->version . "\" /><{$this->bodyName}>";
$xml .= Utils::data_to_xml($this->data);
$xml .= "{$this->bodyName}>";
$this->send = $xml;
}
/**
* Des:设置带有命名空间的xml报文
* Name: setXml
* @author 倪宗锋
*/
private function setXmlNs()
{
$params = \Yii::$app->params['ctrip']['soap'];
$timeStamp = date("Y-m-d\TH:i:s+08:00", time());
$xml = "\n";
$xml .= "";
$xml .= "RequestTypeName\" Version=\"" . $params['VersionRemain'] . "\" />bodyName}>";
$xml .= Utils::data_to_xml_ns($this->data, 'q1:');
$xml .= "bodyName}>";
$this->send = $xml;
}
/**
* Des:统一返回格式
* Name: reTu
* @param $flag
* @param string $msg
* @param string $data
* @return array
* @author 倪宗锋
*/
private function reTu($flag, $msg = '', $data = '')
{
return [
'flag' => $flag,
'msg' => $msg,
'data' => $data
];
}
public function __destruct()
{
$string = date('Y-m-d H:i:s', time()) . ' ' . $this->version . PHP_EOL;
$string .= "send:【{$this->user_id}】" . $this->send . PHP_EOL;
$string .= "get:【{$this->user_id}】" . $this->getRe . PHP_EOL;
$string .= 'time:' . $this->scTime . 's' . PHP_EOL . PHP_EOL;//时间差
$result = Utils::xml_to_array($this->getRe);
if (empty($result) || $result['RequestResult']['ResultCode'] != 0) {
$arr = array(
"agentid" => 1000002,
"title" => '推送失败:',
"msg" => $this->scTime . ':' . $this->send,
"touser" => 'wangxj|shifp|yuw',
);
zOfficeWechat::sendMsg($arr);
}
file_put_contents(__DIR__ . '/../../../runtime/logs/soap/' . date('Y-m-d') . '.log', $string, FILE_APPEND);
}
}