待发短信

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

4001-021-502

工作时间

9:00-21:00

ECShop小鲸懂商城新增短信宝短信接口

今天小编为大家讲解一下ECShop小鲸懂商城7.9.9版本的短信宝短信接口是如何开发的。我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。

首先我们打开项目\admin\sms.php文件,替换24~79行的代码:

?
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
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>短信宝短信管理</title>
<style type="text/css" >
    :focus{outline:none;}
    .myem {font-size: 15px;color: black;font-weight: bold;}
    .main {padding-left: 60px;}
    .button {width: 150px;height: 35px;border-radius: 5px;border: none;background-color: #0E94D1;color: #FFF;margin-left: 66px;}
    .button:hover {cursor: pointer;}
    a{color: red;text-decoration: none;margin-left: 8px;}
    a:hover {color: red;text-decoration: underline;}
    .div1 {color: black;font-size: 14px;}
    input {padding: 3px 5px;font:12px "sans-serif", "Arial", "Verdana";line-height: 12px;}
    body{font:12px "sans-serif", "Arial", "Verdana";}
    span {line-height: 25px;color: gray;font-size: 13px;}
    h3{font-size: 18px;border-bottom: 1px solid #DCDCDC;padding: 10px 0;}
    p{font:12px "sans-serif", "Arial", "Verdana";}
</style>
<body>
<h3 align="center">短信宝短信管理</h3>
<div class="main">
    <form method="post" action="">
        <div class="div1">
                <span class="myem">请填写短信宝短信参数<a href="http://www.smsbao.com" target="_blank">免费注册短信宝账号</a></span>
            <p> 短信宝用户名&nbsp;:<input type="text" id="appkey" name="hy_appkey" value='<?php echo $hy_appkey ?>'/>
            <p>短信宝账号密码:<input type="password" id="secretkey" name="hy_secretkey" style="width: 228px;" value='<?php echo $hy_secretkey ?>'/><p>
            <p style="color: #808080;"> 特别注意:① 请前往:系统设置 -> 商店设置 -> 短信设置 填写短信模板内容和短信签名</p>
            <p style="color: #808080;">      ② 如需帮助,请联系<a href="http://wpa.b.qq.com/cgi/wpa.php?ln=1&key=XzkzODA0NjAyMV8yNTU0MzFfNDAwMDA5MDQ2NV8yXw" target="_blank" style="margin: 0 5px;">短信宝客服</a></p>
        </div>
 
        <!-- 短信模板 -->
        <div class="div2">
            <span class="myem" >虚拟卡发货是否发送短信给客户</span><br/>
            是<input type="radio" name="mobile_virtual" value="1" <?php if($mobile_virtual==1){echo 'checked';} ?>/>
            否<input type="radio" name="mobile_virtual" value="0" <?php if($mobile_virtual==0){echo 'checked';} ?>/><br/>
            短信模板内容:<input name="mobile_virtual_template" type="text" value='<?php echo $mobile_virtual_template ?>'/><br/>
            <span>模板内容示例:您已获得店铺${supplier_name}的${goods_name}虚拟卡,卡号为:${card_sn},有效期为:${vali_date}</span><p>
        </div>
 
        <div class="div2">
            <span class="myem" >是否开启报错提示</span><br/>
            是<input type="radio" name="hy_showbug" value="1" <?php if($hy_showbug==1){echo 'checked';} ?>/>
            否<input type="radio" name="hy_showbug" value="0" <?php if($hy_showbug==0){echo 'checked';} ?>/><br/>
            <span>开启后,短信发送失败时,将提示详细错误信息。</span><p>
        </div>
 
        <input class="button" type="submit" name="submit" id="submit" value="提交修改"/><br/><br/><br/>
    </form>
</div>
<div style="width: 100%;line-height: 35px;font-size: 12px;color: #585858;text-align: center;position:fixed;bottom:0;border-top: 1px solid #DCDCDC;"><a href="http://hongyuvip.com" target="_blank" style="text-decoration: none;color: #585858;">Copyright © 2015 - 2016 鸿宇科技 版权所有 盗版必究 </a></div>
</body>
</html>

接下来打开项目\mobile\sms\sms.php文件替换sendSMS函数

?
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
function sendSMS($mobile_phone$content)
{
   include "hy_config.php";
   $smsbao_param['u']=$hy_appkey;
   $smsbao_param['p']=md5($hy_secretkey);
   $smsbao_param['m']=$mobile_phone;
   $smsbao_param['c']=$content[0];
   $param_val=json_decode($content[1],true);
   if(!isset($param_val['product'])){
    $param_val[]=$content[2];
   }
   //由于变量个人不确定,判断数组长度来替换变量
   $count=count($param_val);
   foreach($param_val as $key=>$val){
    $new_param_val[]=$val;
   }
   if($count==1){
    $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0]);
   }elseif($count==2){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1]);
   }elseif($count==3){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1],$new_param_val[2]);
   }elseif($count==4){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1],$new_param_val[2],$new_param_val[3]);
   }elseif($count==5){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1],$new_param_val[2],$new_param_val[3],$new_param_val[4]);
   }elseif($count==6){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1],$new_param_val[2],$new_param_val[3],$new_param_val[4],$new_param_val[5]);
   }elseif($count==7){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1],$new_param_val[2],$new_param_val[3],$new_param_val[4],$new_param_val[5],$new_param_val[6]);
   }
  
   $hy_result=file_get_contents("http://api.smsbao.com/sms?".http_build_query($smsbao_param));
   $hy_result=$hy_result=='0'?1:0;
 
   if ($hy_result == true) {
       return true;
   else {
       if($hy_showbug == true){
           $hy_result $resp->sub_msg;
           if(empty($hy_result)){
               echo "短信验证码发送失败!请检查:\n鸿宇管理中心->短信管理->短信账号与密码\n商店设置->短信设置->短信签名、对应的模板编号\n阿里开发者控制台->安全中心->IP白名单是否正确?";
           }else{
               echo "发送失败:【" $hy_result "】";
           }
           exit;
       }
       return false;
   }
}

