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
330c149e
Commit
330c149e
authored
Aug 09, 2018
by
tufengqi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '
TRADE-169
' into 'master'
Resolve
TRADE-169
Closes
TRADE-169
See merge request
!3
parents
699aded9
58ecc596
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
45 deletions
+71
-45
BaseConstant.php
classes/fpf/response/BaseConstant.php
+1
-0
ResponseMsg.php
classes/fpf/response/ResponseMsg.php
+22
-13
ThriftServiceFactoryProxy.php
classes/fpf/thrift/ThriftServiceFactoryProxy.php
+45
-31
common.php
config/common.php
+3
-1
No files found.
classes/fpf/response/BaseConstant.php
View file @
330c149e
...
@@ -6,6 +6,7 @@ class BaseConstant
...
@@ -6,6 +6,7 @@ class BaseConstant
{
{
const
ERROR
=
'error'
;
const
ERROR
=
'error'
;
const
MSG
=
'msg'
;
const
MSG
=
'msg'
;
const
MESSAGE
=
'message'
;
const
CODE
=
'code'
;
const
CODE
=
'code'
;
const
VAL
=
'val'
;
const
VAL
=
'val'
;
const
DATA
=
'data'
;
const
DATA
=
'data'
;
...
...
classes/fpf/response/ResponseMsg.php
View file @
330c149e
...
@@ -16,6 +16,15 @@ class ResponseMsg
...
@@ -16,6 +16,15 @@ class ResponseMsg
public
function
__construct
()
public
function
__construct
()
{
{
$this
->
header_list
=
self
::
$default_header_list
;
$this
->
header_list
=
self
::
$default_header_list
;
$this
->
fzmCrossHeader
();
}
public
function
fzmCrossHeader
()
{
$this
->
header
(
'Access-Control-Allow-Origin'
,
'*'
);
$this
->
header
(
'Access-Control-Allow-Methods'
,
'POST,GET'
);
$this
->
header
(
'Access-Control-Allow-Credentials'
,
'true'
);
$this
->
header
(
'Access-Control-Allow-Headers'
,
'Authorization,FZM-REQUEST-OS,FZM-USER-IP,FZM-REQUEST-UUID,Content-Type,Content-Length'
);
}
}
public
static
function
setDefaultHeader
(
$default_header_list
)
public
static
function
setDefaultHeader
(
$default_header_list
)
...
@@ -30,14 +39,14 @@ class ResponseMsg
...
@@ -30,14 +39,14 @@ class ResponseMsg
return
self
::
$default_header_list
;
return
self
::
$default_header_list
;
}
}
public
function
arrSuccess
(
$data
=
'ok'
,
$code
=
200
)
public
function
arrSuccess
(
$data
=
BaseConstant
::
OK
,
$code
=
200
)
{
{
return
[
BaseConstant
::
ERROR
=>
false
,
BaseConstant
::
M
SG
=>
$data
,
BaseConstant
::
CODE
=>
$code
];
return
[
BaseConstant
::
ERROR
=>
false
,
BaseConstant
::
M
ESSAGE
=>
$data
,
BaseConstant
::
CODE
=>
$code
];
}
}
public
function
arrFail
(
$data
,
$code
=
-
1
)
public
function
arrFail
(
$data
,
$code
=
-
1
)
{
{
return
[
BaseConstant
::
ERROR
=>
true
,
BaseConstant
::
M
SG
=>
$data
,
BaseConstant
::
CODE
=>
$code
];
return
[
BaseConstant
::
ERROR
=>
true
,
BaseConstant
::
M
ESSAGE
=>
$data
,
BaseConstant
::
CODE
=>
$code
];
}
}
/**
/**
...
@@ -52,8 +61,8 @@ class ResponseMsg
...
@@ -52,8 +61,8 @@ class ResponseMsg
$msg
=
'unknown error'
;
$msg
=
'unknown error'
;
}
}
$view
=
[
$view
=
[
'code'
=>
$code
,
BaseConstant
::
CODE
=>
$code
,
'msg'
=>
$msg
,
BaseConstant
::
MESSAGE
=>
$msg
,
];
];
$json
=
json_encode
(
$view
);
$json
=
json_encode
(
$view
);
return
$this
->
dumpJsonData
(
$json
);
return
$this
->
dumpJsonData
(
$json
);
...
@@ -69,7 +78,7 @@ class ResponseMsg
...
@@ -69,7 +78,7 @@ class ResponseMsg
{
{
$view
=
[
$view
=
[
BaseConstant
::
CODE
=>
$code
,
BaseConstant
::
CODE
=>
$code
,
BaseConstant
::
M
SG
=>
BaseConstant
::
OK
,
BaseConstant
::
M
ESSAGE
=>
BaseConstant
::
OK
,
BaseConstant
::
DATA
=>
$data
BaseConstant
::
DATA
=>
$data
];
];
$json
=
json_encode
(
$view
);
$json
=
json_encode
(
$view
);
...
@@ -82,10 +91,10 @@ class ResponseMsg
...
@@ -82,10 +91,10 @@ class ResponseMsg
*/
*/
public
function
dealRet
(
$ret
)
public
function
dealRet
(
$ret
)
{
{
if
(
true
===
$ret
[
'error'
])
{
if
(
true
===
$ret
[
BaseConstant
::
ERROR
])
{
$this
->
jsonError
(
$ret
[
'msg'
]
?
:
'unknown error'
);
$this
->
jsonError
(
$ret
[
BaseConstant
::
MESSAGE
]
?
:
'unknown error'
);
}
else
{
}
else
{
$this
->
jsonSuccess
(
$ret
[
'msg'
]
?
:
BaseConstant
::
OK
);
$this
->
jsonSuccess
(
$ret
[
BaseConstant
::
MESSAGE
]
?
:
BaseConstant
::
OK
);
}
}
}
}
...
@@ -166,10 +175,10 @@ class ResponseMsg
...
@@ -166,10 +175,10 @@ class ResponseMsg
public
function
printOldFail
(
$code
,
$code_msg
,
$detail_code
,
$detail_msg
,
$callback_key
=
''
)
public
function
printOldFail
(
$code
,
$code_msg
,
$detail_code
,
$detail_msg
,
$callback_key
=
''
)
{
{
self
::
header
(
'Access-Control-Allow-Origin'
,
'*'
);
$this
->
header
(
'Access-Control-Allow-Origin'
,
'*'
);
self
::
header
(
'Access-Control-Allow-Methods'
,
'POST,GET'
);
$this
->
header
(
'Access-Control-Allow-Methods'
,
'POST,GET'
);
self
::
header
(
'Access-Control-Allow-Credentials'
,
'true'
);
$this
->
header
(
'Access-Control-Allow-Credentials'
,
'true'
);
self
::
header
(
'Access-Control-Allow-Headers'
,
'Authorization,FZM-REQUEST-OS,FZM-USER-IP,FZM-REQUEST-UUID,Content-Type,Content-Length'
);
$this
->
header
(
'Access-Control-Allow-Headers'
,
'Authorization,FZM-REQUEST-OS,FZM-USER-IP,FZM-REQUEST-UUID,Content-Type,Content-Length'
);
$callback
=
''
;
$callback
=
''
;
if
(
$callback_key
)
{
if
(
$callback_key
)
{
$callback
=
$_GET
[
$callback_key
]
??
''
;
$callback
=
$_GET
[
$callback_key
]
??
''
;
...
...
classes/fpf/thrift/ThriftServiceFactoryProxy.php
View file @
330c149e
...
@@ -9,8 +9,10 @@ use fpf\response\BaseConstant;
...
@@ -9,8 +9,10 @@ use fpf\response\BaseConstant;
class
ThriftServiceFactoryProxy
class
ThriftServiceFactoryProxy
{
{
private
$instance
=
null
;
private
$instance
=
null
;
private
$transport
=
null
;
private
$request_base_params
=
null
;
private
$socket
=
null
;
private
$tem_class_name
=
''
;
private
$class_name
=
''
;
private
$service_real_config
;
const
BINARY
=
0
;
const
BINARY
=
0
;
const
JSON
=
1
;
const
JSON
=
1
;
...
@@ -18,6 +20,7 @@ class ThriftServiceFactoryProxy
...
@@ -18,6 +20,7 @@ class ThriftServiceFactoryProxy
{
{
$service_default_protocol
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_default_protocol'
,
'thrift_service'
);
$service_default_protocol
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_default_protocol'
,
'thrift_service'
);
$service_default_hosts
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_default_hosts'
,
'thrift_service'
);
$service_default_hosts
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_default_hosts'
,
'thrift_service'
);
$service_default_failure_policy
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_default_failure_policy'
,
'thrift_service'
);
$service_module_hosts
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_module_hosts'
,
'thrift_service'
);
$service_module_hosts
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_module_hosts'
,
'thrift_service'
);
$check_ret
=
$this
->
checkService
(
$class_name
);
$check_ret
=
$this
->
checkService
(
$class_name
);
if
(
true
===
$check_ret
[
BaseConstant
::
ERROR
])
{
if
(
true
===
$check_ret
[
BaseConstant
::
ERROR
])
{
...
@@ -26,6 +29,8 @@ class ThriftServiceFactoryProxy
...
@@ -26,6 +29,8 @@ class ThriftServiceFactoryProxy
$service_check_arr
=
$check_ret
[
BaseConstant
::
MSG
];
$service_check_arr
=
$check_ret
[
BaseConstant
::
MSG
];
$service_name_space_str
=
$service_check_arr
[
0
];
$service_name_space_str
=
$service_check_arr
[
0
];
$service_str
=
$service_check_arr
[
1
];
$service_str
=
$service_check_arr
[
1
];
$this
->
tem_class_name
=
'\\service\\'
.
$service_name_space_str
.
'\\'
.
$service_str
;
$this
->
class_name
=
$class_name
;
if
(
empty
(
$service_module_hosts
[
$service_name_space_str
.
'-'
.
$service_str
]))
{
if
(
empty
(
$service_module_hosts
[
$service_name_space_str
.
'-'
.
$service_str
]))
{
$service_config
=
$service_default_hosts
;
$service_config
=
$service_default_hosts
;
}
else
{
}
else
{
...
@@ -47,32 +52,14 @@ class ThriftServiceFactoryProxy
...
@@ -47,32 +52,14 @@ class ThriftServiceFactoryProxy
self
::
BINARY
=>
'application/thrift-binary'
,
self
::
BINARY
=>
'application/thrift-binary'
,
self
::
JSON
=>
'application/thrift-json'
,
self
::
JSON
=>
'application/thrift-json'
,
];
];
if
(
defined
(
'IS_SWOOLE_SERVICE'
)
&&
IS_SWOOLE_SERVICE
===
true
)
{
$this
->
service_real_config
=
$service_real
;
$this
->
socket
=
new
SwoftHttpClient
(
$this
->
request_base_params
=
[
$service_real
[
'host'
],
'host'
=>
$service_real
[
'host'
],
$service_real
[
'port'
],
'port'
=>
$service_real
[
'port'
],
'/'
.
$service_name_space_str
.
'/'
.
$service_str
.
'/'
,
'uri'
=>
'/'
.
$service_name_space_str
.
'/'
.
$service_str
.
'/'
,
'http'
,
'content_type_str'
=>
$content_type_mapping
[
$content_type
],
$service_real
'content_type'
=>
$content_type
,
);
];
$this
->
socket
->
addHeaders
([
'Contents-Type'
=>
$content_type_mapping
[
$content_type
]]);
}
else
{
$this
->
socket
=
new
TCurlClient
(
$service_real
[
'host'
],
$service_real
[
'port'
],
'/'
.
$service_name_space_str
.
'/'
.
$service_str
.
'/'
,
'http'
,
$service_real
);
$this
->
socket
->
addHeaders
([
'Content-type'
=>
$content_type_mapping
[
$content_type
]]);
}
$this
->
transport
=
new
\Thrift\Transport\TBufferedTransport
(
$this
->
socket
,
1024
,
1024
);
if
(
self
::
BINARY
===
$content_type
)
{
$protocol
=
new
\Thrift\Protocol\TBinaryProtocol
(
$this
->
transport
,
$strict_read
=
true
,
$strict_write
=
true
);
}
elseif
(
self
::
JSON
===
$content_type
)
{
$protocol
=
new
\Thrift\Protocol\TJSONProtocol
(
$this
->
transport
);
}
$this
->
instance
=
new
$class_name
(
$protocol
);
}
}
private
function
checkService
(
$class_name
)
private
function
checkService
(
$class_name
)
...
@@ -100,10 +87,36 @@ class ThriftServiceFactoryProxy
...
@@ -100,10 +87,36 @@ class ThriftServiceFactoryProxy
public
function
__call
(
$name
,
$arguments
)
public
function
__call
(
$name
,
$arguments
)
{
{
$this
->
transport
->
open
();
if
(
defined
(
'IS_SWOOLE_SERVICE'
)
&&
IS_SWOOLE_SERVICE
===
true
)
{
$this
->
socket
->
setFuncUri
(
$name
);
$socket
=
new
SwoftHttpClient
(
$this
->
request_base_params
[
'host'
],
$this
->
request_base_params
[
'port'
],
$this
->
request_base_params
[
'uri'
],
'http'
,
$service_real
);
$socket
->
addHeaders
([
'Contents-Type'
=>
$this
->
request_base_params
[
'content_type_str'
]]);
}
else
{
$socket
=
new
TCurlClient
(
$this
->
request_base_params
[
'host'
],
$this
->
request_base_params
[
'port'
],
$this
->
request_base_params
[
'uri'
],
'http'
,
$this
->
service_real_config
);
$socket
->
addHeaders
([
'Content-type'
=>
$this
->
request_base_params
[
'content_type_str'
]]);
}
$transport
=
new
\Thrift\Transport\TBufferedTransport
(
$socket
,
1024
,
1024
);
if
(
self
::
BINARY
===
$this
->
request_base_params
[
'content_type'
])
{
$protocol
=
new
\Thrift\Protocol\TBinaryProtocol
(
$transport
,
$strict_read
=
true
,
$strict_write
=
true
);
}
elseif
(
self
::
JSON
===
$this
->
request_base_params
[
'content_type'
])
{
$protocol
=
new
\Thrift\Protocol\TJSONProtocol
(
$transport
);
}
$this
->
instance
=
new
$this
->
class_name
(
$protocol
);
$transport
->
open
();
$socket
->
setFuncUri
(
$name
);
$ret
=
call_user_func_array
([
$this
->
instance
,
$name
],
$arguments
);
$ret
=
call_user_func_array
([
$this
->
instance
,
$name
],
$arguments
);
$t
his
->
t
ransport
->
close
();
$transport
->
close
();
return
$ret
;
return
$ret
;
}
}
}
}
\ No newline at end of file
config/common.php
View file @
330c149e
...
@@ -2,5 +2,6 @@
...
@@ -2,5 +2,6 @@
$config
[
'coin_type'
]
=
[
$config
[
'coin_type'
]
=
[
1
=>
'USDT'
,
1
=>
'USDT'
,
2
=>
'BTC'
,
2
=>
'BTC'
,
3
=>
'ETH'
3
=>
'ETH'
,
4
=>
'BTY'
];
];
\ No newline at end of file
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