http://www.gysms.com/freesms.phpを使用してSMSを送信するPhpCurlを含むスクリプトを開発しています 。ページにはCookiePHPSESSIDが格納され、投稿中にtokenという名前の非表示フィールドが渡されます。
2つのcurlリクエストを含むスクリプトを作成しました。最初のcurlリクエストはページを解析し、トークン値を取得します。
そのためのコードは次のとおりです。
<?php
$phone = '9197xxxxxxx';
$msg = 'Hi this is curlpost';
$get_cookie_page = 'http://www.gysms.com/freesms.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $get_cookie_page);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$sabin = curl_exec($ch);
$html=explode('<input type="hidden" name="trigger" value="',$sabin);
$html=explode('"/>',$html[1]);
//store the token value to $html[0]
?>
カール投稿は、次のコードを使用して行われます。
<?php
$fields = array(
'trigger'=>urlencode($html[0]), //token value
'number'=>urlencode($phone), //phone no
'message'=>urlencode($msg) //message
);
//posting curl request
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$url = 'http://www.gysms.com/freesms.php';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
//execute post
$result = curl_exec($ch);
echo $result;
curl_close($ch);
?>
上記のコードを使用してSMSが送信されていません。SMSが送信された場合SMSが送信されたことを示す必要があります-いいえ。どこが間違っていたのかわかりません。助けてください、私はPHPに不慣れです。最後に、この試みは私の教育目的のためだけです。