如何将msg91 php api与Prestasms或Prestashop集成?

时间:2017-11-29 13:21:45

标签: php api sms prestashop sms-gateway



<?php
error_reporting(E_ALL ^ E_NOTICE);ini_set('error_reporting', E_ALL ^ E_NOTICE);
    
define('IS_ADMIN_FLAG', false);

include_once(dirname(__FILE__).'/../../config/config.inc.php');
include_once(dirname(__FILE__).'/../../config/setting.inc.php');

include_once('includes/model/smsAdapter.php');
include_once('includes/model/sms.php');
include_once('includes/model/variables.php');

class ControllerSmsApi
{
    public function __construct()
    {
        $this->index();
    }                  

    public function index()
    {
        die("DISABLED");
                         
        $to = $this->getVar("to");
        $text = $this->getVar("text");
        $unicode = $this->getVar("unicode");
        $type = $this->getVar("type");
        $transaction = $this->getVar("transaction");
        
        if(isset($to) && strlen($to) > 4 && strlen($text) > 0)
        {   
            $sms = new SmsModel(true, SmsModel::TYPE_SIMPLE, $type, ($transaction ? SmsModel::SMS_TRANSACTION : SmsModel::SMS_BULK));
            
            $sms->number($to)->text($text)->unicode($unicode)->send();

            if(!$sms->isError())
            {
                echo "SMSSTATUS:OK";
            }
            else
            {
                echo "SMSSTATUS:ERROR";
            }
        }
        else
        {
            echo "SMSSTATUS:ERROR";
        }
    }
    
    private function getVar($var)
    {
        if(filter_input(INPUT_POST, $var))
        {
            return filter_input(INPUT_POST, $var);
        }
        elseif(filter_input(INPUT_GET, $var))
        {
            return filter_input(INPUT_GET, $var);
        }
        else
        {
            return null;
        }
    }
}

new ControllerSmsApi();
  
?>
&#13;
&#13;
&#13;

我有一个ecommers网站,其中客户下订单并通过电子邮件服务获得所有更新,但现在我想为sms服务也是为了我在msg91 for php中有sms api。但不幸的是,我无法通过prestasms或任何其他免费模块将它与prestashop集成。

1 个答案:

答案 0 :(得分:0)

实际上制作模块应该完成工作并添加 各种钩子可以完成这项工作,你可以在这里生成几乎所有你需要的一个:https://validator.prestashop.com/

根据您的回答,您肯定需要两个钩子:actionOrderStatusUpdate和actionValidateOrder。您还可以在此处获取更新列表http://www.prestarocket.com/blog/prestashop-1-7-hook-list-liste-des-hooks/

如果您需要一个模块正常工作的示例,您可以查看模块/ dashactivity /哪个最符合Prestashops指南。

您的代码最终可能如下所示:

<?php


class Msg91SMS extends Module
{
    public function __construct()
    {
        $this->name = 'msg91sms';
        $this->tab = 'front_office';
        $this->version = '1.0.1';
        $this->author = 'YourName';

        $this->displayName = $this->l('MSG91SMS');
        $this->description = $this->l('Description');

        // Hooks you need, setup on install so you might do it again
        $this->hooks = array(
            'actionValidateOrder',
            'actionOrderStatusUpdate',
        );
    }

    public function install() {
        if (!parent::install()) {
            return false;
        } else {
            if (isset($this->hooks) && !empty($this->hooks)) {
                foreach ($this->hooks as $v) {
                    if (!$this->registerHook($v)) {
                        return false;
                    }
                }
            }
        }

    }

    public function hookActionValidateOrder($params) {
       $order = $params['order'];
       // Do your magic here
    }

    public function hookActionOrderStatusUpdate($params) {
        // Same as above, remember to check order state to see if it interests you some ways with $order->id_state and a switch / case
    }

}