使用php进行Opencart短信集成

I have a page for registration of users where the user need to provide their name phonenumber etc for registration. It accepts the phone number the following way.

 <input type="text" name="telephone" value="<?php echo $telephone; ?>"/>

phonenumber is storend in the db.

When the user checkout and goes to success.php, user should be notified by the sms

This is a API form smsgatewaycenter

<?php
$sendsms ="";
$param['To'] = "123456";
$param['Message'] = "Hello this is test message.";
$param['UserName'] = "my_username";
$param['Password'] = "mypwd";
$param['Mask'] = "TTNERD";
$param['v'] = "1.1";
$param['Type'] = "Individual";
foreach($param as $key=>$val)
{
$sendsms.= $key."=".urlencode($val);
$sendsms.= "&";
}
$sendsms = substr($sendsms, 0, strlen($sendsms)-1);
$url = "http://www.smsgatewaycenter.com/library/send_sms_2.php?".$sendsms;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;

?>

It works fine but

$param['To'] = "123456";

It sends the sms to the number 123456, i want it to send the sms to the number which is registered by the user during the registration process. Should it be like this?

$param['To'] = '$telephone';

Please help. Thanks in Advance.

You need to edit your success controller file.

Just go to catalog/controller/checkout/success.php and find line no 5.

You can see below code:

$this->cart->clear();

You need to put below code after above code:

$this->load->model('account/customer');                 
$customer_info = $this->model_account_customer->getCustomer($this->session->data['user_id']);
    $sendsms ="";
    $param['To'] = $customer_info['telephone'];
    $param['Message'] = "Hello this is test message.";
    $param['UserName'] = "my_username";
    $param['Password'] = "mypwd";
    $param['Mask'] = "TTNERD";
    $param['v'] = "1.1";
    $param['Type'] = "Individual";
    $sendsms = http_build_query($param);
    $url = "http://www.smsgatewaycenter.com/library/send_sms_2.php?".$sendsms;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $curl_scraped_page = curl_exec($ch);
    curl_close($ch);

Now you can send your sms when user is logged in and complete checkout successfully.

It should be

$param['To'] = $telephone;

if You earlier have sth like

$telephone = '123456789'

Getting data from form and configuration on event can be a difficult task. You can use any free sms module to send sms from your opencart store.

Example (a plugin developed by the company I work for): http://www.opencart.com/index.php?route=extension/extension/info&extension_id=27121

This module send sms on below events:

  • Notify store-admin on new order and registration.
    • Send sms on new order place.
    • Send sms on order status change.
    • Send sms on account registration.

Events are configurable from admin area.