按照惯例,先上图
【销售出库单】保存,
如图:已经打印出 登陆请求及登陆成功,保存请求及保存成功的返回信息。
如下代码,是完全可以直接进行运行的代码,具体详见代码中注释。
[code]
//K/3 Cloud 业务站点地址
$cloudUrl = "http://192.168.18.133/k3cloud/";
//登陆参数
$data = array(
'55b828ecd6fc90',//帐套Id
'demo',//用户名
'888888',//密码
2052//语言标识
);
//定义记录Cloud服务端返回的Session
$cookie_jar = tempnam('./tmp','CloudSession');
$post_content = create_postdata($data);
$result = invoke_login($cloudUrl,$post_content,$cookie_jar);
//$array = json_decode($result,true);
header("Content-type: text/html; charset=gb2312");
echo '';print_r('登陆请求数据:');
echo '';print_r($post_content);
echo '';print_r('登陆返回结果:');
echo '';print_r($result);
$data_model = '{"Creator":"String","NeedUpDateFields":[],"Model":{"FID":0,"FBillTypeID":{"FBillTypeID":"","FNUMBER":"XSCKD01_SYS"},"FSaleOrgId":{"FOrgID":0,"FNUMBER":"103"},"FCustomerID":{"FCUSTID":0,"FNUMBER":"CUST0002"},"FStockOrgId":{"FOrgID":0,"FNUMBER":"101.2"},"FOwnerIdHead":{"FItemID":0,"FNUMBER":"103"},"FNote":"","SAL_OUTSTOCK__FEntity":[{"FMaterialID":{"FNumber":"1.01.001"},"FUnitID":{"FNumber":"Pcs","FName":""},"FStockID":{"FNumber":"CK001"},"FStockStausID":{"FNumber":"KCZT01_SYS"},"FMustQty":1,"FRealQty":1,"FAmount":0,"FPrice":0,"FTaxPrice":0,"FDiscount":0,"FDiscountRate":0,"FIsFree":true,"FLot":{"FNUMBER":"0000"}}],"SAL_OUTSTOCK__SubHeadEntity":{"FSettleCurrID":{"FCURRENCYID":0,"FNumber":"PRE001"},"FLocalCurrID":{"FCURRENCYID":0,"FNumber":"PRE001"},"FSettleOrgID":{"FOrgID":0,"FNumber":"103"},"FExchangeTypeID":{"FRATETYPEID":0,"FNumber":"HLTX01_SYS"},"FExchangeRate":"1","FBillAllAmount":0}}}';
$data = array(
'SAL_OUTSTOCK',//业务对象标识FormId
$data_model//具体Json字串
);
$post_content = create_postdata($data);
$result = invoke_save($cloudUrl,$post_content,$cookie_jar);
//$array = json_decode($result,true);
echo '';print_r('销售出库单请求数据:');
echo '';print_r($post_content);
echo '';print_r('保存返回结果:');
echo '';print_r($result);
//登陆
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_save($cloudUrl,$post_content,$cookie_jar)
{
$invokeurl = $cloudUrl.'Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save.common.kdsvc';
return invoke_post($invokeurl,$post_content,$cookie_jar,FALSE);
}
//审核
function invoke_audit($cloudUrl,$post_content,$cookie_jar)
{
$invokeurl = $cloudUrl.'Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit.common.kdsvc';
return invoke_post($invokeurl,$post_content,$cookie_jar,FALSE);
}
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;
}
?>[/code]