91成人在线播放_欧美一区二区视频在线观看_91精品国产高清久久久久久_国产精品久久亚洲不卡4k岛国


待發(fā)短信

在線(xiàn)客服
產(chǎn)品支持 短信寶客服
合作渠道 渠道合作
服務(wù)咨詢(xún)

4001-021-502

工作時(shí)間

9:00-21:00

OpenCartV3.8新增短信寶短信接口

OpenCart是一款開(kāi)源的 PHP 開(kāi)源電子商務(wù)建站系統(tǒng)。OpenCart獨(dú)立站建站系統(tǒng)安裝方便、功能強(qiáng)大、操作簡(jiǎn)單。支持多語(yǔ)言、多貨幣、多店鋪等功能。今天小編就以新增短信接口為例,給大家講解一下如何進(jìn)行二次開(kāi)發(fā),使用的短信接口是我們短信寶短信群發(fā)平臺(tái)的短信接口,我們短信寶短信群發(fā)平臺(tái)的接口非常穩(wěn)定,發(fā)送速度快,注冊(cè)就送測(cè)試短信,推薦大家使用。
1:打開(kāi)項(xiàng)目:\admin\view\template\setting\setting.twig 增加短信寶設(shè)置頁(yè)面大概在40行和1235行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<ul class="nav nav-tabs">
  <li class="active"><a href="#tab-general" data-toggle="tab">{{ tab_general }}</a></li>
  <li><a href="#tab-store" data-toggle="tab">{{ tab_store }}</a></li>
  <li><a href="#tab-local" data-toggle="tab">{{ tab_local }}</a></li>
  <li><a href="#tab-option" data-toggle="tab">{{ tab_option }}</a></li>
  <li><a href="#tab-image" data-toggle="tab">{{ tab_image }}</a></li>
  <li><a href="#tab-mail" data-toggle="tab">{{ tab_mail }}</a></li>
  <li><a href="#tab-server" data-toggle="tab">{{ tab_server }}</a></li>
  <li><a href="#tab-sms" data-toggle="tab">短信寶配置</a></li>
</ul>
 
<div class="tab-pane" id="tab-sms">
  <div class="form-group required">
    <label class="col-sm-2 control-label" for="input-name">短信寶用戶(hù)名</label>
    <div class="col-sm-10">
      <input type="text" name="config_smsbaouser" value="{{ config_smsbaouser }}" placeholder="短信寶用戶(hù)名" id="input-name" class="form-control"/>
    </div>
  </div>
  <div class="form-group required">
    <label class="col-sm-2 control-label" for="input-owner">短信寶密碼</label>
    <div class="col-sm-10">
      <input type="text" name="config_smsbaopass" value="{{ config_smsbaopass }}" placeholder="短信寶密碼" id="input-owner" class="form-control"/>
    </div>
  </div>
  <div class="form-group required">
    <label class="col-sm-2 control-label" for="input-owner">短信寶簽名</label>
    <div class="col-sm-10">
      <input type="text" name="config_smsbaosign" value="{{ config_smsbaosign }}" placeholder="短信寶簽名" id="input-owner" class="form-control"/>
     </div>
  </div>
</div>

