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


待發(fā)短信

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

4001-021-502

工作時(shí)間

9:00-21:00

iWebShop電商平臺(tái)短信接口替換

iwebshop電商平臺(tái)是一款基于php+mysql開發(fā)的100%開源軟件,支持二次開發(fā)和自由修改,具有跨平臺(tái)性適用于各種服務(wù)器環(huán)境,今天小編就分享一下如何進(jìn)行二次開發(fā),我以替換短信接口為例。一步步的教大家如何開發(fā),我們使用的短信接口是我們短信寶短信群發(fā)平臺(tái)的短信接口,我們短信寶短信群發(fā)平臺(tái)非常穩(wěn)定,發(fā)送速度快,注冊(cè)就送測試短信,推薦大家使用。

進(jìn)行短信接口替換,首先我們需要修改后臺(tái)的顯示界面,打開項(xiàng)目/views/sysdefault/hsms.html文件,修改6~57行左右,代碼如下:

?
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
<form action="#" method="post" name='sms_conf'>
    <table class="form_table">
        <colgroup>
            <col width="150px" /><col />
        </colgroup>
        <tr>
            <th>說明:</th>
            <td>還沒有注冊(cè)短信寶短信平臺(tái)的用戶,請(qǐng)點(diǎn)擊
                <a href="http://www.gjrencai.com" target="_blank" class="orange">注冊(cè)</a>
                <p>商城所用的短信內(nèi)容模板在【/classes/smstemplate.php】文件中,盡量用原始的短信模板,否則會(huì)導(dǎo)致短信發(fā)送延遲等問題</p>
                <p>如果想關(guān)閉某個(gè)短信發(fā)送環(huán)節(jié),可以直接把相應(yīng)方法的返回值設(shè)置為空</p>
            </td>
        </tr>
        <tr>
            <th>管理員手機(jī)號(hào):</th>
            <td><label class="red">【系統(tǒng)】——【網(wǎng)站設(shè)置】——【手機(jī)號(hào)】</label></td>
        </tr>
        <tr>
            <th>短信平臺(tái):</th>
            <td>
                <select name="sms_platform" class="normal">
                    <option value="smsbao">短信寶短信平臺(tái)</option>
                </select>
            </td>
        </tr>
        <tr>
            <th>用戶名:</th>
            <td><input type='text' class='normal' name='sms_username' pattern='required' alt='' /><label>短信寶用戶名</label></td>
        </tr>
        <tr>
            <th>密碼:</th>
            <td><input type='text' class='normal' name='sms_pwd' pattern='required' alt='' /><label>短信寶密碼</label></td>
        </tr>
        <tr>
            <th>簽名</th>
            <td><input type='text' class='normal' name='sms_userid' alt='' /><label>短信簽名(3-8個(gè)字符)</label></td>
        </tr>
        <tr>
            <th>測試手機(jī)號(hào)碼:</th>
            <td>
                <input type='text' class='normal' name='mobile' pattern='mobi' empty alt='填寫正確的手機(jī)號(hào)碼' />
                <label>必須先<保存>配置后,在測試短信發(fā)送的功能【可選】</label>
            </td>
        </tr>
        <tr>
            <th></th>
            <td>
                <button type='button' class="submit" onclick="submitConfig();"><span>保 存</span></button>
                <button class="submit" type='button' onclick="test_sendhsms(this);"><span id='testmobile'>測試短信發(fā)送</span></button>
            </td>
        </tr>
    </table>
</form>

后臺(tái)顯示界面修改完成后,我們接下來去修改發(fā)送短信的調(diào)用接口,將其修改成短信寶的接口,打開項(xiàng)目/classes/hsms.php文件,修改send方法,修改代碼如下:

