标签:val 11.14 secret sub ips sprint control close xtend
用友T+ V2对接PHP版本,使用Orgid验证方式。
<?php require_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
标签:val 11.14 secret sub ips sprint control close xtend
原文地址:https://www.cnblogs.com/liuliwei/p/9319093.html