public function formatTemplateMessage ($templateID, $openID, $url, array $data, array $options = [])
    {
        $json = [
            'touser'      => (string)$openID,
            'template_id' => (string)$templateID,
            'url'         => (string)$url,
            'data'        => [],
        ];

        if (isset($options['color'])) {
            $json['topcolor'] = '#' . strtoupper(ltrim($options['color'], '#'));
        }

        foreach ($data as $fieldName => $fieldValue) {
            if (! is_array($fieldValue)) {
                $json['data'][$fieldName] = ['value' => $fieldValue];
            } else {
                $json['data'][$fieldName] = [
                    'value' => $fieldValue['value'],
                ];

                if (isset($fieldValue['color'])) {
                    $json['data'][$fieldName]['color'] = '#' . strtoupper(ltrim($fieldValue['color'], '#'));
                }
            }
        }

        return $json;
    }
public function formatTemplateMessage ($templateID, $openID, $url, array $data, array $options = [])
    {
        $json = [
            'touser'      => (string)$openID,
            'template_id' => (string)$templateID,
            'url'         => (string)$url,
            'data'        => [],
        ];

        if (isset($options['color'])) {
            $json['topcolor'] = '#' . strtoupper(ltrim($options['color'], '#'));
        }

        foreach ($data as $fieldName => $fieldValue) {
            if (! is_array($fieldValue)) {
                $json['data'][$fieldName] = ['value' => $fieldValue];
            } else {
                $json['data'][$fieldName] = [
                    'value' => $fieldValue['value'],
                ];

                if (isset($fieldValue['color'])) {
                    $json['data'][$fieldName]['color'] = '#' . strtoupper(ltrim($fieldValue['color'], '#'));
                }
            }
        }

        return $json;
    }
public function formatTemplateMessage ( $ templateID , $ openID , $ url , array $ data , array $ options = [ ] ) { $ json = [ 'touser' => ( string ) $ openID , 'template_id' => ( string ) $ templateID , 'url' => ( string ) $ url , 'data' => [ ] , ] ; if ( isset ( $ options [ 'color' ] ) ) { $ json [ 'topcolor' ] = '#' . strtoupper ( ltrim ( $ options [ 'color' ] , '#' ) ) ; } foreach ( $ data as $ fieldName => $ fieldValue ) { if ( ! is_array ( $ fieldValue ) ) { $ json [ 'data' ] [ $ fieldName ] = [ 'value' => $ fieldValue ] ; } else { $ json [ 'data' ] [ $ fieldName ] = [ 'value' => $ fieldValue [ 'value' ] , ] ; if ( isset ( $ fieldValue [ 'color' ] ) ) { $ json [ 'data' ] [ $ fieldName ] [ 'color' ] = '#' . strtoupper ( ltrim ( $ fieldValue [ 'color' ] , '#' ) ) ; } } } return $ json ; }
Formats the given data to be used in a template message. Returns an array that can be sent to the API.

@param string $templateID
@param string $openID
@param string $url
@param array  $data
@param array  $options

@return array
Formats the given data to be used in a template message . Returns an array that can be sent to the API .