成功返回

@param string $msg
@param string $url
@param string $data
@param int $wait
@param array $header
549229
protected function success($msg = '', $url = '', $data = '', $wait = 3, $header = [])
    {
        $this->jump(CodeConstant::CODE_SUCCESS, $msg, $url, $data, $wait, $header);
    }
1318729
public function get($url, array $data = [], array $headers = [], $cacheMinutes = 0, HttpExceptionHandler $handler = null)
    {
        return $this->send('get', $url, $data, $headers, $cacheMinutes, $handler);
    }
465278
private function msg($msg): string
    {
        // 将数组转为字符串
        if (is_array($msg) or is_object($msg) or is_bool($msg)) {
            return json($msg);
        }

        // 返回可显示的字符串
        return (string)$msg;
    }
538231
public function post($url, $data = '', array $headers = [])
    {
        return $this->executor->execute(
            $url,
            [
                CURLOPT_POST => true,
                CURLOPT_HTTPHEADER => $headers,
                CURLOPT_POSTFIELDS => $data,
            ]
        );
    }
711077
public function httpPost($url, $data) {
        $curl     = curl_init();
        $header[] = "Content-Type:application/json;charset=utf-8";
        if (!empty($header)) {
            curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //设置 HTTP 头字段的数组。格式： array('Content-type: text/plain', 'Content-length: 100')
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 500);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, 320));
        #为保证第三方服务器与微信服务器之间数据传输的安全性，所有微信接口采用https方式调用，必须使用下面2行代码打开ssl安全校验。
        #如果在部署过程中代码在此处验证失败，请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_URL, $url);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
1164172
protected function jump($code = CodeConstant::CODE_SUCCESS, $msg = '', $url = '', $data = '', $wait = 3, $header = [])
    {
        $result = [
            'code' => $code,
            'msg' => $msg,
            'url' => $this->buildUrl($url),
            'data' => $data,
            'wait' => $wait
        ];
        if ($this->request->isAjax()) {
            Response::json($result, $header);
        } else {
            $template = $this->getJumpTemplate($code);
            $content = $this->fetch($template, $result);
            Response::data($content, 'html', 200, $header);
        }
    }
496947
function recv($length = 65535, $waitall = false)
    {
        $flags = 0;
        if ($waitall)
        {
            $flags = MSG_WAITALL;
        }

        $ret = socket_recv($this->sock, $data, $length, $flags);
        if ($ret === false)
        {
            $this->set_error();
            //重试一次，这里为防止意外，不使用递归循环
            if ($this->errCode == 4)
            {
                socket_recv($this->sock, $data, $length, $waitall);
            }
            else
            {
                return false;
            }
        }
        return $data;
    }
987685
protected function error($msg = '', $url = '', $data = '', $wait = 3)
    {
        return $this->jump(0, $msg, $url, $data, $wait);
    }
1130542
public static function log(string $msg, array $data = [], int $level = self::VERB_DEBUG, array $opts = []): void
    {
        $levelName  = self::LEVEL_NAMES[$level] ?? 'INFO';
        $colorName  = self::LEVEL2TAG[$level] ?? 'info';
        $taggedName = ColorTag::add($levelName, $colorName);

        $userOpts = [];
        foreach ($opts as $n => $v) {
            if (\is_numeric($n) || \strpos($n, '_') === 0) {
                $userOpts[] = "[$v]";
            } else {
                $userOpts[] = "[$n:$v]";
            }
        }

        $optString = $userOpts ? ' ' . \implode(' ', $userOpts) : '';

        self::write(\sprintf(
            '%s [%s]%s %s %s',
            \date('Y/m/d H:i:s'),
            $taggedName,
            $optString,
            \trim($msg),
            $data ? \PHP_EOL . \json_encode($data, \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT) : ''
        ));
    }
1011470
public static function response($mdata = array(), $status = null, $msg = '')
    {
        if (is_array($mdata) && isset($mdata['msg']) && isset($mdata['data']) && isset($mdata['status']) && !$status) {
            $status = $mdata['status'];
            $msg = $mdata['msg'];
            $mdata = $mdata['data'];
        }


        if (!$status && count($mdata)) {
            $status = 200;
        } elseif (!$status) {
            $status = 400;
        }


        $response = array(
            'status' => $status,
            'msg' => $msg,
            'data' => $mdata
        );

        return $response;
    }
1226672
public function builder($ret, $data, $msg = '', $format = 'json')
    {
        @header('Content-type: application/json; charset=utf-8');
        $this->ret  = strval($ret);
        $this->time = time();
        $this->msg  = $msg;
        $this->data = $data;
        $this->format = $format;
    }
486375
public static function outputJson($data = null, $msg = '', $code = 0)
    {
        if (!$code) {
            return [
                'code' => 0,
                'msg' => $msg,
                'data' => $data,
            ];
        } else {
            return [
                'code' => $code,
                'msg' => $msg ? $msg : '未知错误',
            ];
        }
    }
1067824
public function success($message,$url='',$wait=3){
        $url=is_null($url) || $url=='' ? 'javascript:history.back(-1)' : $url;
        if($this->instance->isTemplateFile('success')){
            $this->instance->assign(['status'=>0,'message'=>$message,'url'=>url($url),'wait'=>$wait]);
            echo $this->instance->render('success');
            exit;
        }else{
            $status=true;
            require CORE_PATH.'tpl/jump.php';
            exit;
        }
    }
242478
protected function request($url, $data, $headers=array()){
        try{
            $result = $this->validate($url, $data);
            if($result !== true){
                return $result;
            }

            $params = array();
            $authObj = $this->auth();

            if($this->isCloudUser === false){
                $params['access_token'] = $authObj['access_token'];
            }

            // 特殊处理
            $this->proccessRequest($url, $params, $data, $headers);
 
            $headers = $this->getAuthHeaders('POST', $url, $params, $headers);
            $response = $this->client->post($url, $data, $params, $headers);
 
            $obj = $this->proccessResult($response['content']);

            if(!$this->isCloudUser && isset($obj['error_code']) && $obj['error_code'] == 110){
                $authObj = $this->auth(true);
                $params['access_token'] = $authObj['access_token'];
                $response = $this->client->post($url, $data, $params, $headers);
                $obj = $this->proccessResult($response['content']);
            }

            if(empty($obj) || !isset($obj['error_code'])){
                $this->writeAuthObj($authObj);
            }
        }catch(Exception $e){
            return array(
                'error_code' => 'SDK108',
                'error_msg' => 'connection or read data timeout',
            );
        }

        return $obj;
    }
107997
private function send($url, array $data = [], array $headers = [])
    {
        // Set incoming parameters as cURL options
        $this->setUrl($url);
        $this->setData($data);
        $this->setHeaders($headers);

        return $this->executeCurlRequest();
    }
939829
public function execute($url, $postString = '', array $headers = [])
    {
        return $this
            ->init($url, $postString, $headers)
            ->callCurl();
    }
526840
public function outputJson($data = null, $message = '', $status = 200)
    {
        // 错误信息返回格式可参考：[https://developer.github.com/v3/]
        if ($status != 200 && $message !== '') {
            $data = [
                'message' => $message
            ];
        }
        parent::outputJson($data, $status);
    }