2:打開(kāi)項(xiàng)目:admin\controller\setting\setting.php 修改代碼大概224行左右

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
if (isset($this->request->post['config_smsbaouser'])) {
    $data['config_smsbaouser'] = $this->request->post['config_smsbaouser'];
else {
    $data['config_smsbaouser'] = $this->config->get('config_smsbaouser');
}
if (isset($this->request->post['config_smsbaopass'])) {
    $data['config_smsbaopass'] = $this->request->post['config_smsbaopass'];
else {
    $data['config_smsbaopass'] = $this->config->get('config_smsbaopass');
}
if (isset($this->request->post['config_smsbaosign'])) {
    $data['config_smsbaosign'] = $this->request->post['config_smsbaosign'];
else {
    $data['config_smsbaosign'] = $this->config->get('config_smsbaosign');
}
if (isset($this->request->post['config_name'])) {
    $data['config_name'] = $this->request->post['config_name'];
else {
    $data['config_name'] = $this->config->get('config_name');
}

3:打開(kāi)項(xiàng)目:catalog\view\theme\default\template\account\register.twig 修改代碼大概97行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<div class="form-group required ">
  <label class="col-sm-2 control-label" for="input-mobiles">短信驗(yàn)證碼</label>
  <div class="col-sm-10">
    <input type="text" name="mobiles" value="" placeholder="短信驗(yàn)證碼" id="input-mobiles" class="form-control" />
    <b class="huoqu" style="height: 28px; width: 120px;cursor: pointer;">獲取驗(yàn)證碼</b>
    {% if error_mobiles %}
      <div class="text-danger">{{ error_mobiles }}</div>
    {% endif %} </div>
</div>
<script>
  var time = 0; // 倒計(jì)時(shí)時(shí)間
  var res = null// 倒計(jì)時(shí)資源,釋放時(shí)使用
  /**
   * 執(zhí)行倒計(jì)時(shí)的方法
   */
  function sendTime() {
    clearTimeout(res); // 先清空一下倒計(jì)時(shí)資源。
    time--; // 倒計(jì)時(shí)時(shí)間遞減。
    // 如果倒計(jì)時(shí)到達(dá)0時(shí),則恢復(fù)按鈕原來(lái)的內(nèi)容
    if (time <= 0) {
      time = "獲取驗(yàn)證碼";
      $('.huoqu').text(time);
      clearTimeout(res);
      time = 0;
      return;
    }
    // 倒計(jì)時(shí)的內(nèi)容寫(xiě)到按鈕里面
    $('.huoqu').text("剩余" + time + "秒");
    res = setTimeout("sendTime()", 1000);
  }
  /**
   * 調(diào)用處
   */
  $(function() {
    var flg = true// 防止ajax重復(fù)提交的標(biāo)記
    /**
     * 點(diǎn)擊發(fā)送短信,觸發(fā)事件
     */
    $('.huoqu').on("click"function() {
      var mobile = $("#input-telephone").val();
      var reg = /^1[3,4,5,7,8]\d{9}$/;
      if (!reg.test(mobile)) {alert('手機(jī)號(hào)碼不正確');return ret;}
      // 如果當(dāng)前倒計(jì)時(shí)結(jié)束,則收集表單數(shù)據(jù),并ajax提交到服務(wù)端
      if (0 == time) {
        var data = {"mobile" : mobile};
        var err = "";
        if (flg == true) {
          flg = false;
          // ajax提交請(qǐng)求
          $.ajax({
            "url" "index.php?route=account/register/sendsms",
            "type" "post",
            "data" : data,
            "dataType" "json",
            "success" function (msg) {
              if(msg == '0'){
                time = 60;
                sendTime();
                alert('短信發(fā)送成功!');
                ret = true;
              }else if(msg == '2'){
                alert('短信配置不正確');
              }else{
                alert(msg);
              }
            }
          });
        }
        return false;
      }
    });
  });
</script>

4:打開(kāi)項(xiàng)目:catalog\view\theme\default\template\account\forgotten.twig 修改密碼增加短信頁(yè)面 大概32行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<fieldset class="{{ register_type != 'mobile' ? 'hidden' }} mobile">
  <legend class="mobile">您的手機(jī)號(hào)</legend>
  <div class="form-group required mobile">
    <label class="col-sm-2 control-label" for="input-telephone">手機(jī)號(hào)碼</label>
    <div class="col-sm-10">
      <input type="tel" name="telephone" value="" placeholder="手機(jī)號(hào)碼" id="input-telephone" class="form-control" />
      {% if error_telephone %}
        <div class="text-danger">{{ error_telephone }}</div>
      {% endif %} </div>
  </div>
  <div class="form-group required mobile">
    <label class="col-sm-2 control-label" for="input-mobiles">短信驗(yàn)證碼</label>
    <div class="col-sm-10">
      <input type="text" name="mobiles" value="" placeholder="短信驗(yàn)證碼" id="input-mobiles" class="form-control" />
      <b class="huoqu" style="height: 28px; width: 120px;cursor: pointer;">獲取驗(yàn)證碼</b>
      {% if error_mobiles %}
        <div class="text-danger">{{ error_mobiles }}</div>
      {% endif %} </div>
  </div>
</fieldset>
<script>
  var time = 0; // 倒計(jì)時(shí)時(shí)間
  var res = null// 倒計(jì)時(shí)資源,釋放時(shí)使用
 
  /**
   * 執(zhí)行倒計(jì)時(shí)的方法
   */
  function sendTime() {
    clearTimeout(res); // 先清空一下倒計(jì)時(shí)資源。
    time--; // 倒計(jì)時(shí)時(shí)間遞減。
    // 如果倒計(jì)時(shí)到達(dá)0時(shí),則恢復(fù)按鈕原來(lái)的內(nèi)容
    if (time <= 0) {
      time = "獲取驗(yàn)證碼";
      $('.huoqu').text(time);
      clearTimeout(res);
      time = 0;
      return;
    }
    // 倒計(jì)時(shí)的內(nèi)容寫(xiě)到按鈕里面
    $('.huoqu').text("剩余" + time + "秒");
    res = setTimeout("sendTime()", 1000);
  }
  /**
   * 調(diào)用處
   */
  $(function() {
    var flg = true// 防止ajax重復(fù)提交的標(biāo)記
    /**
     * 點(diǎn)擊發(fā)送短信,觸發(fā)事件
     */
    $('.huoqu').on("click"function() {
      var mobile = $("#input-telephone").val();
      var reg = /^1[3,4,5,7,8]\d{9}$/;
      if (!reg.test(mobile)) {alert('手機(jī)號(hào)碼不正確');return ret;}
      // 如果當(dāng)前倒計(jì)時(shí)結(jié)束,則收集表單數(shù)據(jù),并ajax提交到服務(wù)端
      if (0 == time) {
        var data = {"mobile" : mobile};
        var err = "";
        if (flg == true) {
          flg = false;
          // ajax提交請(qǐng)求
          $.ajax({
            "url" "index.php?route=account/register/sendsms",
            "type" "post",
            "data" : data,
            "dataType" "json",
            "success" function (msg) {
              if(msg == '0'){
                time = 60;
                sendTime();
                alert('短信發(fā)送成功!');
                ret = true;
              }else if(msg == '2'){
                alert('短信配置不正確');
              }else{
                alert(msg);
              }
            }
          });
        }
        return false;
      }
    });
  });
</script>

5:打開(kāi)項(xiàng)目:catalog\controller\account\register.php 增加短信發(fā)送函數(shù)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public function sendsms()
{
    $mobile = $_POST['mobile'];
    $this->load->model('setting/setting');
    $user = $this->config->get('config_smsbaouser');
    $pass = $this->config->get('config_smsbaopass');
    $sign = $this->config->get('config_smsbaosign');
    if (empty($user) && empty($pass) && empty($sign)) {
        echo json_encode(2);exit;
    }
    $code = rand(1000,9999);
    $content = '【'.$sign.'】您的驗(yàn)證碼為:'.$code.'請(qǐng)妥善保存!';
    $result = file_get_contents($url);
    if ($result == 0) {
        $this->session->data['mobile_code'] = $code;
        echo json_encode(0);exit;
    }else{
        echo json_encode($result);exit;
    }
 
}

6:當(dāng)前項(xiàng)目235行左右增加校驗(yàn)短信代碼

1
2
3
4
5
6
if ($this->request->post['mobiles'] != $this->session->data['mobile_code'] && $this->request->post['type'] == 'mobile') {
      $this->error['mobiles'] = '短信驗(yàn)證碼錯(cuò)誤';
}
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
   $this->error['firstname'] = $this->language->get('error_firstname');
}

7:打開(kāi)項(xiàng)目:catalog\controller\account\forgotten.php 修改代碼大概19行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
    if ($this->request->post['type'] == 'mobile') {
        $this->checksms($this->request->post['telephone']);
        $customer_info = $this->model_account_customer->getCustomerByMobile($this->request->post['telephone']);
        $this->model_account_customer->editPassword($customer_info['customer_id'], $this->session->data['checkpassword']);
        $this->session->data['success'] = '重設(shè)密碼鏈接已發(fā)送到您的手機(jī)!';
    else {
        $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
        $this->model_account_customer->editCode($customer_info['customer_id'], token(40));
        $this->session->data['success'] = $this->language->get('text_success');
    }
    $this->response->redirect($this->url->link('account/login'));
}
protected function checksms($mobile)
{
    $this->load->model('setting/setting');
    $user = $this->config->get('config_smsbaouser');
    $pass = $this->config->get('config_smsbaopass');
    $sign = $this->config->get('config_smsbaosign');
    if (empty($user) && empty($pass) && empty($sign)) {
        return 2;
        exit;
    }
    $code = rand(1000, 9999);
    $content = '【' . $sign . '】您的新密碼為:' . $code . '請(qǐng)妥善保存!';
    $result = file_get_contents($url);
    if ($result == 0) {
        $this->session->data['checkpassword'] = $code;
        return 0;
        exit;
    else {
        return $result;
        exit;
    }
}

8:當(dāng)前項(xiàng)目93行左右增加校驗(yàn)短信代碼

1
2
3
4
5
6
7
8
if ($this->request->post['type'] == 'mobile') {
    if ($this->request->post['mobiles'] != $this->session->data['mobile_code']) {
        $this->error['mobiles'] = '短信驗(yàn)證碼錯(cuò)誤';
    }
    if ($this->request->post['telephone'] && !$this->model_account_customer->getTotalCustomersByTelephone($this->request->post['telephone'])) {
        $this->error['warning'] = $this->language->get('error_exists_telephone');
    }
}

經(jīng)過(guò)上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行測(cè)試發(fā)送:

報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。

另外:我們已經(jīng)開(kāi)發(fā)好完整的OpenCartV3.8系統(tǒng)短信寶插件,點(diǎn)擊此鏈接 下載及查看安裝流程。

開(kāi)源插件

最新更新

電商類(lèi)

CMS類(lèi)

微信類(lèi)

文章標(biāo)簽