我正在使用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集成。
如果您正在尋找OTP功能與正常短信通知 結帳這個擴展 https://magecomp.com/magento-sms-notification.html https://magecomp.com/magento-2-sms-notification.html –