Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
weixiuhui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
蒋林
weixiuhui
Commits
2014758a
Commit
2014758a
authored
Oct 25, 2016
by
蒋林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
对外相关接口开发
parent
3a770a54
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
585 additions
and
98 deletions
+585
-98
Suning.php
application/controllers/api/Suning.php
+132
-0
base_helper.php
application/helpers/base_helper.php
+39
-3
ReceiveSuning.php
application/libraries/Receive/ReceiveSuning.php
+127
-0
Source.php
application/libraries/Source/Source.php
+75
-30
SourceSuning.php
application/libraries/Source/SourceSuning.php
+212
-65
No files found.
application/controllers/api/Suning.php
0 → 100644
View file @
2014758a
<?php
/**
* Created by PhpStorm.
* User: LinJiangL
* Date: 16/10/24
* Time: 上午10:54
*/
defined
(
'BASEPATH'
)
OR
exit
(
'No direct script access allowed'
);
/**
* Class Suning 苏宁相关接口
*
* @property api_log_model api_log_model
* @property SourceSuning SourceSuning
* @property ReceiveSuning ReceiveSuning
*/
class
Suning
extends
BaseController
{
public
function
__construct
()
{
parent
::
__construct
();
ini_set
(
"max_execution_time"
,
600
);
}
//服务订单作业条件
public
function
serviceOrderCondition
()
{
$param
=
$this
->
input
->
post
();
//验证参数
$obj
=
$this
->
receiveObj
();
$obj
->
SetValues
(
$param
);
$obj
->
CheckServiceOrderConditionValues
();
$values
=
$obj
->
GetValues
();
$this
->
saveLog
(
''
,
'serviceOrderCondition'
,
$values
);
$sourceObj
=
$this
->
sourceObj
(
$values
[
'account'
],
$values
[
'pwd'
]);
$result
=
$sourceObj
->
ServiceOrderCondition
(
$values
[
'type'
]);
$obj
->
ReturnMessage
(
true
,
''
,
$result
);
}
//服务订单作业查询
public
function
serviceOrder
()
{
$param
=
$this
->
input
->
post
();
//验证参数
$obj
=
$this
->
receiveObj
();
$obj
->
SetValues
(
$param
);
$obj
->
CheckServiceOrderValues
();
$values
=
$obj
->
GetValues
();
$this
->
saveLog
(
''
,
'serviceOrder'
,
$values
);
$sourceObj
=
$this
->
sourceObj
(
$values
[
'account'
],
$values
[
'pwd'
]);
$result
=
$sourceObj
->
ServiceOrder
(
$values
[
'type'
],
$values
);
$obj
->
ReturnMessage
(
true
,
''
,
$result
);
}
//服务订单查询条件
public
function
selectServiceOrderCondition
()
{
$param
=
$this
->
input
->
post
();
//验证参数
$obj
=
$this
->
receiveObj
();
$obj
->
SetValues
(
$param
);
$obj
->
CheckSelectServiceOrderConditionValues
();
$values
=
$obj
->
GetValues
();
$this
->
saveLog
(
''
,
'SelectServiceOrderCondition'
,
$values
);
$sourceObj
=
$this
->
sourceObj
(
$values
[
'account'
],
$values
[
'pwd'
]);
$result
=
$sourceObj
->
SelectServiceOrderCondition
();
$obj
->
ReturnMessage
(
true
,
''
,
$result
);
}
//服务订单作业查询
public
function
selectServiceOrder
()
{
$param
=
$this
->
input
->
post
();
//验证参数
$obj
=
$this
->
receiveObj
();
$obj
->
SetValues
(
$param
);
$obj
->
CheckSelectServiceOrderValues
();
$values
=
$obj
->
GetValues
();
$this
->
saveLog
(
''
,
'selectServiceOrder'
,
$values
);
$sourceObj
=
$this
->
sourceObj
(
$values
[
'account'
],
$values
[
'pwd'
]);
$result
=
$sourceObj
->
SelectServiceOrder
(
$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/SourceSuning'
,
$account
,
'SourceSuning'
);
return
$this
->
SourceSuning
;
}
private
function
receiveObj
()
{
$this
->
load
->
library
(
'Receive/ReceiveSuning'
,
null
,
'ReceiveSuning'
);
return
$this
->
ReceiveSuning
;
}
}
\ No newline at end of file
application/helpers/base_helper.php
View file @
2014758a
...
@@ -81,7 +81,8 @@ function return_msg($code=true, $msg='', $data=null)
...
@@ -81,7 +81,8 @@ function return_msg($code=true, $msg='', $data=null)
die
();
die
();
}
}
function
curl_get
(
$url
)
{
function
curl_get
(
$url
)
{
$curl
=
curl_init
();
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
0
);
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
0
);
...
@@ -100,7 +101,8 @@ function curl_get($url) {
...
@@ -100,7 +101,8 @@ function curl_get($url) {
}
}
function
curl_post
(
$url
,
$post
)
{
function
curl_post
(
$url
,
$post
)
{
$curl
=
curl_init
();
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
0
);
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
0
);
...
@@ -108,7 +110,41 @@ function curl_post($url, $post) {
...
@@ -108,7 +110,41 @@ function curl_post($url, $post) {
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
http_build_query
(
$post
));
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
http_build_query
(
$post
));
$result
=
curl_exec
(
$curl
);
$result
=
curl_exec
(
$curl
);
$code
=
curl_getinfo
(
$curl
,
CURLINFO_HTTP_CODE
);
$code
=
curl_getinfo
(
$curl
,
CURLINFO_HTTP_CODE
);
$info
=
curl_getinfo
(
$curl
);
curl_close
(
$curl
);
curl_close
(
$curl
);
return
[
'code'
=>
$code
,
'data'
=>
$result
];
return
[
'code'
=>
$code
,
'data'
=>
$result
,
'info'
=>
$info
];
}
function
phone_code
()
{
$mbox
=
imap_open
(
"
{
pop.163.com:995/pop3/ssl
}
INBOX"
,
"wxh__8888@163.com"
,
"WXH888888"
);
if
(
!
$mbox
)
{
return_msg
(
false
,
'登陆邮箱失败'
);
}
$num
=
imap_num_msg
(
$mbox
);
$result
=
[];
if
(
$num
)
{
$body
=
imap_base64
(
imap_fetchbody
(
$mbox
,
imap_num_msg
(
$mbox
),
1
));
$body
=
iconv
(
'utf8'
,
'gbk'
,
$body
);
preg_match
(
'/\d{6}/'
,
$body
,
$code
);
preg_match
(
'/2\d{3}-[\s\S]{14}/'
,
$body
,
$date
);
if
(
isset
(
$code
[
0
])
&&
isset
(
$date
[
0
]))
{
$result
[
'code'
]
=
$code
[
0
];
$result
[
'date'
]
=
$date
[
0
];
$result
[
'st'
]
=
time
()
-
strtotime
(
$result
[
'date'
]);
}
//关闭资源
imap_close
(
$mbox
);
}
return
$result
;
}
}
application/libraries/Receive/ReceiveSuning.php
0 → 100644
View file @
2014758a
<?php
require
'Receive.php'
;
class
ReceiveSuning
extends
Receive
{
public
function
CheckServiceOrderConditionValues
()
{
$fileds
=
[
'type'
];
$this
->
CheckValues
(
$fileds
);
}
public
function
CheckServiceOrderValues
()
{
$fileds
=
[
'type'
,
'siteBp'
];
$this
->
CheckValues
(
$fileds
);
$dfields
=
[
'siteBp'
,
'objectIds'
,
'startTime'
,
'endTime'
,
'processTypeName'
,
'processType'
,
];
$this
->
SetDefaultValues
(
$dfields
);
if
(
$this
->
values
[
'startTime'
])
{
$this
->
values
[
'startTime'
]
=
date
(
'Y-m-d'
,
strtotime
(
$this
->
values
[
'startTime'
]));
}
if
(
$this
->
values
[
'endTime'
])
{
$this
->
values
[
'endTime'
]
=
date
(
'Y-m-d'
,
strtotime
(
$this
->
values
[
'endTime'
]));
}
}
public
function
CheckSelectServiceOrderConditionValues
()
{
$this
->
CheckValues
();
}
public
function
CheckSelectServiceOrderValues
()
{
$fileds
=
[
'mark'
,
'siteBp'
];
$this
->
CheckValues
(
$fileds
);
$dfields
=
[
'mark'
,
'siteBp'
,
'objectIds'
,
'phone'
,
'startTime'
,
'endTime'
,
'processTypeName'
,
'processType'
,
'orderStatusName'
,
'orderStatus'
];
$this
->
SetDefaultValues
(
$dfields
);
if
(
$this
->
values
[
'startTime'
])
{
$this
->
values
[
'startTime'
]
=
date
(
'Y-m-d'
,
strtotime
(
$this
->
values
[
'startTime'
]));
}
if
(
$this
->
values
[
'endTime'
])
{
$this
->
values
[
'endTime'
]
=
date
(
'Y-m-d'
,
strtotime
(
$this
->
values
[
'endTime'
]));
}
}
/**
* 检查参数
* @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
application/libraries/Source/Source.php
View file @
2014758a
...
@@ -10,6 +10,7 @@ class Source
...
@@ -10,6 +10,7 @@ class Source
{
{
protected
static
$cookieFilePath
=
''
;
//cookie 文件路径
protected
static
$cookieFilePath
=
''
;
//cookie 文件路径
protected
static
$captchaFilePath
=
''
;
//验证码 文件路径
protected
static
$captchaFilePath
=
''
;
//验证码 文件路径
protected
static
$debug
=
false
;
protected
function
SetUrlCookie
(
$url
)
protected
function
SetUrlCookie
(
$url
)
{
{
...
@@ -56,10 +57,22 @@ class Source
...
@@ -56,10 +57,22 @@ class Source
return
[
'code'
=>
$code
,
'data'
=>
$result
];
return
[
'code'
=>
$code
,
'data'
=>
$result
];
}
}
protected
function
CurlPostHttps
(
$url
,
$post
,
$headers
)
protected
function
CurlPostHttps
(
$url
,
$post
,
$headers
,
$type
=
""
)
{
{
$cacert
=
APPPATH
.
'config/cacert.pem'
;
$cacert
=
APPPATH
.
'config/cacert.pem'
;
if
(
$type
==
'json'
)
{
foreach
(
$headers
as
$k
=>
$v
)
{
if
(
stripos
(
$v
,
'Content-Type'
)
!==
false
)
{
$headers
[
$k
]
=
'Content-Type: application/json;charset=UTF-8'
;
}
}
$post
=
json_encode
(
$post
);
}
else
{
$post
=
http_build_query
(
$post
);
}
$curl
=
curl_init
();
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_HTTPHEADER
,
$headers
);
curl_setopt
(
$curl
,
CURLOPT_HTTPHEADER
,
$headers
);
...
@@ -71,63 +84,86 @@ class Source
...
@@ -71,63 +84,86 @@ class Source
curl_setopt
(
$curl
,
CURLOPT_FOLLOWLOCATION
,
1
);
curl_setopt
(
$curl
,
CURLOPT_FOLLOWLOCATION
,
1
);
curl_setopt
(
$curl
,
CURLOPT_COOKIEFILE
,
self
::
$cookieFilePath
);
curl_setopt
(
$curl
,
CURLOPT_COOKIEFILE
,
self
::
$cookieFilePath
);
curl_setopt
(
$curl
,
CURLOPT_COOKIEJAR
,
self
::
$cookieFilePath
);
curl_setopt
(
$curl
,
CURLOPT_COOKIEJAR
,
self
::
$cookieFilePath
);
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
http_build_query
(
$post
)
);
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
$post
);
$result
=
curl_exec
(
$curl
);
$result
=
curl_exec
(
$curl
);
$info
=
curl_getinfo
(
$curl
);
$info
=
curl_getinfo
(
$curl
);
$code
=
curl_getinfo
(
$curl
,
CURLINFO_HTTP_CODE
);
curl_close
(
$curl
);
curl_close
(
$curl
);
if
(
$
info
[
'http_code'
]
==
200
)
{
if
(
$
code
==
200
)
{
$this
->
ReturnError
(
$result
,
$url
);
$this
->
ReturnError
(
$result
,
$url
);
}
}
return
[
'info'
=>
$info
,
'data'
=>
$result
];
return
[
'
code'
=>
$code
,
'
info'
=>
$info
,
'data'
=>
$result
];
}
}
protected
function
GetUrlContents
(
$url
,
$isCheck
=
true
)
protected
function
CurlGetHttps
(
$url
,
$headers
)
{
{
$cacert
=
APPPATH
.
'config/cacert.pem'
;
$curl
=
curl_init
();
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_H
EADER
,
0
);
curl_setopt
(
$curl
,
CURLOPT_H
TTPHEADER
,
$headers
);
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
15
);
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
20
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
1
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
2
);
curl_setopt
(
$curl
,
CURLOPT_CAINFO
,
$cacert
);
curl_setopt
(
$curl
,
CURLOPT_COOKIEFILE
,
self
::
$cookieFilePath
);
curl_setopt
(
$curl
,
CURLOPT_COOKIEFILE
,
self
::
$cookieFilePath
);
$rs
=
curl_exec
(
$curl
);
//执行cURL抓取页面内容
$result
=
curl_exec
(
$curl
);
$info
=
curl_getinfo
(
$curl
);
$code
=
curl_getinfo
(
$curl
,
CURLINFO_HTTP_CODE
);
curl_close
(
$curl
);
curl_close
(
$curl
);
if
(
$
isCheck
)
{
if
(
$
code
==
200
)
{
$this
->
ReturnError
(
$r
s
,
$url
);
$this
->
ReturnError
(
$r
esult
,
$url
);
}
}
return
$rs
;
return
[
'code'
=>
$code
,
'info'
=>
$info
,
'data'
=>
$result
]
;
}
}
/**
protected
function
HttpsFollowLocation
(
$url
,
$headers
)
* 获取手机验证码
* @return array
*/
public
function
GetMailPhoneCode
()
{
{
$
mbox
=
imap_open
(
"
{
pop.163.com:995/pop3/ssl
}
INBOX"
,
"wxh__8888@163.com"
,
"WXH888888"
)
;
$
cacert
=
APPPATH
.
'config/cacert.pem'
;
$num
=
imap_num_msg
(
$mbox
);
$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_SSL_VERIFYPEER
,
1
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
2
);
curl_setopt
(
$curl
,
CURLOPT_CAINFO
,
$cacert
);
curl_setopt
(
$curl
,
CURLOPT_COOKIEFILE
,
self
::
$cookieFilePath
);
curl_setopt
(
$curl
,
CURLOPT_COOKIEJAR
,
self
::
$cookieFilePath
);
$result
=
curl_exec
(
$curl
);
$info
=
curl_getinfo
(
$curl
);
$code
=
curl_getinfo
(
$curl
,
CURLINFO_HTTP_CODE
);
curl_close
(
$curl
);
$result
=
[];
if
(
$code
==
302
)
{
return
$this
->
HttpsFollowLocation
(
$info
[
'redirect_url'
],
$headers
);
}
if
(
$num
)
{
return
[
'code'
=>
$code
,
'info'
=>
$info
,
'data'
=>
$result
];
$body
=
imap_base64
(
imap_fetchbody
(
$mbox
,
imap_num_msg
(
$mbox
),
1
));
}
$body
=
iconv
(
'utf8'
,
'gbk'
,
$body
);
preg_match
(
'/\d{6}/'
,
$body
,
$code
);
protected
function
GetUrlContents
(
$url
,
$isCheck
=
true
)
preg_match
(
'/2\d{3}-[\s\S]{14}/'
,
$body
,
$date
);
{
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
0
);
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
15
);
curl_setopt
(
$curl
,
CURLOPT_COOKIEFILE
,
self
::
$cookieFilePath
);
$rs
=
curl_exec
(
$curl
);
//执行cURL抓取页面内容
curl_close
(
$curl
);
if
(
isset
(
$code
[
0
])
&&
isset
(
$date
[
0
]))
{
if
(
$isCheck
)
{
$result
[
'code'
]
=
$code
[
0
];
$this
->
ReturnError
(
$rs
,
$url
);
$result
[
'date'
]
=
$date
[
0
];
$result
[
'st'
]
=
time
()
-
strtotime
(
$result
[
'date'
]);
}
}
}
return
$r
esult
;
return
$r
s
;
}
}
protected
function
HandelHtmlScript
(
$html
)
protected
function
HandelHtmlScript
(
$html
)
...
@@ -135,6 +171,15 @@ class Source
...
@@ -135,6 +171,15 @@ class Source
return
str_replace
(
'script'
,
'scriptt'
,
$html
);
return
str_replace
(
'script'
,
'scriptt'
,
$html
);
}
}
protected
function
Debug
(
$function
,
$data
)
{
if
(
self
::
$debug
)
{
echo
"
{
$function
}
<br/>"
;
echo
"<pre>"
;
print_r
(
$data
);
}
}
protected
function
ReturnError
(
$html
,
$url
)
protected
function
ReturnError
(
$html
,
$url
)
{
{
if
(
!
$html
)
{
if
(
!
$html
)
{
...
...
application/libraries/Source/SourceSuning.php
View file @
2014758a
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment