批量向所有 gateway 发包，并得到返回数组

@param string $gateway_data
@return array
@throws Exception
17727
protected static function getBufferFromAllGateway($gateway_data)
    {
        $addresses = static::getAllGatewayAddress();
        $gateway_buffer_array = array();
        $gateway_buffer = GatewayProtocol::encode($gateway_data);
        $gateway_buffer = static::$secretKey ? static::generateAuthBuffer() . $gateway_buffer : $gateway_buffer;
        foreach ($addresses as $address) {
            $gateway_buffer_array[$address] = $gateway_buffer;
        }

        return static::getBufferFromGateway($gateway_buffer_array);
    }
51058
protected function getResponse($json_request_str = '')
    {

        $response = new \sb\JSON\RPC2\Response();

        $request = null;

        if (empty($json_request_str)) {

            if (isset(\sb\Gateway::$cmd_options) && isset(\sb\Gateway::$cmd_options['json_request'])) {
                $json_request_str = \sb\Gateway::$cmd_options['json_request'];
            } elseif ($this->method == 'post' || $this->method == 'both') {
                $json_request_str = \file_get_contents("php://input");
            }

            if (is_null($request)
                    && ($this->method == 'get' || $this->method == 'both')
                    && (isset($this->request->get['method'])
                    && isset($this->request->get['params'])
                    && isset($this->request->get['id']))) {

                $request = new \sb\JSON\RPC2\Request();

                $request->id = $this->request->get['id'];
                $request->method = $this->request->get['method'];

                $params = $this->request->get['params'];

                if (!\preg_match("~[\[\{]~", \substr($params, 0, 1))) {

                    $params = \base64_decode($params);
                }

                $request->params = \json_decode($params);

                $json_request_str = \json_encode($request);
            }
        }

        if ($json_request_str) {
            if (isset($this->encryption_key)) {
                $json_request_str = $this->encryptor->decrypt($json_request_str);
            }
        }
        $request = new \sb\JSON\RPC2\Request($json_request_str);

        if (\is_null($request)) {
            $response->error = new \sb\JSON\RPC2\Error(-32700, 'Parse Error', "Data Received: " . $json_request_str);
        } else {
            $response->id = $request->id;
        }
        //log the incoming request
        $this->logRequest($json_request_str);

        $servable = false;
        $servedClass = false;
        foreach($this->served_classes as $class){
            
            if (\method_exists($class, $request->method)) {
                $reflection = new \ReflectionMethod($class, $request->method);

                if($class == $this){
                    //check for phpdocs
                    $docs = $reflection->getDocComment();
                    $non_rpc = false;
                    if (!empty($docs)) {
                        if (\preg_match("~@servable (true|false)~", $docs, $match)) {
                            $servable = $match[1] == 'true' ? true : false;
                        }
                    }
                } else {
                    $servable = $reflection->isPublic();
                }
                
                if($servable){
                    $servedClass = $class;
                    break;
                }
            }
        }

        //check for requested remote procedure
        if ($servedClass) {

            if (\is_object($request->params)) {
                $answer = \call_user_func(Array($servedClass, $request->method), $request->params);
            } else {
                if (!\is_array($request->params)) {
                    $request->params = Array();
                }
                $answer = \call_user_func_array(Array($servedClass, $request->method), $request->params);
            }
            //if they return an error from the method call, return that
            if ($answer instanceof \sb\JSON\RPC2\Error) {
                $response->error = $answer;
            } else {
                //otherwise return the answer
                $response->result = $answer;
            }
        } else {
            if (isset($request->error) && $request->error instanceOf \sb\JSON\RPC2\Error) {
                $response->error = $request->error;
            } else {
                $response->error = new \sb\JSON\RPC2\Error();
                $response->error->code = -32601;
                $response->error->message = "Procedure not found";
            }
        }

        //remove unnecessary properties
        if ($response->error instanceof \sb\JSON\RPC2\Error) {

            unset($response->result);
            if (\is_null($response->error->data)) {
                unset($response->error->data);
            }
        } else {
            unset($response->error);
        }

        //log the final response
        $this->logResponse(json_encode($response));

        return $response;
    }
