Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
system
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
_site-res
system
Commits
70f31f44
Commit
70f31f44
authored
Jul 20, 2018
by
tufengqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复yii swoft cookie_edit 兼容文件
parent
3157e7d8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
15 deletions
+69
-15
ResponseMsg.php
classes/fpf/response/ResponseMsg.php
+57
-10
Application.php
classes/fpf/yii_component/Application.php
+11
-5
Functions.php
yiiswoft/Functions.php
+1
-0
No files found.
classes/fpf/response/ResponseMsg.php
View file @
70f31f44
...
@@ -11,6 +11,25 @@ class ResponseMsg
...
@@ -11,6 +11,25 @@ class ResponseMsg
public
$header_list
=
[];
public
$header_list
=
[];
private
static
$default_header_list
=
[];
public
function
__construct
()
{
$this
->
header_list
=
self
::
$default_header_list
;
}
public
static
function
setDefaultHeader
(
$default_header_list
)
{
foreach
(
$default_header_list
as
$key
=>
$header
)
{
self
::
$default_header_list
[
$key
]
=
$header
;
}
}
public
static
function
getDefaultHeader
()
{
return
self
::
$default_header_list
;
}
public
function
arrSuccess
(
$data
=
'ok'
,
$code
=
200
)
public
function
arrSuccess
(
$data
=
'ok'
,
$code
=
200
)
{
{
return
[
BaseConstant
::
ERROR
=>
false
,
BaseConstant
::
MSG
=>
$data
,
BaseConstant
::
CODE
=>
$code
];
return
[
BaseConstant
::
ERROR
=>
false
,
BaseConstant
::
MSG
=>
$data
,
BaseConstant
::
CODE
=>
$code
];
...
@@ -79,7 +98,9 @@ class ResponseMsg
...
@@ -79,7 +98,9 @@ class ResponseMsg
{
{
$callback
=
''
;
$callback
=
''
;
if
(
true
===
$this
->
is_support_jsonp
)
{
if
(
true
===
$this
->
is_support_jsonp
)
{
$this
->
header
(
'Content-type'
,
'application/javascript'
);
if
(
!
$this
->
isDebug
())
{
$this
->
header
(
'Content-type'
,
'application/javascript'
);
}
$callback_key
=
'jsonpcallback'
;
$callback_key
=
'jsonpcallback'
;
$callback
=
$_GET
[
$callback_key
];
$callback
=
$_GET
[
$callback_key
];
if
(
$callback
)
{
if
(
$callback
)
{
...
@@ -87,7 +108,7 @@ class ResponseMsg
...
@@ -87,7 +108,7 @@ class ResponseMsg
$json
=
$callback
.
'('
.
$json
.
')'
;
$json
=
$callback
.
'('
.
$json
.
')'
;
}
}
}
}
if
(
!
$callback
)
{
if
(
!
$callback
&&
!
$this
->
isDebug
()
)
{
$this
->
header
(
'Content-type'
,
'application/json'
);
$this
->
header
(
'Content-type'
,
'application/json'
);
}
}
return
$json
;
return
$json
;
...
@@ -106,10 +127,14 @@ class ResponseMsg
...
@@ -106,10 +127,14 @@ class ResponseMsg
}
}
if
(
$callback
)
{
if
(
$callback
)
{
$callback
=
Html
::
encode
(
$callback_key
);
$callback
=
Html
::
encode
(
$callback_key
);
$this
->
header
(
'Content-type'
,
'application/javascript'
);
if
(
!
$this
->
isDebug
())
{
$this
->
header
(
'Content-type'
,
'application/javascript'
);
}
return
$callback
.
'('
.
$json_str
.
')'
;
return
$callback
.
'('
.
$json_str
.
')'
;
}
else
{
}
else
{
$this
->
header
(
'Content-type'
,
'application/json'
);
if
(
!
$this
->
isDebug
())
{
$this
->
header
(
'Content-type'
,
'application/json'
);
}
return
$json_str
;
return
$json_str
;
}
}
}
}
...
@@ -127,10 +152,14 @@ class ResponseMsg
...
@@ -127,10 +152,14 @@ class ResponseMsg
}
}
if
(
$callback
)
{
if
(
$callback
)
{
$callback
=
Html
::
encode
(
$callback_key
);
$callback
=
Html
::
encode
(
$callback_key
);
$this
->
header
(
'Content-type'
,
'application/javascript'
);
if
(
!
$this
->
isDebug
())
{
$this
->
header
(
'Content-type'
,
'application/javascript'
);
}
return
$callback
.
'('
.
json_encode
(
$arr
)
.
')'
;
return
$callback
.
'('
.
json_encode
(
$arr
)
.
')'
;
}
else
{
}
else
{
$this
->
header
(
'Content-type'
,
'application/json'
);
if
(
!
$this
->
isDebug
())
{
$this
->
header
(
'Content-type'
,
'application/json'
);
}
return
json_encode
(
$arr
);
return
json_encode
(
$arr
);
}
}
}
}
...
@@ -148,10 +177,14 @@ class ResponseMsg
...
@@ -148,10 +177,14 @@ class ResponseMsg
$arr
=
[
'code'
=>
$code
,
'error'
=>
$code_msg
,
'ecode'
=>
$detail_code
,
'message'
=>
$detail_msg
,
'data'
=>
[]];
$arr
=
[
'code'
=>
$code
,
'error'
=>
$code_msg
,
'ecode'
=>
$detail_code
,
'message'
=>
$detail_msg
,
'data'
=>
[]];
if
(
$callback
)
{
if
(
$callback
)
{
$callback
=
Html
::
encode
(
$callback_key
);
$callback
=
Html
::
encode
(
$callback_key
);
$this
->
header
(
'Content-type'
,
'application/javascript'
);
if
(
!
$this
->
isDebug
())
{
$this
->
header
(
'Content-type'
,
'application/javascript'
);
}
return
$callback
.
'('
.
json_encode
(
$arr
)
.
')'
;
return
$callback
.
'('
.
json_encode
(
$arr
)
.
')'
;
}
else
{
}
else
{
$this
->
header
(
'Content-type'
,
'application/json'
);
if
(
!
$this
->
isDebug
())
{
$this
->
header
(
'Content-type'
,
'application/json'
);
}
return
json_encode
(
$arr
);
return
json_encode
(
$arr
);
}
}
}
}
...
@@ -174,14 +207,28 @@ class ResponseMsg
...
@@ -174,14 +207,28 @@ class ResponseMsg
$arr
=
[
'code'
=>
200
,
'ecode'
=>
200
,
'error'
=>
'OK'
,
'message'
=>
'OK'
,
'data'
=>
$success_data
];
$arr
=
[
'code'
=>
200
,
'ecode'
=>
200
,
'error'
=>
'OK'
,
'message'
=>
'OK'
,
'data'
=>
$success_data
];
if
(
$callback
)
{
if
(
$callback
)
{
$callback
=
Html
::
encode
(
$callback_key
);
$callback
=
Html
::
encode
(
$callback_key
);
$this
->
header
(
'Content-type'
,
'application/javascript'
);
if
(
!
$this
->
isDebug
())
{
$this
->
header
(
'Content-type'
,
'application/javascript'
);
}
return
$callback
.
'('
.
json_encode
(
$arr
)
.
')'
;
return
$callback
.
'('
.
json_encode
(
$arr
)
.
')'
;
}
else
{
}
else
{
$this
->
header
(
'Content-type'
,
'application/json'
);
if
(
!
$this
->
isDebug
())
{
$this
->
header
(
'Content-type'
,
'application/json'
);
}
return
json_encode
(
$arr
);
return
json_encode
(
$arr
);
}
}
}
}
/**
* 解决xdebug cookie设置不了的问题
*/
private
function
isDebug
()
{
if
(
defined
(
'SERVICE_ENV'
)
&&
(
SERVICE_ENV
===
'test'
||
SERVICE_ENV
===
'local'
)
&&
isset
(
$_GET
[
'debug'
]))
{
return
true
;
}
return
false
;
}
public
function
header
(
$key
,
$value
)
public
function
header
(
$key
,
$value
)
{
{
...
...
classes/fpf/yii_component/Application.php
View file @
70f31f44
...
@@ -6,6 +6,7 @@ use Yii;
...
@@ -6,6 +6,7 @@ use Yii;
use
yii\base\Component
;
use
yii\base\Component
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
yii\web\Response
;
use
yii\web\Response
;
use
fpf\response\ResponseMsg
;
class
Application
extends
Component
class
Application
extends
Component
{
{
...
@@ -115,20 +116,25 @@ class Application extends Component
...
@@ -115,20 +116,25 @@ class Application extends Component
$set_cookie_val
=
Yii
::
$app
->
request
->
get
(
'set_cookie_val'
,
''
);
$set_cookie_val
=
Yii
::
$app
->
request
->
get
(
'set_cookie_val'
,
''
);
if
(
$set_cookie_val
)
{
if
(
$set_cookie_val
)
{
setcookie
(
VERSION_KEY
,
$set_cookie_val
,
time
()
+
3600
*
24
*
7
);
setcookie
(
VERSION_KEY
,
$set_cookie_val
,
time
()
+
3600
*
24
*
7
);
\Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_RAW
;
$header_arr
=
[
'Content-type'
=>
'application/javascript;charset=utf-8'
]
;
\Yii
::
$app
->
response
->
headers
->
add
(
'Content-type'
,
'application/javascript;charset=utf-8'
);
$header_arr
=
array_merge
(
$header_arr
,
ResponseMsg
::
getDefaultHeader
()
);
\Yii
::
$app
->
response
->
send
(
);
echo
response
()
->
withHeaders
(
$header_arr
)
->
withContent
(
''
);
return
;
return
;
}
}
$header_arr
=
[];
$user_ip
=
Yii
::
$app
->
request
->
userIP
;
$user_ip
=
Yii
::
$app
->
request
->
userIP
;
$host_name
=
$_SERVER
[
'SERVER_NAME'
];
$host_name
=
$_SERVER
[
'SERVER_NAME'
];
$is_online_host
=
$this
->
isOnlineHost
(
$host_name
);
$is_online_host
=
$this
->
isOnlineHost
(
$host_name
);
ob_start
();
if
(
$this
->
isAllowIp
(
$user_ip
))
{
if
(
$this
->
isAllowIp
(
$user_ip
))
{
\Yii
::
$app
->
response
->
headers
->
add
(
'Content-type'
,
'text/html'
)
;
$header_arr
[
'Content-type'
]
=
'text/html'
;
\Yii
::
$app
->
response
->
send
(
);
$header_arr
=
array_merge
(
$header_arr
,
ResponseMsg
::
getDefaultHeader
()
);
// 开关开启,用户IP是公司IP,内外IP,允许打开cookie编辑
// 开关开启,用户IP是公司IP,内外IP,允许打开cookie编辑
include
(
__DIR__
.
'/views/CookieEdit.php'
);
include
(
__DIR__
.
'/views/CookieEdit.php'
);
}
}
$content
=
ob_get_contents
();
ob_end_clean
();
echo
response
()
->
withHeaders
(
$header_arr
)
->
withContent
(
$content
);
}
}
private
function
isOnlineHost
(
$host_name
)
private
function
isOnlineHost
(
$host_name
)
...
...
yiiswoft/Functions.php
View file @
70f31f44
...
@@ -7,6 +7,7 @@ class response
...
@@ -7,6 +7,7 @@ class response
foreach
(
$header_arr
as
$key
=>
$val
)
{
foreach
(
$header_arr
as
$key
=>
$val
)
{
\Yii
::
$app
->
response
->
headers
->
add
(
$key
,
$val
);
\Yii
::
$app
->
response
->
headers
->
add
(
$key
,
$val
);
}
}
\Yii
::
$app
->
response
->
send
();
return
$this
;
return
$this
;
}
}
public
function
withContent
(
$content
)
public
function
withContent
(
$content
)
...
...
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