doxrxwn2252 2015-06-18 11:55
浏览 41
已采纳

xml_data传递PHP变量

I have integrated SMS Gateway in my Opencart CMS

It uses the following SYNTAX

    $xml_data ='<?xml version="1.0"?><smslist><sms><user>username</user
<password>112131</password><message>Your order # {$order_id} has been successfully received. Thank you for placing an Order at mystore.com</message><mobiles>9898000000</mobiles><senderid>Sherif</senderid><cdmasenderid>00201009546310</cdmasenderid><accountusagetypeid>1</accountusagetypeid></sms></smslist>';  

$URL = "http://mainadmin.dove-sms.com/sendsms.jsp?"; 

            $ch = curl_init($URL);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
            curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $output = curl_exec($ch);
            curl_close($ch);

Please make note that I have not used my personal credentials and this is just a syntax. I have tested the code and it works absolutely fine using my credentials

Now, What I want is it should load the order number, instead it shows the text {$order_id} in my message!

Moreover I want the text to be sent to the user who has logged-in in my stored by fetching the $telephone variable

Please help and thanks in advance

File in which this code is included: catalog/controller/checkout/sucess.php

Opencart version: 1.5.6

Find the Screenshot of the message I have Received here

  • 写回答

1条回答 默认 最新

  • dpzlz08480 2015-06-18 12:35
    关注

    Now, What I want is it should load the order number, instead it shows the text {$order_id} in my message!

    That's because you are using a single quoted string for the variable $xml_data, single quoted strings in PHP display things as is (variables won't be substituted with their values, they will be treated as text), to solve this issue, use a double quoted string instead (according to the PHP manual)

    Moreover I want the text to be sent to the user who has logged-in in my stored by fetching the $telephone variable

    simply $telephone = $this->customer->getTelephone(), now you just need to put the variable $telephone in the correct tag in $xml_data

    Edit

    I have read the post comments and noticed that you get an error that says $order_id is not defined, to solve that, use $this->session->data['order_id'] instead of $order_id and place your SMS code in the beginning of the
    if (isset($this->session->data['order_id'])) code block like that (to use the value of order id before it's erased from session):

    if (isset($this->session->data['order_id'])) {
        $xml_data ="<?xml version="1.0"?><smslist><sms><user>username</user
    <password>112131</password><message>Your order # {$this->session->data['order_id']} has been successfully received. Thank you for placing an Order at mystore.com</message><mobiles>9898000000</mobiles><senderid>Sherif</senderid><cdmasenderid>00201009546310</cdmasenderid><accountusagetypeid>1</accountusagetypeid></sms></smslist>";  
        $URL = "http://mainadmin.dove-sms.com/sendsms.jsp?"; 
        $ch = curl_init($URL);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
    
        // here put the rest of the code
        $this->cart->clear();
        // ...
    }
    

    Finally, delete cotenets of the the folder vqcache

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?