退款
@param array $args
@return bool|mixed|null
@throws Exception
776586
public function refund(array $args) {
        $data = $this->getRefund()->parameters($this->merge($args))->text();
        if (empty($data)) {
            return false;
        }
        if ($data['return_code'] != 'SUCCESS') {
            throw new Exception($data['return_msg']);
        }
        if ($data['result_code'] != 'SUCCESS') {
            throw new Exception($data['err_code_des']);
        }
        return $data;
    }
1141147
public function handle(array $args)
  {
    switch ( strtoupper(request()->getMethod()) ) {
      case "GET"    : return $this->handleGET($args); break;
      case "POST"   : return $this->handlePOST($args); break;
      case "PUT"    : return $this->handlePUT($args); break;
      case "PATCH"  : return $this->handlePATCH($args); break;
      case "DELETE" : return $this->handleDELETE($args); break;
      case "HEAD"   : return $this->handleHEAD($args); break;
      case "OPTIONS": return $this->handleOPTIONS($args); break;
      default       : return $this->handleCUSTOM($args); break;
    }
  }
299019
protected function optionFor(string $arg)
    {
        foreach ($this->_options as $option) {
            if ($option->is($arg)) {
                return $option;
            }
        }

        return null;
    }
377638
public static function parseArgs(array $args)
    {
        $result = [
            'name'   => null,
            'work'   => null,
            'weight' => 1,
            'backup' => false,
        ];
        foreach ($args as $arg) {
            //find work
            if (is_callable($arg)) {
                $result['work'] = $arg;
            }
            //find weight, backup, name
            if (is_string($arg) || is_numeric($arg)) {
                $arg = preg_replace('/\s+/', ' ', "$arg");
                $subArgs = explode(' ', trim($arg));
                foreach ($subArgs as $subArg) {
                    if (preg_match('/^[0-9]+$/', $subArg)) {
                        $result['weight'] = intval($subArg);
                    } elseif (preg_match('/(backup)/', strtolower($subArg))) {
                        $result['backup'] = true;
                    } else {
                        $result['name'] = $subArg;
                    }
                }
            }
        }

        return $result;
    }
317638
private function parseArgs(array $args) : string
    {
        if (!is_array($args)) return false;
        $components = array();
        if (count($args) == 1 && is_string($args[0])) {
            $components['src'] = $args[0];
            return $this->makeLink($components);
        } elseif (count($args) == 1 && is_array($args)) {
            $components = $args[0];
            return $this->makeLink($components);
        } elseif (count($args) == 2 && is_string($args[0]) && is_array($args[1])) {
            $args[1]['src'] = $args[0];
            $components = $args[1];
            return $this->makeLink($components);
        } elseif (count($args) == 2 && is_string($args[0]) && is_string($args[1])) {
            return '<script type="'.$args[1].'">'."\n".$args[0]."\n</script>\n";
        }
        Core::i()->log->warning('Unable to interpret script. Not added.');
        return false;
    }
868660
public function handle($args = null)
    {
        $this->_args = $args !== null ? $args : $GLOBALS['argv'];

        list(, $controllerName, $commandName) = array_pad($this->_args, 3, null);
        if ($commandName !== null && $commandName[0] === '-') {
            $commandName = null;
        }

        if ($controllerName === 'list') {
            $controllerName = 'help';
            $commandName = $commandName ?: 'list';
        } elseif ($controllerName === null) {
            $controllerName = 'help';
        } elseif ($controllerName === 'help' && $commandName !== null && $commandName !== 'list') {
            $controllerName = $commandName;
            $commandName = 'help';
        }

        $controllerName = Text::camelize($controllerName);
        $commandName = lcfirst(Text::camelize($commandName));

        $controllerClassName = null;

        if ($this->alias->has('@ns.cli')) {
            $namespaces = ['@ns.cli', 'ManaPHP\\Cli\\Controllers'];
        } else {
            $namespaces = ['ManaPHP\\Cli\\Controllers'];
        }

        foreach ($namespaces as $prefix) {
            $className = $this->alias->resolveNS($prefix . '\\' . $controllerName . 'Controller');

            if (class_exists($className)) {
                $controllerClassName = $className;
                break;
            }
        }

        if (!$controllerClassName) {
            $guessed = $this->_guessController($controllerName);
            if ($guessed) {
                $controllerClassName = $guessed;
                $controllerName = basename(substr($controllerClassName, strrpos($controllerClassName, '\\')), 'Controller');
            } else {
                return $this->console->error(['`:command` command is not exists', 'command' => lcfirst($controllerName) . ':' . $commandName]);
            }
        }

        $controllerInstance = $this->_di->getShared($controllerClassName);
        if ($commandName === '') {
            $commands = $this->_getCommands($controllerClassName);
            if (count($commands) === 1) {
                $commandName = $commands[0];
            } elseif (in_array('default', $commands, true)) {
                $commandName = 'default';
            } else {
                $commandName = 'help';
            }
        }

        if ($commandName !== 'help' && in_array('--help', $this->_args, true)) {
            $commandName = 'help';
        }

        if (!method_exists($controllerInstance, $commandName . 'Command')) {
            $guessed = $this->_guessCommand($controllerClassName, $commandName);
            if (!$guessed) {
                return $this->console->error(['`:command` sub command is not exists', 'command' => lcfirst($controllerName) . ':' . $commandName]);
            } else {
                $commandName = $guessed;
            }
        }

        try {
            $r = $this->commandInvoker->invoke($controllerInstance, $commandName);
        } /** @noinspection PhpRedundantCatchClauseInspection */
        catch (ArgumentsException $e) {
            return $this->console->error($e->getMessage());
        }

        return is_int($r) ? $r : 0;
    }
