1. 程式人生 > >用友T+ v2d對接,PHP版

用友T+ v2d對接,PHP版

lose exe secret access acc etop username time field

  

<?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‘;//正式環境 //‘http://211.149.155.16:8080 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); } } ?>

用友T+ v2d對接,PHP版