發(fā)布時間:2024-11-18 瀏覽:2318次
特價活動:>>>> 用友U8、T6、T+、T3軟件產(chǎn)品特價活動,暢捷通T+cloud、好會計、易代賬、好業(yè)財、好生意云產(chǎn)品6-8折優(yōu)惠。
對接步驟:
一、T+開發(fā)社區(qū)中心注冊成為開發(fā)者,且申請開發(fā)者,T+管理員審核通過后會有appkey、appsecret,用于登錄接口使用
二、對接接口有兩個版本:v1和v2。
三、安裝好用友T+系統(tǒng),并創(chuàng)建賬套和賬號,(賬號在對接的接口登錄驗證會使用)
四 、找到你所需的對應(yīng)版本的開發(fā)文檔,進(jìn)行開發(fā)對接
五、用什么賬號登錄,決定接口提交單據(jù)的制單人(這點(diǎn)需注意)
用友T+版本為T+12.3以上的要用v2版本的對接接口,以下用v1版本的對接接口
所做的用友T+版本為T+12.2版本,幾年前使用v1版本的對接文檔,代碼如下
$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(); //開啟會話信息
curl_setopt($ch, CURLOPT_URL, $uri); //設(shè)置會話傳輸信息
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í)行會話
curl_close($ch);
return $response;
}
//用戶賬號密碼登錄
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 : 請求地址
* $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)){ //出錯
$data[‘status‘] = false;
$data[‘message‘] = $arr->message;
return $data;
} else {
$data[‘status‘] = true;
$data[‘message‘] = $arr;
return $data;
}
}
}
近期升級用友T+系統(tǒng)到13.0以上版本,故以前對接的v1版本已不適用,現(xiàn)采用v2版本對接文檔(需從開發(fā)者中心下載v2的sdk),代碼如下:
‘xxxxx‘, // ISV賬號的AppKey
‘a(chǎn)ppsecret‘ => ‘xxxxx‘, // ISV賬號的AppSecret
‘cert‘ => ‘D:\xxxxx\xxx\cjet_pri.pem‘, // 申請ISV賬號審核通過后下發(fā)的pem版證書,使用cjet_pri.pem文件
‘orgid‘ => ‘‘, // 企業(yè)云賬號
‘a(chǎn)uthmode‘ => ‘a(chǎn)ccount‘, // 認(rèn)證模式 account-賬套 ecloud-企業(yè)云賬號模式
‘a(chǎn)ccount‘ => [ // 賬套賬號配置
‘id‘ => ‘‘, // 賬套賬號ID 賬號名
‘password‘ => ‘‘, // 賬套賬號密碼 賬號密碼
‘number‘ => ‘001‘, // 賬套編號
],
];
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)報頭(鑒權(quán))
$tplusAPI::createAuthorizationHeader($authorizationHeader);
# 創(chuàng)建訪問令牌
$tplusAPI::createAccessToken($authorizationHeader);
# 創(chuàng)建授權(quán)報頭(業(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)){ //出錯
$data[‘status‘] = false;
$data[‘message‘] = $arr->message;
return $data;
} else {
$data[‘status‘] = true;
$data[‘message‘] = $arr;
return $data;
}
}
}
?>
總結(jié):從v1接口升級到v2就在登錄機(jī)制需要變化,其他接口的參數(shù)不需變化
客服電話:400-665-0028
用友好會計、用友易代賬、用友好業(yè)財、用友好生意、用友T+Cloud試用地址__用友暢捷通公司網(wǎng)站
關(guān)鍵字:用友軟件,暢捷通軟件,財務(wù)軟件,進(jìn)銷存軟件,U9官網(wǎng),用友U8,用友T1,用友T+,用友T3,用友T6,暢捷通好會計,好生意,好業(yè)財,用友培訓(xùn)服務(wù)售后公司,暢捷通運(yùn)營培訓(xùn)服務(wù)公司