mirror of
https://gitee.com/ShopeX/OMS
synced 2026-03-23 02:45:33 +08:00
132 lines
4.2 KiB
PHP
132 lines
4.2 KiB
PHP
<?php
|
|
/**
|
|
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
class openapi_ctl_admin_test extends desktop_controller{
|
|
|
|
/**
|
|
* test
|
|
* @return mixed 返回值
|
|
*/
|
|
public function test(){
|
|
$conf = openapi_conf::getMethods();
|
|
|
|
foreach($conf as $k => $v){
|
|
try{
|
|
$paramsObj = kernel::single('openapi_api_params_v1_'.$k);
|
|
} catch (Throwable $e) {
|
|
list($app, $class) = explode('.', $k);
|
|
$paramsObj = kernel::single($app.'_openapi_params_v1_'.$class);
|
|
}
|
|
foreach ($v['methods'] as $method => $vv){
|
|
if( $paramsObj->getAppParams($method) ){
|
|
$list[] = $k.'.'.$method;
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->pagedata['list'] = $list;
|
|
$this->page('admin/test/test.html');
|
|
}
|
|
|
|
/**
|
|
* ajaxResult
|
|
* @return mixed 返回值
|
|
*/
|
|
public function ajaxResult(){
|
|
if(!$_POST['apiName']) return;
|
|
$k = substr($_POST['apiName'], 0, strrpos($_POST['apiName'], '.'));
|
|
$function = substr($_POST['apiName'], strrpos($_POST['apiName'], '.')+1);
|
|
try{
|
|
$obj = kernel::single('openapi_api_params_v1_'.$k);
|
|
} catch (Throwable $e) {
|
|
list($app, $class) = explode('.', $k);
|
|
$obj = kernel::single($app.'_openapi_params_v1_'.$class);
|
|
}
|
|
$list = $obj->getAppParams($function);
|
|
$description = $obj->description($function);
|
|
|
|
|
|
$this->pagedata['list'] = $list;
|
|
$this->pagedata['post'] = $_POST;
|
|
$this->pagedata['description'] = $description;
|
|
|
|
//display
|
|
$this->display('admin/test/apiForm.html');
|
|
}
|
|
|
|
/**
|
|
* result
|
|
* @return mixed 返回值
|
|
*/
|
|
public function result(){
|
|
$url =kernel::base_url(1).kernel::url_prefix().'/openapi/rpc/service/';
|
|
$token = $_POST['token'];
|
|
$method = $_POST['method1'];
|
|
unset($_POST['token']);
|
|
unset($_POST['method1']);
|
|
|
|
$params = $_POST;
|
|
$params['ver'] = 1;
|
|
$params['method'] = $method;
|
|
|
|
$params['type'] = $_POST['data_format'];
|
|
$params['charset'] = 'utf-8';
|
|
|
|
//$params['page_no'] = 1;
|
|
//$params['page_size'] = 100;
|
|
if($params['items']){
|
|
$items = explode(";", $params['items']);
|
|
foreach ($items as $item){
|
|
if($item){
|
|
$tempa=explode(",", $item);
|
|
foreach ($tempa as $tempb){
|
|
$tempc=explode(":", $tempb);
|
|
$tempd[$tempc[0]]=$tempc[1];
|
|
}
|
|
$tempe[]=$tempd;
|
|
}
|
|
}
|
|
$params['items']= json_encode($tempe);
|
|
}
|
|
$sign = $this->gen_sign($params ,$token);
|
|
$params['sign'] = $sign;
|
|
$http = kernel::single('base_httpclient');
|
|
$response = $http->set_timeout($time_out)->post($url,$params ,$headers);
|
|
echo $response;
|
|
}
|
|
|
|
private function gen_sign($params,$token){
|
|
|
|
if(!$token){
|
|
return false;
|
|
}
|
|
return strtoupper(md5(strtoupper(md5($this->assemble($params))).$token));
|
|
}
|
|
|
|
private function assemble($params)
|
|
{
|
|
if(!is_array($params)) return null;
|
|
ksort($params, SORT_STRING);
|
|
$sign = '';
|
|
foreach($params AS $key=>$val){
|
|
if(is_null($val)) continue;
|
|
if(is_bool($val)) $val = ($val) ? 1 : 0;
|
|
$sign .= $key . (is_array($val) ? $this->assemble($val) : $val);
|
|
}
|
|
return $sign;
|
|
}
|
|
} |