分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

用友T+ v2d对接,PHP版

发布时间:2023-09-06 02:04责任编辑:胡小海关键词:PHP


用友T+ V2对接PHP版本,使用Orgid验证方式。

<?phprequire_once dirname(__FILE__) . ’/../extensions/vendor/vendor/autoload.php’;use \Firebase\JWT\JWT;class TestController extends CController{ ???const appKey = ’192be680fsfjsdjfskljfsjlkgjklsdjfgkldsjlk’; ???const appSecret = ’dfasdfsa’; ???const userName = ’133333333’; ???const password = ’56456’; ???const accountNum = ’4’;//正式环境 ???function getMillisecond() ???{ ???????list($t1, $t2) = explode(’ ’, microtime()); ???????return (float)sprintf(’%.0f’, (floatval($t1) + floatval($t2)) * 1000); ???} ???public function actionTest() ???{ ???????$uri = ’http://127.0.0.1:8080/tplus/api/v2/collaborationapp/GetAnonymousTPlusToken?IsFree=1’; ???????//密钥 ???????$privateKey = <<<EOD-----BEGIN RSA PRIVATE KEY----------END RSA PRIVATE KEY-----EOD; ???????$token = [ ???????????"appkey" => self::appKey, ???????????"orgid" => "123456789", ???????????"appsecret" => self::appSecret ???????]; ???????$tokens = json_encode($token); ???????$payload = [ ???????????’sub’ => ’cjt’, ???????????’exp’ => $this->getMillisecond() + 30000, ???????????’datas’ => md5($tokens) ???????]; ???????$jwt = JWT::encode($payload, $privateKey, ’RS256’); ???????$auth = array( ???????????’appKey’ => self::appKey, ???????????’authInfo’ => $jwt, ???????????’orgId’ => ’123456789’, ???????); ???????$Authorization = base64_encode(stripslashes(json_encode($auth))); ???????$header = array( ???????????"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_POSTFIELDS, http_build_query($args)); ???????curl_setopt($ch, CURLOPT_POST, 1); ???????$response = curl_exec($ch); ???????echo "<pre>"; ???????print_r($response); ???????echo "</pre>"; ???????curl_close($ch); ???????$response = json_decode($response, true); ???????/** ???????*上:获取token ???????*/ ???????$payload = [ ???????????’sub’ => ’cjt’, ???????????’exp’ => $this->getMillisecond() + 30000, ???????????’datas’ => md5($tokens), ???????????"access_token" => $response[’access_token’], ???????]; ???????$jwt = JWT::encode($payload, $privateKey, ’RS256’); ???????$auth2 = array( ???????????’appKey’ => self::appKey, ???????????’authInfo’ => $jwt, ???????????’orgId’ => ’123456789’, ???????); ???????$Authorization2 = base64_encode(stripslashes(json_encode($auth2))); ???????$uri2 = ’http://127.0.0.1/tplus/api/v2/inventory/Query’; ???????$args = array(’Code’ => ’16742’);//测试数据 ???????$header2 = array( ???????????"Authorization:$Authorization2" . ’’, ???????); ???????$ch = curl_init(); ???????curl_setopt($ch, CURLOPT_URL, $uri2); ???????curl_setopt($ch, CURLOPT_HTTPHEADER, $header2); ???????curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); ???????curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args)); ???????curl_setopt($ch, CURLOPT_POST, 1); ???????$response1 = curl_exec($ch); ???????echo "<pre>"; ???????print_r($response1); ???????echo "</pre>"; ???????curl_close($ch); ???}}?>

疑问联系Q:657122957



用友T+ v2d对接,PHP版

原文地址:https://www.cnblogs.com/liuliwei/p/9319093.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved