如何将 msg91 php api 与 Prestasms 或 Prestashop 集成? [英] How to integrate msg91 php api with Prestasms or Prestashop?

查看:25
本文介绍了如何将 msg91 php api 与 Prestasms 或 Prestashop 集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?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();
  
?>

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

I have an ecommers website in which customer placed order and get all updation via email service ,but now i want to make it for sms service also for which i have sms api in msg91 for php. But unfortunately i am unable to integrate it with prestashop via prestasms or any other free module.

推荐答案

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

Actually making a Module should do the job and adding various hooks might do the job, you can generate one with nearly all you will need here : https://validator.prestashop.com/

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

Based on your answer you will certainly need two hooks : actionOrderStatusUpdate and actionValidateOrder. You can also get an updated list here http://www.prestarocket.com/blog/prestashop-1-7-hook-list-liste-des-hooks/.

如果您需要一个运行良好的模块示例,您可以查看 modules/dashactivity/哪个最符合 Prestashops 指南.

If you need example of a module well working, you can take a look at modules/dashactivity/ which one of the most compliant to Prestashops guidelines.

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

Your code might look like this in the end :

<?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
    }

}

这篇关于如何将 msg91 php api 与 Prestasms 或 Prestashop 集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