發(fā)布時(shí)間:2024-11-18 瀏覽:2317次
對(duì)接步驟:
一、T+開發(fā)社區(qū)中心注冊(cè)成為開發(fā)者,且申請(qǐng)開發(fā)者,T+管理員審核通過后會(huì)有appkey、appsecret,用于登錄接口使用
二、對(duì)接接口有兩個(gè)版本:v1和v2。
三、安裝好用友T+系統(tǒng),并創(chuàng)建賬套和賬號(hào),(賬號(hào)在對(duì)接的接口登錄驗(yàn)證會(huì)使用)
四 、找到你所需的對(duì)應(yīng)版本的開發(fā)文檔,進(jìn)行開發(fā)對(duì)接
五、用什么賬號(hào)登錄,決定接口提交單據(jù)的制單人(這點(diǎn)需注意)
用友T+版本為T+12.3以上的要用v2版本的對(duì)接接口,以下用v1版本的對(duì)接接口
所做的用友T+版本為T+12.2版本,幾年前使用v1版本的對(duì)接文檔,代碼如下
$uri,‘a(chǎn)ccess_token‘=>$token,‘date‘=>gmdate(‘l, d M Y H:i:s‘).‘ GMT‘);
$authinfo = base64_encode(hash_hmac("sha1", stripslashes(json_encode($param)), self::appSecret, true));
$auth = array(
‘a(chǎn)ppKey‘=>self::appKey,
‘a(chǎn)uthInfo‘=>‘hmac-sha1 ‘.$authinfo,
‘paramInfo‘=>$param
);
$Authorization = base64_encode(stripslashes(json_encode($auth)));
return $Authorization;
}
//token登錄
private function tokenPost($uri,$token,$args=array()){
$Authorization = self::AuthSign($uri,$token);
$header = array(
"Content-type:application/x-www-form-urlencoded;charset=utf-8",
"Authorization:$Authorization",
);
$ch = curl_init(); //開啟會(huì)話信息
curl_setopt($ch, CURLOPT_URL, $uri); //設(shè)置會(huì)話傳輸信息
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args));
$response = curl_exec($ch); //執(zhí)行會(huì)話
curl_close($ch);
return $response;
}
//用戶賬號(hào)密碼登錄
private function post($uri,$args=array()){
$Authorization = self::AuthSign($uri);
$header = array(
"Content-type:application/x-www-form-urlencoded;charset=utf-8",
"Authorization:$Authorization",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
//開放外面開發(fā)接口
/*
* $uri : 請(qǐng)求地址
* $args : 傳遞數(shù)據(jù)
*/
public function Open($uri,$args){
//生成token
// date_default_timezone_set(‘Asia/Shanghai‘);
$data= [];
$password = base64_encode(md5($this->passWord,true));
$tokenArgs = array(‘UserName‘=>$this->userName,‘Password‘=>$password,‘AccountNumber‘=>self::AccountNumber,‘LoginDate‘=>date(‘Y-m-d‘, time()));
$res = json_decode($this->post(self::Uri . ‘TPlus/api/v1/Authorization‘,array("_args"=>json_encode($tokenArgs))));
if(!empty($res->result)){
$token = $res->access_token;
}else{
if($res->code=‘EXSM0004‘){
//用戶已登錄,需要調(diào)用重新登錄接口
$token = $res->data;
$res = json_decode($this->tokenPost(self::Uri . ‘TPlus/api/v1/Authorization/ReLogin‘,$token));
if(!isset($res->access_token)){
$data[‘status‘] = false;
$data[‘message‘] = ‘連接失敗‘;
return $data;
}
$token = $res->access_token;
}else{
//something wrong......
$data[‘status‘] = false;
$data[‘message‘] = ‘連接失敗‘;
return $data;
}
}
$arr = json_decode($this->tokenPost(self::Uri . $uri,$token,array(‘_args‘=>json_encode($args))));
if(isset($arr->message)){ //出錯(cuò)
$data[‘status‘] = false;
$data[‘message‘] = $arr->message;
return $data;
} else {
$data[‘status‘] = true;
$data[‘message‘] = $arr;
return $data;
}
}
}
近期升級(jí)用友T+系統(tǒng)到13.0以上版本,故以前對(duì)接的v1版本已不適用,現(xiàn)采用v2版本對(duì)接文檔(需從開發(fā)者中心下載v2的sdk),代碼如下:
‘xxxxx‘, // ISV賬號(hào)的AppKey
‘a(chǎn)ppsecret‘ => ‘xxxxx‘, // ISV賬號(hào)的AppSecret
‘cert‘ => ‘D:\xxxxx\xxx\cjet_pri.pem‘, // 申請(qǐng)ISV賬號(hào)審核通過后下發(fā)的pem版證書,使用cjet_pri.pem文件
‘orgid‘ => ‘‘, // 企業(yè)云賬號(hào)
‘a(chǎn)uthmode‘ => ‘a(chǎn)ccount‘, // 認(rèn)證模式 account-賬套 ecloud-企業(yè)云賬號(hào)模式
‘a(chǎn)ccount‘ => [ // 賬套賬號(hào)配置
‘id‘ => ‘‘, // 賬套賬號(hào)ID 賬號(hào)名
‘password‘ => ‘‘, // 賬套賬號(hào)密碼 賬號(hào)密碼
‘number‘ => ‘001‘, // 賬套編號(hào)
],
];
public function Open($url,$args,$setFields=‘‘){
$authorizationHeader = ‘‘;
# 實(shí)例化
$this->options[‘a(chǎn)ccount‘][‘id‘] = $this->userName;
$this->options[‘a(chǎn)ccount‘][‘password‘] = $this->passWord;
$tplusAPI = new api($this->options);
# 創(chuàng)建授權(quán)報(bào)頭(鑒權(quán))
$tplusAPI::createAuthorizationHeader($authorizationHeader);
# 創(chuàng)建訪問令牌
$tplusAPI::createAccessToken($authorizationHeader);
# 創(chuàng)建授權(quán)報(bào)頭(業(yè)務(wù))
$tplusAPI::createAuthorizationHeader($authorizationHeader);
# 業(yè)務(wù)演示
$tplusAPI::setAPIUrl(‘/‘.$url);
if(!empty($setFields)){
$tplusAPI::setFields($setFields);
}
$apiParam = [
‘_args‘ => json_encode($args, JSON_UNESCAPED_UNICODE)
];
$tplusAPI::post($authorizationHeader, $arr, $apiParam);
// var_dump($arr); exit;
if(isset($arr->message)){ //出錯(cuò)
$data[‘status‘] = false;
$data[‘message‘] = $arr->message;
return $data;
} else {
$data[‘status‘] = true;
$data[‘message‘] = $arr;
return $data;
}
}
}
?>
總結(jié):從v1接口升級(jí)到v2就在登錄機(jī)制需要變化,其他接口的參數(shù)不需變化
客服電話:400-665-0028
用友好會(huì)計(jì)、用友易代賬、用友好業(yè)財(cái)、用友好生意、用友T+Cloud試用地址__用友暢捷通公司網(wǎng)站
關(guān)鍵字:用友軟件,暢捷通軟件,財(cái)務(wù)軟件,進(jìn)銷存軟件,U9官網(wǎng),用友U8,用友T1,用友T+,用友T3,用友T6,暢捷通好會(huì)計(jì),好生意,好業(yè)財(cái),用友培訓(xùn)服務(wù)售后公司,暢捷通運(yùn)營(yíng)培訓(xùn)服務(wù)公司