php 如何查询即时库存
金蝶云社区-王宇uk1FjW
王宇uk1FjW
0人赞赏了该文章 1,996次浏览 未经作者许可,禁止转载编辑于2017年03月15日 16:47:47

我做到现在这样该怎样才能查询回来数据?老是报错。哪里没配置好?数据格式?接口地址?
先贴出返回数据,再贴出代码,实在无力吐槽,为什么找个接口的资料都那么的难?表里的字段名我该去哪里找?
登陆请求数据:{"format":1,"useragent":"ApiClient","rid":"{3927AF3F-4780-17AD-C159-731AEEA853BF}","parameters":["89283942048290348","xxx","xxx",2052],"timestamp":"2017-03-15","v":"1.0"}登陆返回结果:{"Message":null,"MessageCode":"CheckPasswordPolicy","LoginResultType":1......

查询即时库存请求数据:"{\\\"FormId\\\":\\\"STK_Inventory\\\",\\\"FieldKeys\\\":\\\"FID\\\",\\\"FilterString\\\":\\\"\\\",\\\"OrderString\\\":\\\"FID ASC\\\",\\\"TopRowCount\\\":\\\"0\\\",\\\"StartRow\\\":\\\"0\\\",\\\"Limit\\\":\\\"10\\\"}"查询返回结果:response_error:{"InnerExWrapper":{"IsEmpty":false,"Data":{},"HelpLink":null,"Message":"调用的目标发生了异常。","Source":null,"StackTrace":" 在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)\r\n 在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)\r\n 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n 在 Kingdee.BOS.ServiceFacade.KDServiceFx.ServiceExecutor.Execute(KDServiceContext context, ServiceType svcType, String[] paraValues, SerializerProxy serializeProxy, ServiceType beginMethod)","TargetSite":null,"ExceptionType":"System.Reflection.TargetInvocationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","InnerException":{"IsEmpty":false,"Data":{},"HelpLink":null,"Message":"值不能为 null。\r\n参数名: s","Source":null,"StackTrace":" 在 Kingdee.BOS.WebApi.FormService.QueryBillService.ExecuteBillQuery(String data)\r\n 在 Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery(String data)","TargetSite":null,"ExceptionType":"System.ArgumentNullException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","InnerException":null}},"ClassName":"Kingdee.BOS.ServiceFacade.ServiceException","Message":"值不能为 null。\r\n参数名: s","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" 在 Kingdee.BOS.ServiceFacade.KDServiceFx.ServiceExecutor.Execute(KDServiceContext context, ServiceType svcType, String[] paraValues, SerializerProxy serializeProxy, ServiceType beginMethod)\r\n 在 Kingdee.BOS.ServiceFacade.KDServiceFx.ExecuteServiceModule.OnProcess(KDServiceContext context)\r\n 在 Kingdee.BOS.ServiceFacade.KDServiceFx.ModulePipeline.ExcuteRequest(KDServiceContext context)\r\n 在 Kingdee.BOS.ServiceFacade.KDServiceFx.RequestExcuteRuntime.BeginRquest(RequestExtractor requestExtractor, WebContext webCtx)\r\n 在 Kingdee.BOS.ServiceFacade.KDServiceFx.RequestExcuteRuntime.StartRequest(RequestExtractor requestExtractor, WebContext context)\r\n 在 Kingdee.BOS.ServiceFacade.KDServiceFx.KDSVCHandler.ExecuteRequest(WebContext ctx, RequestExtractor requestExtractor)\r\n 在 Kingdee.BOS.ServiceFacade.KDServiceFx.KDSVCHandler.ProcessRequestInternal(WebContext webCtx, RequestExtractor requestExtractor)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nExecute\nKingdee.BOS.ServiceFacade.KDServiceFx, Version=6.0.413.1, Culture=neutral, PublicKeyToken=null\nKingdee.BOS.ServiceFacade.KDServiceFx.ServiceExecutor\nSystem.String Execute(Kingdee.BOS.ServiceFacade.KDServiceFx.KDServiceContext, Kingdee.BOS.ServiceFacade.KDServiceFx.ServiceType, System.String[], Kingdee.BOS.ServiceFacade.SerializerProxy, Kingdee.BOS.ServiceFacade.KDServiceFx.ServiceType)","HResult":-2147467259,"Source":"Kingdee.BOS.ServiceFacade.KDServiceFx","WatsonBuckets":null,"_httpCode":500}
PHP代码
//K/3 Cloud 业务站点地址
$cloudUrl = "http://localhost/K3cloud/";
//登陆参数
$data = array(
'89283942048290348',//帐套Id
'zhanghao',//用户名
'mima',//密码
2052//语言标识
);
//定义记录Cloud服务端返回的Session
$cookie_jar = tempnam('./tmp','CloudSession');
$post_content = create_postdata($data);

$result = invoke_login($cloudUrl,$post_content,$cookie_jar);
header("Content-type: text/html; charset=utf-8");//gb2312
echo '

';print_r('登陆请求数据:');
echo '
';print_r($post_content);
echo '
';print_r('登陆返回结果:'); 
echo '
';print_r($result); 
$data_model = '{\"FormId\":\"STK_Inventory\",\"FieldKeys\":\"FID\",\"FilterString\":\"\",\"OrderString\":\"FID ASC\",\"TopRowCount\":\"0\",\"StartRow\":\"0\",\"Limit\":\"10\"}';
$post_content = json_encode($data_model);

$result = invoke_ExecuteBillQuery($cloudUrl,$post_content,$cookie_jar);

//$array = json_decode($result,true);
echo '
';print_r('查询即时库存请求数据:'); 
echo '
';print_r($post_content); 

echo '
';print_r('查询返回结果:'); 
echo '
';echo $result; 
//表单数据查询接口

function invoke_ExecuteBillQuery($cloudUrl,$post_content,$cookie_jar)
{
$loginurl = $cloudUrl.'Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc';
// $loginurl = $cloudUrl.'Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.View.common.kdsvc';
return invoke_post($loginurl,$post_content,$cookie_jar,TRUE);
}
//登陆
function invoke_login($cloudUrl,$post_content,$cookie_jar)
{
$loginurl = $cloudUrl.'Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc';
return invoke_post($loginurl,$post_content,$cookie_jar,TRUE);
}
function invoke_post($url,$post_content,$cookie_jar,$isLogin)
{
$ch = curl_init($url);
$this_header = array(
'Content-Type: application/json',
'Content-Length: '.strlen($post_content)
);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($isLogin){
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
}
else{
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

$result = curl_exec($ch);
curl_close($ch);

return $result;
}

//构造Web API请求格式
function create_postdata($args) {
$postdata = array(
'format'=>1,
'useragent'=>'ApiClient',
'rid'=>create_guid(),
'parameters'=>$args,
'timestamp'=>date('Y-m-d'),
'v'=>'1.0'
);
return json_encode($postdata);
}

//生成guid
function create_guid() {
$charid = strtoupper(md5(uniqid(mt_rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12)
.chr(125);// "}"
return $uuid;
}