mirror of
https://gitee.com/ShopeX/OMS
synced 2026-03-22 18:35:35 +08:00
121 lines
3.7 KiB
PHP
121 lines
3.7 KiB
PHP
<?php
|
||
/**
|
||
* Copyright © ShopeX (http://www.shopex.cn). All rights reserved.
|
||
* See LICENSE file for license details.
|
||
*/
|
||
|
||
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;
|
||
}
|
||
} |