134857
public function delete($data = null)
    {
        // 分析查询表达式
        $options = $this->parseExpress();
        $pk      = $this->getPk($options);
        if (isset($options['cache']) && is_string($options['cache']['key'])) {
            $key = $options['cache']['key'];
        }

        if (!is_null($data) && true !== $data) {
            if (!isset($key) && !is_array($data)) {
                // 缓存标识
                $key = 'think:' . $options['table'] . '|' . $data;
            }
            // AR模式分析主键条件
            $this->parsePkWhere($data, $options);
        } elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
            $key = $this->getCacheKey($options['where']['AND'][$pk], $options, $this->bind);
        }

        if (true !== $data && empty($options['where'])) {
            // 如果条件为空 不进行删除操作 除非设置 1=1
            throw new Exception('delete without condition');
        }
        // 生成删除SQL语句
        $sql = $this->builder->delete($options);
        // 获取参数绑定
        $bind = $this->getBind();
        if ($options['fetch_sql']) {
            // 获取实际执行的SQL语句
            return $this->connection->getRealSql($sql, $bind);
        }

        // 执行操作
        $result = $this->execute($sql, $bind);
        if ($result) {
            if (!is_array($data) && is_string($pk) && isset($key) && strpos($key, '|')) {
                list($a, $val) = explode('|', $key);
                unset($a);
                $item[$pk]     = $val;
                $data          = $item;
            }
            $options['data'] = $data;
            $this->trigger('after_delete', $options);
        }
        return $result;
    }
840203
public static function exceptionHandler($e)
    {

        $message = 'Code: ' . $e->getCode() . "\n" .
                'Path: ' . \sb\Gateway::$request->path . "\n" .
                'Message: ' . $e->getMessage() . "\n" .
                'Location: ' . $e->getFile() . "\n" .
                'Line: ' . $e->getLine() . "\n";
                if(isset(\sb\Gateway::$request)){
                    $message .= 'Request: '.\sb\Gateway::$request->request."\n";
                    if(isset(\sb\Gateway::$request->method)){
                        $message .= 'Method: '.\sb\Gateway::$request->method."\n";
                    }
                    
                    if(count(\sb\Gateway::$request->get)){
                        $message .= 'Get: '.http_build_query(\sb\Gateway::$request->get) ."\n";
                    }
                }

        if (self::$show_trace) {
            $message .= "Trace: \n\t" . str_replace("\n", "\n\t", \print_r($e->getTrace(), 1));
        }

        if (\method_exists("\App", "exception_handler")) {
            if (\App::exceptionHandler($e, $message) === false) {
                return false;
            }
        }

        if (\ini_get("display_errors") == true) {
            if (\sb\Gateway::$command_line) {
                \file_put_contents('php://stderr', "\n" . $message  . "\n");
            } else {
                echo '<pre style="background-color:red;padding:10px;color:#FFF;">' . $message . '</pre>';
            }
        }

        if (!isset(\App::$logger)) {
            \App::$logger = new \sb\Logger\FileSystem();
        }

        \App::$logger->exceptions($message);

    }
