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


待發(fā)短信

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

4001-021-502

工作時間

9:00-21:00

shopwindV5.0新增短信寶短信接口

shopwind是一款免費開源的輕量級電商系統(tǒng)。穩(wěn)定的架構(gòu)內(nèi)核,基于Yii2深度開發(fā),代碼開源,遵循Apache2.0協(xié)議,完善的開發(fā)文檔,功能模塊化,拒絕臃腫繁雜,源碼易讀方便二次開發(fā),豐富的API接口,數(shù)據(jù)通訊安全加簽,可以滿足任何功能插件開發(fā)的需要。小編對他還是比較了解的,今天小編就以新增短信接口為例,給大家講解一下如何進(jìn)行二次開發(fā),我們今天講解的是v5.0版本,使用的短信接口是我們短信寶短信群發(fā)平臺的短信接口,我們短信寶短信群發(fā)平臺的接口非常穩(wěn)定,發(fā)送速度快,注冊就送測試短信,推薦大家使用。
打開 shopwind/common/plugins/sms 新增短信寶smsbao目錄
插件的目錄結(jié)構(gòu)如下:
├─smsbao插件目錄
│ ├─plugin.info.php 短信插件配置信息
│ ├─SDK.php 繼承系統(tǒng)短信基類
│ ├─smsbao.plugin.php 短信寶核心發(fā)送短信類
1:首先創(chuàng)建SDK.php 文件,繼承系統(tǒng)短信基類文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
namespace common\plugins\sms\smsbao;
  
use yii;
use yii\base\InvalidConfigException;
  
/**
 * @Id smsbao.plugin.php 2025.7.4 $
 * @author smsbao
 */
  
class SDK {
  
}

2:接著創(chuàng)建plugin.info.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
<?php
  
namespace common\plugins\sms\smsbao;
  
use yii;
use yii\helpers\Url;
  
use common\library\Language;
  
  
/**
 * @Id smsbao.plugin.php 2025.7.4 $
 * @author smsbao
 */
return array(
    'code' => 'smsbao',
    'name' => '短信寶',
    'desc' => '短信寶為全國各大開源軟件提供全面的短信支持10年積累,專注提供更好的短信服務(wù)穩(wěn)定,快是我們不變的追求!。<a href="http://www.gjrencai.com/" target="_blank">接口申請</a>',
    'author' => 'SMSBAO',
    'website' => 'http://www.gjrencai.com',
    'version' => '1.0',
    'buttons' => array(
        array(
            'label' => Language::get('manage'),
            'url' => Url::toRoute(['sms/index'])
        )
    ),
    'config' => array(
        'uid' => array(
            'type' => 'text',
            'text' => '短信寶賬號'
        ),
        'ApiKey' => array(
            'type' => 'text',
            'text' => 'API Key'
        ),
        'scene' => array(
            'name' => 'config[scene]',
            'type' => 'checkbox',
            'text' => '啟用場景',
            'items' => array(
                'register' => '用戶注冊',
                'find_password' => '找回密碼'
            )
        )
    )
);

3:smsbao.plugin.php 是短信寶核心發(fā)送短信類

?
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
namespace common\plugins\sms\smsbao;
  
use yii;
  
use common\models\SmsTemplateModel;
  
use common\library\Basewind;
use common\library\Language;
use common\plugins\BaseSms;
  
/**
 * @Id smsbao.plugin.php 2025.7.4 $
 * @author smsbao
 */
  
class Smsbao extends BaseSms
{
    /**
     * 網(wǎng)關(guān)地址
     * @var string $gateway
     */
    protected $gateway ';
      
    /**
     * 短信實例
     * @var string $code
     */
    protected $code 'smsbao';
    protected $smbaostatus = [
        "0" => "短信發(fā)送成功",
        "-1" => "參數(shù)不全",
        "-2" => "服務(wù)器空間不支持,請確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!",
        "30" => "密碼錯誤",
        "40" => "賬號不存在",
        "41" => "余額不足",
        "42" => "帳戶已過期",
        "43" => "IP地址限制",
        "50" => "內(nèi)容含有敏感詞"
];
      
    /**
     * 發(fā)送短信
     * @param bool $valid 發(fā)送頻次等的校驗,如果是系統(tǒng)發(fā)送的短信,可以適當(dāng)?shù)牟蛔鲈撔r炓源_保發(fā)送成功
     */
    public function send($valid = true)
    {
        if(!$this->verify()) {
            return false;
        }
        
        if($valid === true && !$this->validSend()) {
            return false;
        }
          
        // 發(fā)送的短信信息校驗
        if($this->validData() == false) {
            return false;
        }
    
        $result $this->submit();
        if($result == '0') {
            $codekey $this->insert($result);
            return $codekey;
        }
  
        $this->errors = $this->smbaostatus[$result];
        $this->insert(0, $this->errors);
        return false;
    }
  
    /**
     * 測試短信發(fā)送
     */
    public function testsend($content '') {
        $this->content = $content;
        $result $this->submit();
        if($result == '0') {
            return true;
        }
  
        $this->errors = $this->smbaostatus[$result];
        return false;
    }
      
    /**
     * 執(zhí)行短信發(fā)生
     */
    private function submit()
    {
        $url $this->gateway.'sms?u='.$this->config['uid'].'&p='.$this->config['ApiKey'] .
        '&m=' $this->receiver . '&c=' . urlencode('【'.$this->signName.'】'.$this->content);
        return Basewind::curl($url);
    }
  
    /**
     * 檢測是否配置
     * @var boolean $force 是否驗證短信模板內(nèi)容
     */
    public function verify($force = true)
    {
        if(!$this->config['uid']) {
            $this->errors = '短信設(shè)置錯誤';
            return false;
        }
        if(!$this->config['ApiKey']) {
            $this->errors = '短信設(shè)置錯誤';
            return false;
        }
  
        // 如果是驗證非具體短信場景,可以不用驗證短信模板
        // 比如某個地方僅僅需要判斷密鑰是否配置,從而進(jìn)行開關(guān)控制
        if(!$force) {
            return true;
        }
  
        // 傳遞具體短信場景參數(shù),則驗證短信模板
        if(($template $this->getTemplate()) === false) {
            return false;
        }
        if(!$template || empty($template->content)) {
            $this->errors = Language::get('The "content" property must be set');
            return false;
        }
        if(empty($template->signName)) {
            $this->errors = Language::get('The "signName" property must be set');
            return false;
        }
  
        // 此處為必須賦值,避免無法發(fā)送短信
        $this->templateId = $template->templateId;
        $this->signName = $template->signName;
        $this->content = $this->getContent($template);
  
        return true;
    }
      
}

好了經(jīng)過以上的添加,短信寶的短信平臺已經(jīng)替換成功了,可以正常使用了

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

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

開源插件

最新更新

電商類

CMS類

微信類

文章標(biāo)簽