用友T+ v2d对接,PHP版

Posted liuliwei

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用友T+ v2d对接,PHP版相关的知识,希望对你有一定的参考价值。


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

<?php
require_once dirname(__FILE__) . ’/../extensions/vendor/vendor/autoload.php’;

use FirebaseJWTJWT;

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版的主要内容,如果未能解决你的问题,请参考以下文章

用友YonSuite与旺店通数据集成对接-技术篇2

万物皆可集成系列:低代码释放用友深度价值—系统对接集成

万物皆可集成系列:低代码释放用友深度价值—系统对接集成

万物皆可集成系列:低代码释放用友深度价值—系统对接集成

外系统对接用友U8

用友时空B/S表单外挂(接口)程序操作说明文档