【问题标题】:How to integrate msg91 php api with Prestasms or Prestashop?如何将 msg91 php api 与 Prestasms 或 Prestashop 集成?
【发布时间】:2017-11-29 13:21:45
【问题描述】:

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

我有一个电子商务网站,客户在该网站下订单并通过电子邮件服务获取所有更新,但现在我想将其用于短信服务,为此我在 msg91 中为 php 提供了短信 API。但不幸的是,我无法通过 prestasms 或任何其他免费模块将它与 prestashop 集成。

【问题讨论】:

  • 在寻求帮助之前向我们展示一些工作:)
  • 这是一个与您的短信提供商兼容的模块:addons.prestashop.com/fr/emails-notifications/…
  • 我说的是免费模块
  • 那我说,让我们看看你到目前为止做了什么。
  • 它在本地主机上,我怎么给你看? Prestasms 文件?或任何特定代码?实际上我想在订单状态发生变化时发送短信,我不了解 prestashop 核心文件来执行此操作。并且没有任何东西可以在互联网上提供这些信息。

标签: php api sms prestashop sms-gateway


【解决方案1】:

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

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

如果您需要一个运行良好的模块示例,您可以查看 modules/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
    }

}

【讨论】:

  • 是的,我只是想制作一个模块。您的代码为我提供了最好的指导,谢谢哥们?
  • 我如何获取发送消息的用户的数据?
  • 在钩子中你可以这样做:$customer = new Customer($order->id_customer);
  • 那么如何获取手机号的客户呢?
  • 其实我要发货手机号
猜你喜欢
  • 2014-08-24
  • 2011-01-12
  • 2011-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-27
  • 2015-01-16
相关资源
最近更新 更多