119704
public function pemDecode($pem_data)
    {
        $beg_ec_text = '-----BEGIN EC PRIVATE KEY-----';
        $end_ec_text = '-----END EC PRIVATE KEY-----';

        $decoded = '';

        $ecpemstruct = array();

        $pem_data = str_ireplace($beg_ec_text, '', $pem_data);
        $pem_data = str_ireplace($end_ec_text, '', $pem_data);
        $pem_data = str_ireplace("\r", '', trim($pem_data));
        $pem_data = str_ireplace("\n", '', trim($pem_data));
        $pem_data = str_ireplace(' ', '', trim($pem_data));

        $decoded = bin2hex(base64_decode($pem_data));

        if (strlen($decoded) < 230) {
            throw new \Exception('Invalid or corrupt secp256k1 key provided. Cannot decode the supplied PEM data.');
        }

        $ecpemstruct = array(
                'oct_sec_val'  => substr($decoded, 14, 64),
                'obj_id_val'   => substr($decoded, 86, 10),
                'bit_str_val'  => substr($decoded, 106),
        );

        if ($ecpemstruct['obj_id_val'] != '2b8104000a') {
            throw new \Exception('Invalid or corrupt secp256k1 key provided. Cannot decode the supplied PEM data.');
        }

        $private_key = $ecpemstruct['oct_sec_val'];
        $public_key  = $ecpemstruct['bit_str_val'];

        if (strlen($private_key) < 64 || strlen($public_key) < 128) {
            throw new \Exception('Invalid or corrupt secp256k1 key provided. Cannot decode the supplied PEM data.');
        }

        $this->pemDecoded = array('private_key' => $private_key, 'public_key' => $public_key);

        return $this->pemDecoded;
    }
1078005
protected static function sendToAllGateway($gateway_data)
    {
        $buffer = GatewayProtocol::encode($gateway_data);
        // 如果有businessWorker实例，说明运行在workerman环境中，通过businessWorker中的长连接发送数据
        if (static::$businessWorker) {
            foreach (static::$businessWorker->gatewayConnections as $gateway_connection) {
                /** @var TcpConnection $gateway_connection */
                $gateway_connection->send($buffer, true);
            }
        } // 运行在其它环境中，通过注册中心得到gateway地址
        else {
            $all_addresses = static::getAllGatewayAddressesFromRegister();
            foreach ($all_addresses as $address) {
                static::sendBufferToGateway($address, $buffer);
            }
        }
    }
1129470
public function getPaymentMethods()
    {
        $result = array();

        foreach ($this->data->gateways->gateway as $gateway) {
            $result[(string) $gateway->id] = (string) $gateway->description;
        }

        return $result;
    }
602079
public String sendMessage(String gatewayId, Struct data) throws PageException, IOException {
	Gateway g = getGateway(gatewayId);
	if (g.getState() != Gateway.RUNNING) throw new GatewayException("Gateway [" + gatewayId + "] is not running");
	return g.sendMessage(data);
    }
572222
public function parse($_data)
    {
        $ctrlName = Config::getField('project', 'default_ctrl_name', 'main\\main');
        $methodName = Config::getField('project', 'default_method_name', 'main');
        if (empty($this->_cache)) {
            $this->_cache = ZCache::getInstance('Php');
        }
        $fd = Request::getFd();
        $cacheData = $this->_cache->get($fd);
        if (!empty($cacheData)) {
            $_data = $cacheData . $_data;
            $this->_cache->delete($fd);
        }
        if (empty($_data)) {
            return false;
        }
        $packData = new MessagePacker($_data);
        $packLen = $packData->readInt();
        $dataLen = \strlen($_data);
        if ($packLen > $dataLen) {
            $this->_cache->set($fd, $_data);
            return false;
        } elseif ($packLen < $dataLen) {
            $this->_cache->set($fd, \substr($_data, $packLen, $dataLen - $packLen));
        }
        $packData->resetOffset(4);
        $data = [];
        $data['_cmd'] = $packData->readInt();
        $pathinfo = Config::getField('cmdlist', $data['_cmd']);
        $data['_rid'] = $packData->readInt();
        $params = $packData->readString();
        $unpackData = \json_decode(gzdecode($params), true);
        if (!empty($unpackData) && \is_array($unpackData)) {
            $data += $unpackData;
        }
        $routeMap = ZRoute::match(Config::get('route', false), $pathinfo);
        if (is_array($routeMap)) {
            $ctrlName = $routeMap[0];
            $methodName = $routeMap[1];
            if (!empty($routeMap[2]) && is_array($routeMap[2])) {
                //参数优先
                $data = $data + $routeMap[2];
            }
        }
        Request::init($ctrlName, $methodName, $data, Config::getField('project', 'view_mode', 'Zpack'));
        return true;
    }
