记录php对接金蝶接口

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);

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值