2015-04-19 142 views
0

我正在使用Magento 1.8.1,並且我想將SMS與我們的商店集成。SMS與Magento API的集成

我有一個SMS的API網址,但不知道如何以及在Magento中將該URL放在哪裏。

他們給我提供這個代碼:

<?php 
 
class sendsms 
 
{ 
 
    \t private $api_url; 
 
    \t private $time; 
 
    \t private $unicode; 
 
\t private $working_key; 
 
\t private $start; 
 
\t private $sender_id; 
 
\t public $api; 
 
\t public $wk; 
 
\t public $sid; 
 
\t public $to; 
 

 
\t /**function to set the working key 
 
\t * 
 
\t * @param string_type $wk:helps to change the working_key 
 
\t */ 
 
\t function setWorkingKey($wk) 
 
\t { 
 
\t \t $this->working_key=$wk; 
 
\t } 
 
\t 
 
\t /**function to set sender id 
 
\t * 
 
\t * @param string_type $sid:helps to change sender_id 
 
\t */ 
 
\t function setSenderId($sid) 
 
\t { 
 
\t \t $this->sender_id=$sid; 
 
\t } 
 

 
\t /**function to set API url 
 
\t * 
 
\t * @param string_type $apiurl:it is used to set api url 
 
\t */ 
 
\t function setapiurl($apiurl) 
 
\t { \t \t $this->api=$apiurl; 
 
\t \t \t $a=strtolower(substr($apiurl,0,7)); 
 
\t \t \t 
 
\t \t \t if ($a=="http://") //checking if already contains http:// 
 
\t \t \t { 
 
\t \t \t \t $api_url=substr($apiurl,7,strlen($apiurl)); 
 
\t \t \t \t $this->api_url=$api_url; 
 
\t \t \t \t $this->start="http://"; 
 
\t \t \t } 
 
\t \t  elseif ($a=="https:/") //checking if already contains htps:// 
 
\t \t \t { 
 
\t \t \t \t $api_url=substr($apiurl,8,strlen($apiurl)); 
 
\t \t \t \t $this->api_url=$api_url; 
 
\t \t \t \t $this->start="https://"; 
 
\t \t \t } 
 
\t \t \t else { 
 
\t \t \t \t \t \t $this->api_url=$apiurl; 
 
\t \t \t   \t \t $this->start="http://"; 
 
\t \t \t \t } 
 
\t } 
 

 
\t /** function to intialize constructor 
 
\t * 
 
\t * @param string_type $wk: it is working_key 
 
\t * @param string_type $sd: it is sender_id 
 
\t * @param string_type $apiurl: it is api_url 
 
\t *   used for intializing the parameter 
 
\t */ 
 
\t function __construct($apiurl,$wk,$sd) 
 
\t { 
 
\t \t $this->setWorkingKey($wk); 
 
\t \t $this->setSenderId($sd); 
 
\t \t $this->setapiurl($apiurl); 
 
\t } 
 

 
\t /** 
 
\t * function to send sms 
 
\t * 
 
\t */ 
 
\t function send_sms($to,$message,$dlr_url,$type="xml") 
 
\t { 
 
\t \t $this->process_sms($to,$message,$dlr_url,$type="xml",$time="null",$unicode="null"); 
 
\t } 
 

 
\t /** 
 
\t * function to schedule sms 
 
\t * 
 
\t */ 
 
\t function schedule_sms($to,$message,$dlr_url,$type="xml",$time) 
 
\t { 
 
\t \t $this->process_sms($to,$message,$dlr_url,$type="xml",$time,$unicode=''); 
 
\t } 
 

 
\t /** 
 
\t * function to send unicode message 
 
\t */ 
 
\t function unicode_sms($to,$message,$dlr_url,$type="xml",$unicode) 
 
\t { 
 
\t \t $this->process_sms($to,$message,$dlr_url,$type="xml",$time='',$unicode); 
 
\t } 
 

 
\t /** 
 
\t * function to send out sms 
 
\t * @param string_type $to : is mobile number where message needs to be send 
 
\t * @param string_type $message :it is message content 
 
\t * @param string_type $dlr_url: it is used for delivering report to client 
 
\t * @param string_type $type: type in which report is delivered 
 
\t * @return output \t \t $this->api=$apiurl; 
 
\t */ 
 
\t function process_sms($to,$message,$dlr_url="",$type="xml",$time='',$unicode='') 
 
\t { 
 
\t \t $message=urlencode($message); 
 
\t \t $this->to=$to; 
 
\t \t $to=substr($to,-10) ; 
 
\t \t $arrayto=array("9", "8" ,"7"); 
 
\t \t $to_check=substr($to,0,1); 
 
\t 
 
\t if(in_array($to_check, $arrayto)) 
 
\t \t $this->to=$to; 
 
\t else echo "invalid number"; 
 

 
\t if($time=='null') 
 
\t \t $time=''; 
 
\t else 
 
\t \t $time="&time=$time"; 
 
\t if($unicode=='null') 
 
\t \t $unicode=''; 
 
\t else 
 
\t \t $unicode="&unicode=$unicode"; 
 
\t 
 
\t \t 
 
\t \t $url="$this->start$this->api_url/web2sms.php?workingkey=$this->working_key&sender=$this->sender_id&to=$to&message=$message&type=$type&dlr_url=$dlr_url$time$unicode"; 
 
\t \t $this->execute($url); 
 
\t } 
 

 
\t /** 
 
\t * function to check message delivery status 
 
\t * string_type $mid : it is message id 
 
\t */ 
 
\t function messagedelivery_status($mid) 
 
\t { 
 
\t \t $url="$this->start$this->api_url/status.php?workingkey=$this->working_key&messageid=$mid"; 
 
\t \t \t $this->execute($url); 
 
\t } 
 

 
\t /** 
 
\t * function to check group message delivery 
 
\t * string_type $gid: it is group id 
 
\t */ 
 
\t function groupdelivery_status($gid) 
 
\t { 
 
\t \t $url="$this->start$this->api_url/groupstatus.php?workingkey=$this->working_key&messagegid=$gid"; 
 
\t \t $this->execute($url); 
 
\t \t 
 
\t } 
 

 
\t /** 
 
\t * function to request to clent url 
 
\t */ 
 
\t function execute($url) 
 
\t { 
 
\t \t $ch=curl_init(); 
 
\t \t // curl_setopt($ch, CURLOPT_POST, true); 
 
\t \t curl_setopt($ch, CURLOPT_URL, $url); 
 
\t \t curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
 
\t \t curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
 
\t \t $output=curl_exec($ch); 
 
\t \t curl_close($ch); 
 
\t \t echo $output; 
 
\t \t return $output; 
 
\t \t 
 
\t }  
 
}

我是新來的Magento,所以請幫助我的API集成。

+0

如果您正在尋找OTP功能與正常短信通知 結帳這個擴展 https://magecomp.com/magento-sms-notification.html https://magecomp.com/magento-2-sms-notification.html –

回答

0

對於SMS集成,您需要決定要處理的事件。

Magento事件列表可用here

之後你需要爲選擇事件創建觀察者。

觀察者是一個事件處理程序。它會監聽它所附加的任何事件並相應地對事件作出反應。

你的SMS API應該在觀察者中使用。 (這是PHP類中的方法。)

要在Magento中創建觀察者,您需要閱讀this documentation

+0

它需要任何自定義模塊? – sam

+0

您需要添加自定義模塊。用於處理事件。例如,如果您想在創建訂單時發送短信,則需要觀察員進行sales_order_save_after事件。 –

4

有免費的模塊,如 「春天的邊緣Magento的短信擴展」 是兼容: Magento的版本1.x和2.x

Magento的短信模塊事件配置:

  • 當訂單被放置。
  • 訂單狀態設置爲保持。
  • 訂單狀態設置爲Unhold時。
  • 訂單被取消時。
  • 當訂單狀態設置出貨

http://springedge.com/magento-sms-extension-module-free.html