最后打开项目\sms\sms.php文件,替换掉sendSMS函数

?
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
function sendSMS($mobile_phone$content)
{
   include "hy_config.php";
   $smsbao_param['u']=$hy_appkey;
   $smsbao_param['p']=md5($hy_secretkey);
   $smsbao_param['m']=$mobile_phone;
   $smsbao_param['c']="【{$content[2]}】".$content[0];
   $param_val=json_decode($content[1],true);
   if(!isset($param_val['product'])){
    $param_val[]=$content[2];
   }
   //由于变量个人不确定,判断数组长度来替换变量
   $count=count($param_val);
   foreach($param_val as $key=>$val){
    $new_param_val[]=$val;
   }
   if($count==1){
    $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0]);
   }elseif($count==2){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1]);
   }elseif($count==3){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1],$new_param_val[2]);
   }elseif($count==4){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1],$new_param_val[2],$new_param_val[3]);
   }elseif($count==5){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1],$new_param_val[2],$new_param_val[3],$new_param_val[4]);
   }elseif($count==6){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1],$new_param_val[2],$new_param_val[3],$new_param_val[4],$new_param_val[5]);
   }elseif($count==7){
     $smsbao_param['c']=sprintf($smsbao_param['c'],$new_param_val[0],$new_param_val[1],$new_param_val[2],$new_param_val[3],$new_param_val[4],$new_param_val[5],$new_param_val[6]);
   }
   
   $hy_result=file_get_contents("http://api.smsbao.com/sms?".http_build_query($smsbao_param));
   $hy_result=$hy_result=='0'?1:0;
 
   if ($hy_result == true) {
       return true;
   else {
       if($hy_showbug == true){
           $hy_result $resp->sub_msg;
           if(empty($hy_result)){
               echo "短信验证码发送失败!请检查:\n鸿宇管理中心->短信管理->短信账号与密码\n商店设置->短信设置->短信签名、对应的模板编号\n阿里开发者控制台->安全中心->IP白名单是否正确?";
           }else{
               echo "发送失败:【" $hy_result "】";
           }
           exit;
       }
       return false;
   }
}

经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:

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

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

开源插件

最新更新

电商类

CMS类

微信类

文章标签