351886
protected function getEnvironmentArgument(array $args)
	{
		foreach ($args as $k => $v)
		{
			if (substr($v, 0, strlen('--env')) == '--env')
			{
				return $v;
			}
		}

		return null;
	}
336162
public function transfer(array $args) {
        $data = $this->getTransfer()->parameters($this->merge($args))->text();
        if (empty($data)) {
            return false;
        }
        if ($data['return_code'] != 'SUCCESS') {
            throw new Exception($data['return_msg']);
        }
        if ($data['result_code'] != 'SUCCESS') {
            throw new Exception($data['err_code_des']);
        }
        return $data;
    }
1304645
public static function prioritize($args = [])
    {
        $value = null;
        foreach ($args as $arg) {
            if (!empty($arg)) {
                $value = $arg;
                break;
            }
        }
        return $value;
    }
810601
public function get(array $args)
    {
        if (count($args) === 0) {
            return $this->store;
        } elseif (isset($this->store[$args[0]]) === true) {
            return $this->store[$args[0]];
        } else {
            return null;
        }
    }
863258
public static function coalesce($args)
    {
        $args = func_get_args();
        foreach ($args as &$arg) {
            if (isset($arg) && !empty($arg)) {
                return $arg;
            }
        }

        return null;
    }
399842
public function sign($args) {
        if (empty($this->key)) {
            throw new Exception('KEY IS NEED');
        }
        ksort($args);
        reset($args);
        $arg = '';
        foreach ($args as $key => $item) {
            if (Http::isEmpty($item) ||
                in_array($key, $this->ignoreKeys)) {
                continue;
            }
            $arg .= "{$key}={$item}&";
        }
        $signContent = $arg.'key='.$this->key;
        if (!isset($args['sign_type']) || $args['sign_type'] == 'MD5') {
            return strtoupper(md5($signContent));
        }
        return strtoupper(hash_hmac('sha256', $signContent, $this->key, false));
    }
238194
protected function invokeRpc($method, $args)
    {
        if (empty($this->rpc['method']) || ! in_array($method, $this->rpc['method']) || empty($this->rpc['host'])) {
            throw new Exception('非法调用:' .$method . '@' . get_class($this));
        }

        $rpc = new Client($this->rpc['host']);

        return $rpc->exec($this->modName, $method, $args);
    }
1256010
public function error(
        $msg,
        array $args = array(),
        \Exception $exception = null
    ) {
        return $this->log(\Plop\ERROR, $msg, $args, $exception);
    }
870950
public static function decode(array $args): int
    {
        if ($cursor = Arr::get($args, 'after')) {
            return (int) base64_decode($cursor);
        }

        return 0;
    }
683385
public function orderQr(array $args = array()) {
        $data = $this->order($args);
        if ($data === false) {
            return false;
        }
        if (array_key_exists('code_url', $data)) {
            return (new QrCode())->create($data['code_url']);
        }
        throw new Exception('unkown');
        //return (new QrCode())->create($this->getUrl('orderQr', $data));
    }
1178314
public function query($sql, array $args = [])
    {
        if ($args) {
            $sql = \wf\db\QueryBuilder::format($sql, $args);
        }
        $sql = \wf\db\QueryBuilder::tablePrefix($sql, $this->cfg['tablePrefix']);
                            
        // 记录数据库查询次数
        $this->execTimes ++;
        $this->log[] = $sql;
        
        $query = $this->dbh->query($sql);        
        if(false === $query) {
            $this->log[] = $this->getLastErr();
            throw new \wf\db\Exception($this->getLastErr());
        }
        
        return $query;
    }