发送模板消息
@param string $openId
@param string $template
@param string $url 链接的网址
@param array $data [key => [value, color]]
@return bool
@throws \Exception
774260
public function send($openId, $template, $url, array $data) {
        foreach ($data as $key => &$item) {
            if (!is_array($item)) {
                $item = [
                    'value' => $item,
                    'color' => '#777'
                ];
            }
        }
        $arg = $this->getSend()->parameters([
            'touser' => $openId,
            'template_id' => $template,
            'url' => $url,
            'data' => $data
        ])->json();
        return $arg['errcode'] == 0;
    }
540188
public function template($template, $data = [])
    {
        $templatePath = self::$instance->app->findTemplate($template);
        echo self::$instance->renderTemplate($templatePath, $data);
    }
424743
private function _authLink($urn, array $data = [])
    {
        if (empty($this->home)) {
            $this->home = new CollectionDocJson($this->_host);
        }

        // fetch the link
        $link = $this->home->auth($urn);
        if (!$link) {
            throw new LinkException("Unable to retrieve $urn from the home document");
        }

        // expand the link (data will be ignored unless it's an href-template)
        $url = $link->expand($data);

        // check hints
        $method = 'GET';
        if (!empty($link->hints) && !empty($link->hints->allow)) {
            $method = strtoupper($link->hints->allow[0]);
        }

        return [$method, $url];
    }
1226079
public function sendTemplate(User $toUser, $tplId, array $data, $url = '')
    {
        $this->logger->debug('send template message', [
            'user' => $toUser['id'],
            'tplId' => $tplId,
            'url' => $url,
            'data' => $data,
        ]);

        if (!$this->isVerifiedService()) {
            return [
                'code' => -1,
                'message' => '没有开通该服务',
            ];
        }

        if (!$tplId) {
            return [
                'code' => -2,
                'message' => '缺少模板编号',
            ];
        }

        if (!$toUser['isValid'] || !$toUser['wechatOpenId']) {
            return [
                'code' => -3,
                'message' => '用户未关注',
            ];
        }

        $api = $this->createApiService();
        $api->sendTemplate([
            'touser' => $toUser['wechatOpenId'],
            'template_id' => $tplId,
            'url' => $url,
            'data' => $data,
        ]);

        return $api->getResult();
    }
881477
public function setHomePage($shop_id, $template_id, $url = null)
    {
        $data = ['shop_id' => $shop_id, 'template_id' => $template_id];
        is_null($url) && $data['struct'] = ['url' => $url];
        $url = 'https://api.weixin.qq.com/bizwifi/homepage/set?access_token=ACCESS_TOKEN';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, $data);
    }
749890
public function initiate($template = null, $data = null, $templateRootFolder = ERDIKO_APP)
    {
        $template = ($template === null) ? $this->getDefaultTemplate() : $template;
        $this->setTemplate($template);
        $this->setData($data);
        $this->setTemplateRootFolder($templateRootFolder);
    }
640517
public static function vsprintf($template, array $data, \Closure $onError = null)
    {
        if (!is_string($template)) {
            return '';
        }
        if ($template && !(empty($data))) {
            try {
                $template = vsprintf($template, $data);
            } catch (\Exception $e) {
                if ($onError) {
                    call_user_func($onError, $e);
                }
            }
        }

        return $template;
    }
1220429
protected function render(array $data = [], $template = null)
    {
        if (!$template) {
            $template = $this->template;
        }

        $template = (!empty($template)) ? $template : $this->router->directory . $this->router->class . '/' . $this->router->method;
        $data = array_merge($this->data, $data);
        if ($this->input->is_ajax_request()) {
            $this->layout = false;
        } else {
            if (!isset($data['page_title'])) {
                $data['page_title'] = 'lang:' . $this->router->class . '_title_' . $this->router->method;
            }
        }
        $view = new View($this->layout);
        $view->set($data);
        $this->output->set_output($view->render($template));

        if ($this->layout && ($csp = config_item('csp_protection'))) {
            // Add CSP
            if (!isset($csp['script-src'])) {
                $csp['script-src'] = ['self'];
            }
            $asset = Asset::getInstance();
            foreach ($asset->getScriptNonces() as $nonce) {
                $csp['script-src'][] = "'nonce-".$nonce."'";
            }
            $string = '';
            foreach ($csp as $key => $values) {
                $string .= " " . $key . " " . implode(" ", $values) .";";
            }
            if ($report = config_item('csp_report')) {
                $string .= " report-uri " . $report;
            }
            if (config_item('csp_report_only')) {
                $this->output->set_header('Content-Security-Policy-Report-Only:'. $string);
                //var_dump($csp);die;
            } else {
                $this->output->set_header('Content-Security-Policy:'. $string);
            }
        }
    }
