Как отправить контактную форму 7 отправленных данных на внешний ключ API с проверкой идентификатора токена и секретного ключа - PullRequest
0 голосов
/ 11 марта 2020

Я работаю с контактной формой 7. В своем коде я хочу отправить данные контактной формы 7 на внешние API в виде json данных, но перед отправкой данных я хочу проверить идентификатор токена и секретный ключ внешнего API.

 define('CF7_TO_API_URL', 'https://1234567.extforms.customsite.com/app/site/hosting/scriptlet.nl? 
 script=428&deploy=1&compid=5717895&h=43d0ce96286ab3266036');

 function action_wpcf7_mail_sent( $contact_form ) { 

    $wpcf7      = WPCF7_ContactForm::get_current();
    $submission = WPCF7_Submission::get_instance();
    if ($submission) {
        $data = $submission->get_posted_data();
        $url = $submission->get_meta( 'url' ); // url where the submit come from
        $postId = url_to_postid($url); // from the url we get the post ID
        $postType = get_post_type($postId); // from post ID we get the post type
        $title = get_the_title($postId); // and the title
        $output = [
            "name"    => $data['your-name'],// add all needed fields

            "email"   => $data['your-email'],
            "subject" => $data['your-subject'],
            "country" => $data['Countries'],
            "message" => $data['your-message'],
            "source"  => $url,

        ];
        $options = array(
            'http' => array(
                'method'  => 'POST', 
                'content' => json_encode( $output ), // php array as json
                'header'=>  "Content-Type: application/json\r\n" .
                    "Accept: application/json\r\n"
            )
        );

        $context  = stream_context_create( $options );
        $result = file_get_contents( CF7_TO_API_URL, false, $context );

      $response = json_decode( $result );


    }

}; 


add_action( 'wpcf7_mail_sent', 'action_wpcf7_mail_sent', 10, 1 ); 

По приведенному выше коду я нажимаю внешний ключ API и получаю ответ, но я хочу проверить идентификатор токена и секретный ключ API-ключа перед отправкой данных в качестве ответа.

Любая помощь приветствуется

...