Commit 3eca5fec authored by 蒋林's avatar 蒋林

对外接口-志高

parent ed2e2715
<?php
/**
* Created by PhpStorm.
* User: LinJiangL
* Date: 16/11/2
* Time: 下午2:15
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Class Chigo 志高相关接口
*
* @property api_log_model api_log_model
* @property SourceChigo SourceChigo
* @property ReceiveChigo ReceiveChigo
*/
class Chigo extends BaseController
{
public function callAcceptAction()
{
$param = $this->input->post();
//验证参数
$obj = $this->receiveObj();
$obj->SetValues($param);
$obj->CheckCallAcceptActionValues();
$values = $obj->GetValues();
$this->saveLog('', 'callAcceptAction', $values);
$sourceObj = $this->sourceObj($values['account'], $values['pwd']);
$result = $sourceObj->CallAcceptAction($values);
$obj->ReturnMessage(true, '', $result);
}
/**
* 保存日志
*
* @param $search
* @param $method
* @param $data
*/
private function saveLog($search, $method, $data)
{
//记录日志
$this->load->model('api_log_model');
$this->api_log_model->add($search, 'suning', $method, $data);
}
private function sourceObj($username, $pwd)
{
$account = [
'username' => $username,
'pwd' => $pwd
];
$this->load->library('Source/SourceChigo', $account, 'SourceChigo');
return $this->SourceChigo;
}
private function receiveObj()
{
$this->load->library('Receive/ReceiveChigo', null, 'ReceiveChigo');
return $this->ReceiveChigo;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: LinJiangL
* Date: 16/10/31
* Time: 上午10:28
*/
require 'Receive.php';
class ReceiveChigo extends Receive
{
public function CheckCallAcceptActionValues()
{
$fileds = [];
$this->CheckValues($fileds);
$dfields = [
'adat_begin', //20161011
'adat_end',
'mobile',
'phone',
'read_state', //1:已查阅 2;未查阅
'ano'
];
$this->SetDefaultValues($dfields);
if ($this->values['adat_begin']) {
$this->values['adat_begin'] = date('Y-m-d', strtotime($this->values['adat_begin']));
}
if ($this->values['adat_end']) {
$this->values['adat_end'] = date('Y-m-d', strtotime($this->values['adat_end']));
}
if ($this->values['read_state']) {
switch ($this->values['read_state']) {
case 1:
$this->values['read_state'] = 'Y';
break;
case 2:
$this->values['read_state'] = 'N';
break;
default:
$this->values['read_state'] = '';
}
}
}
/**
* 检查参数
* @param array $fields
*/
private function CheckValues($fields = [])
{
if (!$this->GetValues()) {
$this->ReturnMessage(false, '参数错误!');
}
if ($this->CheckAppid() == false) {
$this->ReturnMessage(false, 'appid参数错误!');
}
if ($this->CheckSign() == false) {
$this->ReturnMessage(false, '签名错误!');
}
if (!array_key_exists('account', $this->values) || $this->values['account'] == '') {
$this->ReturnMessage(false, "account参数错误!");
} else {
$this->values['account'] = trim(urldecode($this->values['account']));
}
if (!array_key_exists('pwd', $this->values) || $this->values['pwd'] == '') {
$this->ReturnMessage(false, "pwd参数错误!");
} else {
$this->values['pwd'] = trim(urldecode($this->values['pwd']));
}
if ($fields) {
foreach ($fields as $v) {
if (!array_key_exists($v, $this->values) || $this->values[$v] == '') {
$this->ReturnMessage(false, "{$v}参数错误!");
} else {
$this->values[$v] = trim(urldecode($this->values[$v]));
}
}
}
}
/**
* 给指定参数增加默认值
* @param $fields
*/
private function SetDefaultValues($fields)
{
if ($fields) {
foreach ($fields as $v) {
if (!array_key_exists($v, $this->values)) {
$this->values[$v] = '';
} else {
$this->values[$v] = urldecode($this->values[$v]);
}
}
}
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: LinJiangL
* Date: 16/10/31
* Time: 上午10:22
*/
require 'Source.php';
class SourceChigo extends Source
{
private static $account = [];
private static $app = 'chigo';
public function __construct($account)
{
self::$account = $account;
self::$cookieFilePath = PUBDIR . "cookie/" . self::$app . "_" . md5(self::$account['username']) . ".cookie";
self::$captchaFilePath = PUBDIR . "captcha/" . self::$app . "_" . md5(self::$account['username']) . ".gif";
//debug
self::$debug = false;
//判断是否登陆
$result = $this->IsLogin();
if ($result == false) {
return_msg(false, '登陆失败');
}
}
/**
* 呼叫受理-业务-服务商预约
* @param $condition
* @return array
*/
public function CallAcceptAction($condition)
{
$url = "http://58.254.204.86:9001/cus/CallAcceptAction.do";
$post = [
'adat_begin' => $condition['adat_begin'], //开始时间
'adat_end' => $condition['adat_end'], //结束时间
'mobile' => $condition['mobile'], //手机
'phone' => $condition['phone'], //电话
'read_state' => $condition['read_state'], //查阅状态: Y:已查阅; N:未查阅
'proc_state' => '1',
'ano' => $condition['ano'], //受理单号
'check_state' => 'N',
];
$xml = $this->ArrayToXml('QuerySerNode', $post);
$data = $this->CurlPostXml($url, $xml);
$data = $this->XmlToArray($data['data']);
return $data;
}
/**
* 是否登录
* @param int $num
* @return bool
*/
public function IsLogin($num = 0)
{
$flag = $this->LogonAction();
//重试5次没有登录成功,就失败
if ($num > 5) {
return false;
}
//登录失效,需要登录
if ($flag == false) {
$num++;
$this->Login();
return $this->IsLogin($num);
}
return $flag;
}
/**
* 登录
* @return array
*/
public function Login()
{
$url = "http://58.254.204.86:9001/LoginAction.do?u=cs";
$ip = $_SERVER['REMOTE_ADDR'];
$post = [
'LoginIP' => $ip,
'LoginPC' => $ip,
'LogonName' => self::$account['username'],
'Password' => self::$account['pwd'],
];
$this->SetUrlCookie($url);
$headers = $this->Header($url);
return $this->CurlPost($url, $post, $headers);
}
/**
* 判断是否登录
* @return bool
*/
public function LogonAction()
{
$url = "http://58.254.204.86:9001/security/logonAction.do";
$post = [
'logon_name' => '',
'password' => '',
'login_ip' => '',
'login_pc' => ''
];
$data = $this->CurlPostXml($url, $this->ArrayToXml('GetLogonInfo', $post));
if (!isset($data['data']) || !$data['data']) {
return false;
}
$data = $this->XmlToArray($data['data']);
//debug
$this->Debug('IsLogin', $data);
if (isset($data[0]) && $data[0]) {
if ($data[0]['user_id'] < 0) {
return false;
} else {
return true;
}
}
return false;
}
/**
* 数组转xml
* @param $providername
* @param $arr
* @return string
*/
public function ArrayToXml($providername, $arr)
{
$xml = '<?xml version="1.0" encoding="gbk" standalone="yes"?>';
$xml .= '<DATAPACKET Version="2.0"><ACTION isquery="true"/><DATASET providername="'.$providername.'"><METADATA><FIELDS>';
//ROWDATA 内容
$row = '';
if ($arr) {
//FIELDS 内容
$field = '';
foreach ($arr as $key => $val) {
$attrname = strtoupper($key);
$fieldtype = is_integer($val) ? 'r8' : 'string';
$field .= '<FIELD attrname="'. $attrname .'" fieldtype="'. $fieldtype .'" width="0" />';
$row .= $attrname . '="'. $val .'" ';
}
$xml .= $field;
}
$xml .= '</FIELDS><PARAMS/></METADATA><ROWDATA><ROW '.$row.'/></ROWDATA></DATASET></DATAPACKET>';
return $xml;
}
public function XmlToArray($xml)
{
$order = [];
if (empty($xml)) {
return $order;
}
//匹配数据
preg_match_all('/<ROW\s+([^\/|>]+)?/', $xml, $data);
if (isset($data[1]) && $data[1]) {
foreach ($data[1] as $key => $val) {
$val = preg_replace('/"\s+/', '"|||', trim($val));
$val = explode('|||', str_replace('"', '', $val));
if (!empty($val)) {
foreach ($val as $vall) {
$vall = explode("=", $vall);
$order[$key][strtolower($vall[0])] = html_entity_decode($vall[1]);
}
}
}
}
return $order;
}
public function CurlPostXml($url, $xml)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFilePath);
curl_setopt($curl, CURLOPT_COOKIEJAR, self::$cookieFilePath);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
$result = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$info = curl_getinfo($curl);
curl_close($curl);
if ($result) {
$result = iconv("GBK", "UTF-8", $result);
}
return ['code' => $code, 'info' => $info, 'data' => $result];
}
protected function CurlPost($url, $post, $headers)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFilePath);
curl_setopt($curl, CURLOPT_COOKIEJAR, self::$cookieFilePath);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
$result = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$info = curl_getinfo($curl);
curl_close($curl);
if ($result) {
$result = gzdecode($result);
$result = iconv("GBK", "UTF-8", $result);
}
return ['code' => $code, 'info' => $info, 'data' => $result];
}
/**
* 请求头信息
* @param $referer
* @return array
*/
public function Header($referer)
{
$parseUrl = parse_url($referer);
$header = [
'Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*',
'Accept-Encoding: gzip, deflate',
'Accept-Language: zh-CN',
'Content-Type: application/x-www-form-urlencoded',
'Host: ' . $parseUrl['host']. ':' .$parseUrl['port'],
'Origin: ' . $parseUrl['scheme'] . '//' .$parseUrl['host']. ':' .$parseUrl['port'],
'Referer: ' . $referer,
'Upgrade-Insecure-Requests: 1',
'User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)',
];
return $header;
}
}
\ No newline at end of file
...@@ -266,8 +266,8 @@ class SourceSuning extends Source ...@@ -266,8 +266,8 @@ class SourceSuning extends Source
} }
foreach ($srvOrder[1] as $key => $val) { foreach ($srvOrder[1] as $key => $val) {
$val = preg_replace('/"\s+/', '",', trim($val)); $val = preg_replace('/"\s+/', '"|||', trim($val));
$val = explode(',', str_replace('"', '', $val)); $val = explode('|||', str_replace('"', '', $val));
if (!empty($val)) { if (!empty($val)) {
foreach ($val as $vall) { foreach ($val as $vall) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment