<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<style>
    pre{
        background-color: #f0f0f0;
    }
</style>
<h3><div style="text-align:center">深圳国际贸易单一窗口业务对接创贸集团技术方案</div></h3>
<p>> 一. 签名</p>
<ol>
    <li>签名采用rsa 2048</li>
</ol>

<pre>
    <code class="language-injectablephp">
        /**
        * rsa 签名
        * @param array $data 请求的参数
        * @return string 签名字符串
        */
        function rsaEnSign(array $data){
            ksort($data);
            $dataString = http_build_query($data);
            if (openssl_sign($dataString, $signature, 'private_key', OPENSSL_ALGO_SHA1)) {
                return base64_encode($signature);
            } else {
                return '';
            }
        }
    </code>
</pre>

<ol start="2">
    <li>验证数据</li>
</ol>

<pre>
    <code class="language-injectablephp">
        /**
        * 验证数据来源
        * @param array $data
        * @param string $sign
        */
        function rsaVerify(array $data, string $sign){
            ksort($data);
            $dataString = http_build_query($data);
            $verified = openssl_verify($dataString, base64_decode($sign), 'public_key', OPENSSL_ALGO_SHA1);
            if ($verified === 1) {
                // 验证成功
            } elseif ($verified === 0) {
                // 验证失败
            } else {
                // 签名错误
                $errorMsg =  openssl_error_string();
            }
        }
    </code>
</pre>
<p>> 二. 接口</p>
<ol>
    <li><p>用户授权</p>
        <ul>
            <li>请求地址 /api/southern/auth</li>

            <li>请求类型 POST</li>

            <li>签名规则 rsa</li>

            <li>请求示例</li>

        </ul>

        <pre>
            <code class="language-injectablephp">
            $postData = [
                'payload' => [
                    "serviceFlowId" => "本次业务操作流水id",
                    "uniCode" => "南方电子口岸给对接方分配的 唯一ID号",
                    "mobile" => "手机",
                    "userId" => "用户 ID",
                    "userName" => "用户名称",
                    "entName" => "企业名称",
                    "scCode" => "企业统一社会信用代码"
                ],
                'sign'  =>  '',
            ];
            $postData['sign'] = rsaEnSign($postData['payload']);
            $result = Http::post('url', $postData);
            if($result['code']===200){
                // 成功
            }else{
                // 失败
            }
            </code>
        </pre>

        <ul>
            <li>返回结果 成功</li>
        </ul>

        <pre>
            <code class="language-json">
            {
                "code": 200,
                "message": "SUCCESS",
                "data": {
                    "url": [
                        {
                            "name": "ai搜索",
                            "url": "https://fob.ai.cc/ai_search?iframe_sign=xxxxx"
                        },
                        {
                            "name": "企业洞察",
                            "url": "https://fob.ai.cc/ai_company_search?iframe_sign=xxxxx"
                        },
                        ...
                    ],
                    "uniCode": "1",
                    "firstLogin": true //是否第一次登录
                },
                "success": true
            }
            </code></pre>

        <ul>
            <li>失败信息</li>

        </ul>

        <pre>
            <code class="language-json">
            {
                "code": 500,
                "message": "签名验证失败",
                "success": false
            }
            </code>
        </pre>

    </li>

    <li><p>意向登记</p>
        <ul>
            <li>请求地址 /api/southern/intention</li>

            <li>请求类型 POST</li>

            <li>签名规则 rsa</li>

            <li>请求示例</li>

        </ul>

        <pre><code class="language-injectablephp">
            $postData = [
                "guid"=>"166970C4-AF54-470A-87E4-D598463783A2",
                "busiCode"=> "CMJT04",
                "senderId"=> "XXXXXX",
                "version"=> "1.0",
                'payload' => [
                    "serviceFlowId"=> "F2310011420000001",
                    "orgName"=>"xxx",
                    "orgCode"=>"xxx",
                    "userId"=>"xxx",
                    "userName"=>"xxxxx 有限公司",
                    "contactAddress"=> "xxxxxxxxxxxxxxxxxx",
                    "contactMan"=> "xxx",
                    "contactTel"=> "xxx",
                    "email"=> "xxx",
                    "position"=> "xxx",
                    "notes"=> "xxx"
                ],
                'sign'  =>  '',
            ];
            $postData['sign'] = rsaEnSign($postData['payload']);
            $result = Http::post('url', $postData);
            if($result['code']===200){
                // 成功
            }else{
                // 失败
            }
        </code></pre>

        <ul>
            <li>返回结果 成功</li>

        </ul>

        <pre>
            <code class="language-json">
        {
            "code": 200,
            "message": "SUCCESS",
            "data": {
                "serviceFlowId": "F2310011420000001",
                "status": "11",
                "statusTime": "20230818081331",
                "statusDetail": ""
                },
            "success": true
        }
        </code>
        </pre>

        <ul>
            <li>失败信息</li>
        </ul>

        <pre><code class="language-json">
            {
                "code": 500,
                "message": "签名验证失败",
                "success": false
            }</code></pre>

    </li>

</ol>

</body>
</html>