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


待發短信

在線客服
產品支持 短信寶客服
合作渠道 渠道合作
服務咨詢

4001-021-502

工作時間

9:00-21:00

齊博CMS之X1 新增短信寶短信接口

齊博X1是齊博軟件基于thinkphp5開發的內容管理系統,拓展性非常強,后臺一鍵升級,后臺提供豐富的頻道模塊云市插件市場、風格市場、鉤子市場,所有都是一鍵在線安裝。小編對他還是比較了解的,今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺的接口非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。

首先在項目:\plugins\smsbao中創建admin_menu.php文件,代碼如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
return array(
  'plugin'=>array(
    'title'=>'plugin',
      'sons'=>array(
        array(
          'title'=>'短信寶短信接口',
      'sons'=>array(
        array(
          'title'=>'參數選項管理',
          'link'=>'setting/index',
          'power'=>[],
        ),
      ),
    ),
  ),
  ),
);

接著創建:\plugins\smsbao\Api.php 文件,代碼如下

?
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
<?php
namespace plugins\smsbao;
 
class Api{
    private $accessKeyId;
    private $accessKeySecret;
    function __construct($accessKeyId$accessKeySecret) {
        $this->accessKeyId = $accessKeyId;
        $this->accessKeySecret = $accessKeySecret;
    }
    /**
     * 發送短信
     * @param string $signName 必填, 短信簽名
     * @param string $templateCode 必填, 短信模板Code
     * @param string $phoneNumbers 必填, 短信接收號碼
     */
    public function sendSms($signName$templateCode$phoneNumbers$templateParam = null) {
 
 
        $key array_keys($templateParam);
        $value array_values($templateParam);
        $content =  str_replace($key,$value,$templateCode);
        $url "http://api.smsbao.com/sms?u=".$this->accessKeyId.'&p='.md5($this->accessKeySecret).'&m='.$phoneNumbers.'&c=【'.$signName.'】'.$content;
        return $this->http($url);
    }
 
    /**
     * 通用CURL請求
     * @param $url  需要請求的url
     * @param null $data
     * return mixed 返回值 json格式的數據
     */
    private function http($url,$data=null)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $info = curl_exec($curl);
        curl_close($curl);
        return $info;
    }
}

接著創建:\plugins\smsbao\admin\Setting.php文件,代碼如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
namespace plugins\smsbao\admin;
 
use app\common\controller\admin\Setting AS _Setting;
 
class Setting extends _Setting
{    
    /**
     * 參數設置
     * {@inheritDoc}
     * @see \app\common\controller\admin\Setting::index()
     */
    public function index($group=null){
        return parent::index($group);
    }
}

接著創建安裝數據表的文件:\plugins\smsbao\install\install.sql,代碼如下

?
INSERT INTO `qb_config` (`id`, `type`, `title`, `c_key`, `c_value`, `form_type`, `options`, `ifsys`, `htmlcode`, `c_descrip`, `list`, `sys_id`) VALUES('', -1, '短信寶模板''sms_template''''text''', 1, '''例如:您的驗證碼為code,請妥善保存。', 7, 0);
INSERT INTO `qb_config` (`id`, `type`, `title`, `c_key`, `c_value`, `form_type`, `options`, `ifsys`, `htmlcode`, `c_descrip`, `list`, `sys_id`) VALUES('', -1, '短信寶簽名''smsbao_sign''''text''', 1, '''', 8, 0);
INSERT INTO `qb_config` (`id`, `type`, `title`, `c_key`, `c_value`, `form_type`, `options`, `ifsys`, `htmlcode`, `c_descrip`, `list`, `sys_id`) VALUES('', -1, '短信寶密碼''smsbao_pass''''text''', 1, '''即AccessKeySecret', 9, 0);
INSERT INTO `qb_config` (`id`, `type`, `title`, `c_key`, `c_value`, `form_type`, `options`, `ifsys`, `htmlcode`, `c_descrip`, `list`, `sys_id`) VALUES('', -1, '短信寶用戶名''smsbao_user''''text''', 1, '''即AccessKeyId', 10, 0);

最后打開項目:\application\common\util\Sms.php文件,替換為以下代碼

?
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
<?php
namespace app\common\util;
class Sms{
    public function send($phone='',$msg=''){
        // 如果$msg長度大于6位的話,判斷是營銷信息的話,可以在這里更換其它接口
        return $this->smsbao($phone,$msg);
    }
    private function smsbao($phone='',$msg=''){
        if(!class_exists("\\plugins\\smsbao\\Api")){
            return '短信接口不存在';
        }
        $obj new \plugins\smsbao\Api(config('webdb.smsbao_user'),config('webdb.smsbao_pass'));
        $signName = config('webdb.smsbao_sign');        //簽名,比如齊博
        $templateCode = config('webdb.sms_template');     //使用的模板,比如SMS_16830430
        $phoneNumbers $phone;
        $templateParam = ['code'=>$msg];
        $result $obj->sendSms($signName$templateCode$phoneNumbers$templateParam);
        if($result=='0'){
            return true;
        }else{
            return $result;
        }
    }    
    //其它短信接口
    private function other_sms(){        
    }
    
}

經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:

報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。

另外:我們已經開發好完整的齊博X1系統短信寶插件,點擊此鏈接 下載及查看安裝流程。

開源插件

最新更新

電商類

CMS類

微信類

文章標簽