待发短信

在线客服
产品支持 短信宝客服
合作渠道 渠道合作
服务咨询

4001-021-502

工作时间

9:00-21:00

iwebshop商城V5.15版本新增短信宝短信接口

iWebShop是一款基于PHP语言及MYSQL数据库开发的B2B2C多用户开源免费的商城系统,系统支持平台自营和多商家入驻、集成微信商城、手机商城、移动端APP商城于一体。二次开发非常方便,小编对他还是比较了解的,今天小编为大家讲解iWebShop_5.15版本的短信接口替换,使用的接口是我们短信宝群发平台的短信接口,我们短信宝群发短信平台非常稳定,发送速度快,注册还送测试短信,推荐大家使用。
首先打开项目:iwebshop-master\views\sysdm\system\hsms.html文件,替换34~59代码

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
<tr>
    <th>短信平台:</th>
    <td>
        <select name="sms_platform" class="form-control">
            <option value="smsbao">短信宝短信平台【国内】</option>
            <option value="smsbaoWorld">短信宝短信平台【国际】</option>
        </select>
    </td>
</tr>
<tr>
    <th>短信签名:</th>
    <td><input type='text' class='form-control' name='sms_sign' pattern='required' alt='' /></td>
</tr>
<tr>
    <th>短信宝账号:</th>
    <td><input type='text' class='form-control' name='sms_username' pattern='required' alt='' />
        <p class="help-block">还没有短信宝账号?<a href="https://console.smsbao.com/#/register" target="_blank">去注册</a></p>
    </td>
</tr>
<tr>
    <th>APIKEY:</th>
    <td><input type='text' class='form-control' name='sms_pwd' pattern='required' alt='' />
        <p class="help-block">短信宝APIKEY</p>
    </td>
</tr>

接着在plugins\_hsms目录下新增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
<?php
/**
 * @class smsbao
 * @brief 短信发送接口 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_sign,
        );
    }
 
    /**
     * @brief 发送短信
     * @param string $mobile
     * @param string $content
     * @return
     */
    public function send($mobile,$content)
    {
        $config = self::getConfig();
 
        $post_data array(
            'u' => $config['username'],
            'p' => $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); //如果需要将结果直接返回到变量里,那加上这句。
        $result = curl_exec($ch);
        return $this->response($result);
    }
 
    /**
     * @brief 解析结果
     * @param $result 发送结果
     * @return string success or fail
     */
    public function response($result)
    {
        if(trim($result) =='0')
        {
            return 'success';
        }
        else
        {
            return $this->getMessage($result);
        }
    }
 
    /**
     * @brief 获取参数
     */
    public function getParam()
    {
        return array(
            "username" => "用户名",
            "userpwd"  => "密码",
            "usersign" => "短信签名",
        );
    }
 
 
    //返回消息提示
    public function getMessage($code)
    {
        $messageArray array(
            -1 =>"参数不全",
            30  =>"密码错误",
            40  =>"账号不存在",
            41  =>"余额不足",
            42  =>"账号过期",
            43  =>"IP地址限制",
            50  =>"内容含有敏感词",
            51 =>"手机号码不正确",
        );
        return isset($messageArray[$code]) ? $messageArray[$code] : "未知错误";
    }
}

接着在plugins\_hsms目录下新增smsbaoWorld.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
115
116
117
<?php
/**
 * @class smsbao
 * @brief 短信发送接口 http://api.smsbao.com/sms
 */
class smsbaoWorld extends hsmsBase
{
    private $submitUrl  "http://api.smsbao.com/wsms";
    private $countryCode"61";//国家编号
    /**
     * @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_sign,
        );
    }
      //处理手机号码
    private function filterMobile($mobile)
    {
        if(stripos($mobile,'0') === 0)
        {
            $mobile substr($mobile,1);
        }
        return $mobile;
    }
 
 
    /**
     * @brief 发送短信
     * @param string $mobile
     * @param string $content
     * @return
     */
    public function send($mobile,$content)
    {
        $mobile $this->filterMobile($mobile);
        $config = self::getConfig();
        date_default_timezone_set('Asia/Shanghai');
        $post_data array(
            'u' => $config['username'],
            'p' => $config['userpwd'],
            'c'  => UrlEncode('【'.$config['sign'].'】'.$content),
            'm'   => UrlEncode('+'.$this->countryCode.$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); //如果需要将结果直接返回到变量里,那加上这句。
        $result = curl_exec($ch);
        return $this->response($result);
    }
 
    /**
     * @brief 解析结果
     * @param $result 发送结果
     * @return string success or fail
     */
    public function response($result)
    {
        if(trim($result) =='0')
        {
            return 'success';
        }
        else
        {
            return $this->getMessage($result);
        }
    }
 
    /**
     * @brief 获取参数
     */
    public function getParam()
    {
        return array(
            "username" => "用户名",
            "userpwd"  => "密码",
            "usersign" => "短信签名",
        );
    }
 
 
    //返回消息提示
    public function getMessage($code)
    {
        $messageArray array(
            -1 =>"参数不全",
            30  =>"密码错误",
            40  =>"账号不存在",
            41  =>"余额不足",
            42  =>"账号过期",
            43  =>"IP地址限制",
            50  =>"内容含有敏感词",
            51 =>"手机号码不正确",
        );
        return isset($messageArray[$code]) ? $messageArray[$code] : "未知错误";
    }
}

好了经过以上的添加,短信宝的短信平台已经替换成功了,可以正常使用了

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。

另外:我们已经开发好完整的iWebShop_V5.15系统短信宝插件,点击此链接 下载及查看安装流程。

开源插件

最新更新

电商类

CMS类

微信类

文章标签