2011-09-09 13 views
7

के माध्यम से एसएमएस भेजना कृपया वेबसाइट के माध्यम से एसएमएस भेजने के लिए मुझे नमूना कोड के साथ मार्गदर्शन करें। एसएमएस गेटवे कैसे शामिल करें। कृपया मुझे बताएं, क्या मैं way2sms.com गेटवे के रूप में उपयोग कर सकता हूं?मुफ्त गेटवे

क्या यह उपयोग करने का सही तरीका है? कृपया मुझे केवल इतना कोड काम करने का सुझाव दें?

<?php 
error_reporting(E_ALL); 
ob_implicit_flush(true); 


include_once "class.curl.php"; 
include_once "class.sms.php"; 

$smsapp=new sms(); 
$smsapp->setGateway('way2sms'); 


echo "Logging in ... "; 
$smsapp->login('10 digit number','way2sms password'); 

echo "Sending SMS ... "; 
$result=$smsapp->send('receipient number','text message'); 

if($result=='true') 
{ 
    echo "Message sent"; 
} 
else 
{ 
    echo "Error encountered : ".$smsapp->getLastError(); 
} 

?> 
यहाँ

मेरी class.curl.php

<?php 
class sms 
{ 
    var $username; 
    var $password; 
    var $curl; 
    var $server; 
    var $loginDone; 
    var $debugMode; 
    var $data; 
    var $error; 
    public function __construct() 
    { 
     $this->curl=new cURL(); 
    // $this->curl->setProxy(""); 
     $this->loginDone=false; 
     $this->debugMode=false; 
     $this->data=array(); 
    } 
    public function setGateway($serverName) 
    { 
     switch($serverName) 
     { 
      case '160by2': 
      $this->server='160by2'; 
      break; 

      case 'way2sms': 
      $this->server='way2sms'; 
      break; 

      case 'airtel': 
      $this->server='airtel'; 
      break; 

      default : 
      $this->server='way2sms'; 

     } 
    } 
    public function login($username,$password) 
    { 
     $server=$this->server; 

     call_user_func(array($this,"login_$server"),$username,$password); 
     $this->loginDone=true; 

    } 
    public function send($number,$msg) 
    { 
     $server=$this->server; 
     if($this->loginDone) 
     return call_user_func(array($this,"send_$server"),$number,$msg); 
     else 
     { 
      echo "<h2>Please login first before sending SMS</h2>"; 
     } 

    } 
    private function login_way2sms($username,$password) 
    { 
     $out=($this->curl->post("http://www.way2sms.com","1=1")); 
     $pattern="/Location:(.+?)\n/"; 
     preg_match($pattern,$out,$matches); 
     $domain=trim($matches[1]); 

     $this->data['domain']=$domain; 

     $out= $this->curl->post("{$domain}auth.cl","username=$username&password=$password&Submit=Sign+in"); 

     $pattern="/Location:(.+?)\n/"; 
     preg_match($pattern,$out,$matches); 
     $referer=trim($matches[1]); 
     $this->data['referer']=$referer; 


    } 


    private function send_way2sms($number,$msg) 
    { 
     $domain=$this->data['domain']; 
     $html=$this->curl->post("{$domain}jsp/InstantSMS.jsp?val=0","1=1",$this->data['referer']); 
     if($this->debugMode) 
     { 
     echo "<h2>After logging in, the HTML returned by server is</h2>"; 
     echo $html; 
     } 

     $pattern = '/name="Action".+?value="(.*)"/'; 
     preg_match($pattern, $html, $matches); 

     $custfrom=$matches[1]; 
     $msg=urlencode($msg); 
     $html=$this->curl->post("{$domain}FirstServletsms?custid=","custid=undefined&HiddenAction=instantsms&Action={$custfrom}&login=&pass=&MobNo=$number&textArea=$msg"); 
     $pattern = '/class="style1">(.+?)<\/span>/'; 
     preg_match($pattern, $html, $matches); 
     $out=($matches[1]); 

     if(!preg_match("/successfully/",$out)) 
     { 
     $this->setError($out); 
     return false; 
     } 
     else 
     { 
     return true; 
     $this->setError("No errors"); 
     } 

    } 
    public function getLastError() 
    { 
     return $this->error; 

    } 
    private function setError($error) 
    { 
     $this->error=$error; 
    } 
    private function login_160by2($username,$password) 
    { 
    // $out2=$this->curl->get("http://m.160by2.com"); 
     $out=$this->curl->post("http://m.160by2.com/LoginCheck.asp?l=1&txt_msg=&mno=","txtUserName=$username&txtPasswd=$password&RememberMe=Yes&cmdSubmit=Login"); 
     $pattern="/MyMenu.asp\?Msg=(.+?)&/"; 

     preg_match($pattern,$out,$matches); 
     $id=trim($matches[1]); 
     $this->data['id']=$id; 

    } 