1233288
public function render(string $template, array $data = []): string
    {
        // we store the current state of the template variables
        // so that we have isolated cases on multiple calls to render()
        $backupVariables = $this->thisShouldMakeItUniqueCodeCollabTemplateHtmlVariables;

        if (!empty($data)) {
            $this->thisShouldMakeItUniqueCodeCollabTemplateHtmlVariables = $data;
        }

        try {
            ob_start();

            /** @noinspection PhpIncludeInspection */
            require $template;
        } finally {
            $output = ob_get_clean();
        }

        $this->thisShouldMakeItUniqueCodeCollabTemplateHtmlVariables = $backupVariables;

        return $output;
    }
863195
public function getUserInfo($openid)
    {
        if (!$this->access_token && !$this->getAccessToken()) {
            return false;
        }
        $result = Tools::httpGet(self::API_URL_PREFIX . self::USER_INFO_URL . "access_token={$this->access_token}&openid={$openid}");
        if ($result) {
            $json = json_decode($result, true);
            if (empty($json) || !empty($json['errcode'])) {
                $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
                $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容！';
                return $this->checkRetry(__FUNCTION__, func_get_args());
            }
            return $json;
        }
        return false;
    }
786233
public function extend($template, $data = [], $paramName = 'body') {
		$this->extendedTemplate = $this->resolveTemplatePath($template);
		if (is_array($data)) {
			$this->extendedData = $data;
		}
		if (is_string($paramName) && $paramName) {
			$this->extendedParamName = $paramName;
		}
	}
1337844
public function getid($openid)
    {
        if (!$openid) {
            $this->setError('参数错误,缺少Openid');

            return false;
        }

        $queryStr = ['openid' => $openid];

        $res = $this->_post('getid', $queryStr);

        return $res;
    }
157838
public function sendTemplateMessageByType($touser, $type, $data, $url = null) {
		return isset($this->templates[$type]) && $this->sendTemplateMessage($touser, $this->templates[$type], $data, $url);
	}
1254193
public function editor($template, $data = null, array $params = [])
    {
        $resource = 'templates/'.$template.'/editor';
        $params = array_merge([
            'key' => $this->key,
            'workspace' => $this->workspace,
            'signature' => $this->createSignature($resource)
        ], $params);

        if ($data)
        {
            $params['data'] = self::dataToString($data);
        }

        return $this->baseUrl.$resource.'?'.http_build_query($params);
    }
802713
public function render($template, array $data = [])
    {
        ob_start();
        $this->requireTemplate($template, $data);

        while ($extend = array_pop($this->inherits)) {
            ob_clean();
            $this->requireTemplate($extend, $data);
        }

        return ob_get_clean();
    }