?
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
/**
     * @brief 發(fā)送短信
     * @param string $mobiles 多個(gè)手機(jī)號(hào)為用半角,分開,如13899999999,13688888888(最多200個(gè))
     * @param string $content 短信內(nèi)容
     * @param int $delay 延遲設(shè)置
     * @return success or fail
     */
    public static function send($mobiles$content$delay = 1)
    {
        if(!$content)
        {
            return "短信內(nèi)容不能為空";
        }
 
        if( !isset($_SERVER['HTTP_USER_AGENT']) )
        {
            return "非客戶端訪問";
        }
 
        $mobile_array explode(","$mobiles);
        foreach ($mobile_array as $key => $val)
        {
            if(false === IValidate::mobi($val))
            {
                unset($mobile_array[$key]);
            }
        }
 
        if(!$mobile_array)
        {
            return "非法手機(jī)號(hào)碼";
        }
 
        if(count($mobile_array) > 200)
        {
            return "手機(jī)號(hào)超過200個(gè)";
        }
 
        //延遲機(jī)制
        if($delay == 1)
        {
            $cacheObj new ICache();
            $smsTime $cacheObj->get('smsDelay');
            if($smsTime && time() - $smsTime < self::$sendStep)
            {
                return "短信發(fā)送頻率太快,請(qǐng)稍候再試...";
            }
            //更新發(fā)送時(shí)間
            $cacheObj->set('smsDelay',time());
        }
 
        if(self::$smsInstance == null)
        {
            $platform = self::getPlatForm();
            switch($platform)
            {
                case "smsbao":
                {
                    $classFile = IWeb::$app->getBasePath().'plugins/hsms/smsbao.php';
                    require($classFile);
                    self::$smsInstance new smsbao();
                }
                break;
 
                default:
                {
                    $classFile = IWeb::$app->getBasePath().'plugins/hsms/smsbao.php';
                    require($classFile);
                    self::$smsInstance new smsbao();
                }
            }
        }
        return self::$smsInstance->send($mobiles$content);
    }
}

最后我們進(jìn)行添加短信寶的發(fā)送類,在項(xiàng)目/plugins/hsms下新建一個(gè)smsbao.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
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
<?php
/**
 * @copyright (c) 2016 smsbao.com
 * @file smsbao.php
 * @brief **短信發(fā)送接口
 * @author linf
 * @date 2016/11/21 11:10:38
 * @version 1.0
 */
 
 /**
 * @class smsbao
 * @brief 短信發(fā)送接口 http://api.smsbao.com/sms
 */
class smsbao extends hsmsBase
{
    private $submitUrl  "http://api.smsbao.com/sms";
    /**
     * @brief 獲取config用戶配置
     * @return array
     */
    public function getConfig()
    {
        $siteConfigObj new Config("site_config");
 
        return array(
            'username' => $siteConfigObj->sms_username,
            'userpwd'  => $siteConfigObj->sms_pwd,
            'sign'  => $siteConfigObj->sms_userid,
        );
    }
 
    /**
     * @brief 發(fā)送短信
     * @param string $mobile
     * @param string $content
     * @return
     */
    public function send($mobile,$content)
    {
        $config = self::getConfig();
 
        $post_data array(
            'u' => $config['username'],
            'p' => md5($config['userpwd']),
            'c'  => '【'.$config['sign'].'】'.$content,
            'm'   => $mobile,
        );
 
        $url    $this->submitUrl;
        $string '';
        foreach ($post_data as $k => $v)
        {
           $string .="$k=".urlencode($v).'&';
        }
 
        $post_string substr($string,0,-1);
 
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要將結(jié)果直接返回到變量里,那加上這句。
        $result = curl_exec($ch);
        return $this->response($result);
    }
 
    /**
     * @brief 解析結(jié)果
     * @param $result 發(fā)送結(jié)果
     * @return string success or fail
     */
    public function response($result)
    {
        if(trim($result) =='0')
        {
            return 'success';
        }
        else
        {
            return $this->getMessage($result);
        }
    }
 
    /**
     * @brief 獲取參數(shù)
     */
    public function getParam()
    {
        return array(
            "username" => "用戶名",
            "userpwd"  => "密碼",
            "usersign" => "短信簽名",
        );
    }
 
 
    //返回消息提示
    public function getMessage($code)
    {
        $messageArray array(
            -1 =>"參數(shù)不全",
            30  =>"密碼錯(cuò)誤",
            40  =>"賬號(hào)不存在",
            41  =>"余額不足",
            42  =>"賬號(hào)過期",
            43  =>"IP地址限制",
            50  =>"內(nèi)容含有敏感詞",
            51 =>"手機(jī)號(hào)碼不正確",
        );
        return isset($messageArray[$code]) ? $messageArray[$code] : "未知錯(cuò)誤";
    }
}

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

報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,并且免審核了,短信內(nèi)容3~5秒就可送達(dá)。
開源插件

最新更新

電商類

CMS類

微信類

文章標(biāo)簽