1181258
function registerGateway( $gateway, $class_name, $description )
    {
        $gateways =& $GLOBALS["eZPaymentGateways"];
        if ( !is_array( $gateways ) )
        {
            $gateways = array();
        }

        if ( isset( $gateways[$gateway] ) )
        {
            eZDebug::writeError( "Gateway already registered: $gateway", __METHOD__ );
        }
        else
        {
            $gateways[$gateway] = array( "class_name" => $class_name, "description" => $description );
        }
    }
335662
protected static function sendBufferToGateway($address, $gateway_buffer)
    {
        // 有$businessWorker说明是workerman环境，使用$businessWorker发送数据
        if (static::$businessWorker) {
            if (!isset(static::$businessWorker->gatewayConnections[$address])) {
                return false;
            }
            return static::$businessWorker->gatewayConnections[$address]->send($gateway_buffer, true);
        }
        // 非workerman环境
        $gateway_buffer = static::$secretKey ? static::generateAuthBuffer() . $gateway_buffer : $gateway_buffer;
        $flag           = static::$persistentConnection ? STREAM_CLIENT_PERSISTENT | STREAM_CLIENT_CONNECT : STREAM_CLIENT_CONNECT;
        $client         = stream_socket_client("tcp://$address", $errno, $errmsg, static::$connectTimeout, $flag);
        return strlen($gateway_buffer) == stream_socket_sendto($client, $gateway_buffer);
    }
571313
protected static function getBufferFromSomeGateway($gateway_data_array)
    {
        $gateway_buffer_array = array();
        $auth_buffer = static::$secretKey ? static::generateAuthBuffer() : '';
        foreach ($gateway_data_array as $address => $gateway_data) {
            if ($auth_buffer) {
                $gateway_buffer_array[$address] = $auth_buffer.GatewayProtocol::encode($gateway_data);
            } else {
                $gateway_buffer_array[$address] = GatewayProtocol::encode($gateway_data);
            }
        }
        return static::getBufferFromGateway($gateway_buffer_array);
    }
539657
protected static function generateAuthBuffer()
    {
        $gateway_data         = GatewayProtocol::$empty;
        $gateway_data['cmd']  = GatewayProtocol::CMD_GATEWAY_CLIENT_CONNECT;
        $gateway_data['body'] = json_encode(array(
            'secret_key' => self::$secretKey,
        ));
        return GatewayProtocol::encode($gateway_data);
    }
893910
public static function findAll($page_request = null)
    {
        if($page_request != null){
            return self::listAllBraintreeGateways(['page' => $page_request->getPageNumber(), 'size' => $page_request->getSize() ]);
        }else {
            return self::listAllBraintreeGateways();
        }
    }
1068802
public static function getParameters($gateway)
    {
        $params = self::getConfigSetting($gateway, 'parameters');

        return is_array($params) ? $params : null;
    }
824529
private function PaymentTypes()
    {
        $factory = Omnipay::getFactory();
        // since the omnipay gateway factory only returns gateways from the composer.json extra data,
        // we should merge it with user-defined gateways from Payment.allowed_gateways
        $gateways = array_unique(array_merge(
            $factory->all(),
            array_keys(GatewayInfo::getSupportedGateways(false))
        ));

        $supportedGateways = array();

        array_walk($gateways, function ($name, $index) use (&$supportedGateways, &$factory) {
            try {
                $instance = $factory->create($name);
                $supportedGateways[$name] = $instance;
            } catch (\Exception $e) {
            }
        });

        return $supportedGateways;
    }
205491
public static function getRawData($data_str)
    {
        if (is_string($data_str) && ($data_str=="''" || $data_str=='""')) {
            $data = '';
        } else {
            $data = $data_str;
        }

        if (!empty($data) && ($data{0} == '{' || $data{0} == '[')) {
            try {
                $data = self::json_decode($data);
            } catch (\Exception $e) {
                throw $e;
            }
        }

        return $data;
    }