1257826
private function realExec($url, $data, $type, $header = [])
    {
        if (!$url || !$type) {
            return false;
        }
        if (!$data) {
            $data = [];
        }
        $header = $this->getHeader($header);
        $type = strtolower($type);

        //提供全局日志id支持.
        if ($this->globalLogId) {
            $url = URLUtil::addParameter($url, [Log::LOG_REQUEST_ID => Log::getGlobalRequestId()]);
        }
        //提供基础验证签名支持
        if ($this->basicAuthFlag) {
            if ($type == 'get') {
                $url = AuthUtil::get($url);
            } else {
                $url = URLUtil::addParameter($url, ['sign' => AuthUtil::get($data)]);
            }
        }
        $this->finalUrl = $url;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_URL, $url);

        switch ($this->postType) {
            case self::POST_FORM_DATA:
                if (!$data || !is_array($data)) {
                    $data = [];
                }
                break;
            case self::POST_FORM_URLENCODED:
                if (!$data || !is_array($data)) {
                    $data = [];
                }
                $data = http_build_query($data);
                $header[] = 'Content-Type: application/x-www-form-urlencoded';
                break;
            case self::POST_JSON:
                if (!$data) {
                    $data = '';
                } else if (is_array($data)) {
                    $data = json_encode($data);
                }
                $header[] = 'Content-Type: application/json';
                break;
            case self::POST_XML:
                $header[] = 'Content-Type: text/xml;charset=utf-8';
                break;
            case self::POST_RAW:
                if (is_array($data)) $data = json_encode($data);
                break;
            case self::POST_AJAX:
                if (is_array($data)) $data = json_encode($data);
                $header[] = 'X-Requested-With: XMLHttpRequest';
                $header[] = 'Accept:application/json, text/javascript';
                $header[] = 'Accept-Language:zh-CN,zh;q=0.8,en;q=0.6';
                $data = urlencode($data);
                break;
        }


        if ($type == 'get') {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
        } else if ($type == 'post') {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        } else if ($type == 'put') {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        } else if ($type == 'delete') {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        } else if ($type == 'head') {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
        } else {
            return false;
        }

        if ($this->userAgent) {
            curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
        }
        if ($this->cookieFile) {
            curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookieFile);
        }
        if ($header) {
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        }

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);


        if ($this->httpFormat) {
            //CURLINFO_HEADER_OUT选项可以拿到请求头信息
            curl_setopt($ch, CURLINFO_HEADER_OUT, true);
            //设置返回输出响应头
            curl_setopt($ch, CURLOPT_HEADER, true);
            $this->responseOriginalResult = curl_exec($ch);
            //获取请求头
            $this->requestHeader = curl_getinfo($ch, CURLINFO_HEADER_OUT);
            $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
            //获取响应头(根据头大小去获取响应头信息内容)
            $this->responseHeader = substr($this->responseOriginalResult, 0, $headerSize);
            if ($type == 'get') {
                $this->requestOriginalResult = $this->requestHeader;
            } else {
                $this->requestOriginalResult = $this->requestHeader . http_build_query($data);
            }
            //设置响应原始内容
            $this->result = substr($this->responseOriginalResult, $headerSize);
        } else {
            $this->result = curl_exec($ch);
        }

        $this->curlInfo = curl_getinfo($ch);
        $this->httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $this->errno = curl_errno($ch);
        $this->error = curl_error($ch);
        $this->isSuccess = $this->httpCode == 200;

        return $this->jsonResultFlag ? json_decode($this->result, true) : $this->result;
    }
1078671
public function send($touser, $template_id, $url, $topcolor, array $data, $miniprogram = NUll)
    {
        /**
         * {
         * "touser":"OPENID",
         * "template_id":"ngqIpbwh8bUfcSsECmogfXcV14J0tQlEpBO27izEYtY",
         * "url":"http://weixin.qq.com/download",
         * "miniprogram":{
         * "appid":"xiaochengxuappid12345",
         * "pagepath":"index?foo=bar"
         * },
         * "topcolor":"#FF0000",
         * "data":{
         * "first": {
         * "value":"您好，您已成功消费。",
         * "color":"#0A0A0A"
         * },
         * "keynote1":{
         * "value":"海记汕头牛肉",
         * "color":"#CCCCCC"
         * },
         * "keynote2": {
         * "value":"8703514836",
         * "color":"#CCCCCC"
         * },
         * "keynote3":{
         * "value":"2014-08-03 19:35",
         * "color":"#CCCCCC"
         * },
         * "remark":{
         * "value":"欢迎再次购买。",
         * "color":"#173177"
         * }
         * }
         */
        $params = array();
        $params['touser'] = $touser;
        $params['template_id'] = $template_id;
        $params['url'] = $url;
        if (! is_null($miniprogram)) {
            $params['miniprogram'] = $miniprogram;
        }
        $params['topcolor'] = $topcolor;
        $params['data'] = $data;
        $rst = $this->_request->post($this->_url . 'message/template/send', $params);
        return $this->_client->rst($rst);
    }