2016-02-08 63 views
-2

我正在使用WordPress,並且我想將SMS API集成到我的WordPress站點中。任何人都可以幫助知道在哪裏(在哪個文件中)編寫集成代碼以及集成SMS API的代碼。如何在Wordpress中集成第三方API

我收到的短信API鏈接: http://www.elitbuzzsms.com/app/smsapi/index.php?key=KEY&campaign=****&routeid=**&type=text&contacts=<NUMBER>&senderid=SMSMSG&msg=< Message Content >

我想上面的API集成在我的wordpress主題,這樣我可以給基於手機號碼的短信,並添加所需的信息。

+0

你有什麼迄今所做? –

+0

我不知道如何在wordpress中使用API​​。我是新手。如果你能幫忙,我會很感謝 –

回答

2

在WordPress可以使用wp_remote_getwp_remote_post

GET請求,例如

$url = 'http://www.elitbuzzsms.com/app/smsapi/index.php?key=KEY&campaign=****&routeid=**&type=text&contacts=<NUMBER>&senderid=SMSMSG&msg=< Message Content >'; 

$response = wp_remote_get($url ); 
if(is_array($response)) { 
    $header = $response['headers']; // array of http header lines 
    $body = $response['body']; // use the content 
} 

POST請求例如

$response = wp_remote_post($url, array(
    'method' => 'POST', 
    'timeout' => 45, 
    'redirection' => 5, 
    'httpversion' => '1.0', 
    'blocking' => true, 
    'headers' => array(), 
    'body' => array('username' => 'bob', 'password' => '1234xyz'), 
    'cookies' => array() 
    ) 
); 

if (is_wp_error($response)) { 
    $error_message = $response->get_error_message(); 
    echo "Something went wrong: $error_message"; 
} else { 
    echo 'Response:<pre>'; 
    print_r($response); 
    echo '</pre>'; 
} 
+0

感謝您的幫助,我可以知道在哪個文件中我應該在wordpress中編寫上述代碼,如果它在functions.php中,我們是否需要使用任何鉤子或過濾器? –

+0

你可以在functions.php或任何文件中使用它,它不需要被掛鉤。 –