class test3{
    public $cloudUrl = "http://***.***.***.***:****/k3cloud/";
    public $login_data = array(
        '****',//帐套Id
        '****',//用户名
        '****',//密码
        2052//语言标识
    );
    public $cookie_jar = '';
    public $post_content = '';
    public function __construct(){
        $this->cookie_jar = tempnam('./tmp', 'CloudSession');
        $this->create_postdata($this->login_data);
        $result = $this->invoke_login();
//        $result = json_decode($result, 1);
//        if($result['LoginResultType'] == 1){
//            return '登录成功';
//        }
    }
    //构造Web API请求格式
    public function create_postdata($data) {
        $postdata = array(
            'format'=>1,
            'useragent'=>'ApiClient',
            'rid'=>$this->create_guid(),
            'parameters'=>$data,
            'timestamp'=>date('Y-m-d'),
            'v'=>'1.0'
        );
//        return json_encode($postdata);
        $this->post_content = json_encode($postdata);
    }
    //生成guid
    public 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;
    }
    //curl_post
    public 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;
    }
    //登陆
    public function invoke_login()
    {
        $loginurl = $this->cloudUrl.'Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc';
        return $this->invoke_post($loginurl, $this->post_content, $this->cookie_jar,TRUE);
    }
    //保存
    public function invoke_save()
    {
        $invokeurl = $this->cloudUrl.'Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save.common.kdsvc';
        return $this->invoke_post($invokeurl,$this->post_content,$this->cookie_jar,FALSE);
    }
    //审核
    public function invoke_audit()
    {
        $invokeurl = $this->cloudUrl.'Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit.common.kdsvc';
        return $this->invoke_post($invokeurl,$this->post_content,$this->cookie_jar,FALSE);
    }
    //查看
    public function invoke_view()
    {
        $invokeurl = $this->cloudUrl . 'Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.View.common.kdsvc';
        return $this->invoke_post($invokeurl, $this->post_content,$this->cookie_jar, FALSE);
    }
}
header("Content-type: text/html; charset=utf-8");
echo '<pre>';
$test3 = new test3();
//var_dump($test3->post_content);
//$login = $test3->invoke_login();
//var_dump($login);
$data = [
    'k66f7306b08614692ac95228b2d5856a8',
    [
        'CreateOrgId' => 0,
        'Number'    =>  '',
        'Id'    =>  '1'
    ]
];
$test3->create_postdata($data);
$res = $test3->invoke_view();
var_dump($res);  
                
        
        
    
 
 |