PHP Tcp请求第三方接口

function socketApi()
    {
        error_reporting(E_ALL);
        set_time_limit(0);

        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if ($socket === false) {
            $error_code = socket_last_error();
            $error_msg = socket_strerror($error_code);
            die("Couldn't create socket: [$error_code] $error_msg");
        }

        $result = socket_connect($socket, $this->ip, $this->port);
        if (!$result) {
            $this->errorStr = "socket_connect() Failed.\nReason: ($result) " . socket_strerror($result) . "\n";
            return $this->errorStr;
        }

        $in = $this->bodyTit . $this->bodyXml;
        if (!socket_write($socket, $in, strlen($in))) {
            $this->errorStr = "socket_write() Failed: reason: " . socket_strerror($socket) . "\n";
            return $this->errorStr;
        }

        while ($out = @socket_read($socket, 8192)) {
            $this->outTradingType = substr($out, 87, 6);
            $this->outSubject = trim(substr($out, 93, 100));
            $this->outBodyTit = substr($out, 0, 222);
            if ($this->outTradingType == '000000') {
                $this->outBodyXml = substr($out, 222);
                $this->outXmlArr = self::xmlToArray($this->outBodyXml);

            } else {
                $this->errCode = $this->outTradingType;
                $this->errStr = $this->outSubject;
                return $this->errStr;
            }
        }

        socket_close($socket);
        return $this->errStr;
    }

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...