    private function send_160by2($number,$msg) 
    { 
     $msg=urlencode($msg); 
     $id=$this->data['id']; 
     $out1=$this->curl->post("http://m.160by2.com/SaveCompose.asp?l=1","txt_mobileno=$number&txt_msg=$msg&cmdSend=Send+SMS&TID=&T_MsgId=&Msg=$id"); 
     //echo $out1; 
     $pattern = '/\<table.+?\>(.+)\<\/table/s'; 
     preg_match($pattern, $out1, $matches); 

     $out=strip_tags(@$matches[1]); 
     if(count($matches)<1) 
     { 
     $pattern="/\<div.+?background:.+?yellow.+?\>(.+?)\<\/div\>/s"; 

     preg_match($pattern,$out1,$matches); 

     $out=strip_tags($matches[1]); 
     } 

// 
    // echo "out is $out"; 

     if(!preg_match("/successfully/i",$out)) 
     { 

     $this->setError($out); 

     return false; 
     } 
     else 
     { 
     return true; 
     $this->setError("No errors"); 
     } 

    } 

    private function login_airtel($username,$password) 
    { 
     $this->data['username']=$username; 
     $this->data['password']=$password; 

    } 


    private function send_airtel($number,$msg) 
    { 

    } 
} 

?> 
उपयोगकर्ता नाम और पासवर्ड है, जो उपयोगकर्ता नाम और पासवर्ड का उपयोग करना चाहिए मैं के स्थान पर

है?

+2

आपको शायद उनसे पूछना होगा, हमें –

उत्तर

16

हाँ छोड़कर, या के रूप में वायरलेस सेवा प्रदाताओं को अपने द्वारा प्रदान की आप गेटवे का उपयोग कर सकता है, तो के रूप में यह PHP's mail function के साथ उन्हें एक ईमेल भेजने के रूप में सरल है।

जहां (संख्या) है, तो आपको अपना 10 अंकों का फ़ोन नंबर शामिल करना होगा। तो इसका मतलब है कि आपको अपना क्षेत्र कोड शामिल करना होगा।

& एटी टी (संख्या) @ txt.att.net

टी मोबाइल (संख्या) @ tmomail.net

स्प्रिंट (संख्या) @ messaging.sprintpcs.com

Verizon (संख्या) @ vtext.com या (संख्या) @ vzwpix.com

+0

आपको बहुत बहुत धन्यवाद। मैं बस कोशिश करूँगा – priya

+0

ऊपर मत भूलना। :) –

+0

कृपया मुझे सुझाव दें, क्या मुझे एसएमएस गेटवे बनाने या विवरण प्राप्त करने के लिए way2sms.com समर्थन से संपर्क करने की आवश्यकता है? माफ़ कीजिये। मुझे इसके बारे में कुछ नहीं पता। तो मैं खरोंच से पूछ रहा हूँ। – priya

1

यह ठीक लग रहा है, एक पंक्ति परिवर्तन इस

if($result=='true') 
to 
if($result == true) 
+0

@ जापानप्रो, धन्यवाद। कृपया मेरी वेबसाइट पर इसका उपयोग कैसे करें कृपया मुझे मार्गदर्शन करें? और एसएमएस गेटवे कैसे सेट करें? अगर मैं इस कोड का उपयोग करता हूं तो यह वेबसाइट के माध्यम से एसएमएस भेजने के लिए पर्याप्त है? – priya

+0

मैंने कोड संपादित किया है कृपया मुझे सुझाव दें – priya

+0

क्या कोई मेरी मदद कर सकता है? – priya

4

कोड का उपयोग कर रहे पूरी तरह से पुरानी हो चुकी है। Way2sms प्रमाणीकरण के अपने तरीके को बदलते हैं। यदि आप नए कोड का उपयोग करना चाहते हैं तो यहां समाधान है: http://ritesh-chandora.blogspot.in/2012/02/php-code-for-sending-free-sms.html यह ब्लॉग आसानी से एसएमएस भेजने का नया तरीका प्रदान करेगा।

संबंधित मुद्दे