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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)