外卖人是一款基于PHP+MYSQL开发的一套外卖订餐系统,有微信订餐、wap订餐、预定桌位等等多种外卖功能,是一款非常不错的订餐系统,小编今天就以替换短信接口为例带大家进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
下面我们进行接口替换,首先我们需要修改后台模版文件,打开项目\templates\adminpage\other\smsset.html文件,将下列代码进行覆盖替换即可:
| 
 
						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 
 | 
 <{extends file="<{$tempdir}>/public/admin.html"}>   <{block name=extendjs}><script type="text/javascript" language="javascript" src="<{$siteurl}>/templates/<{$tempdir}>/public/js/artdialog/plugins/iframeTools.js"></script> <{/block}> <{block name=controlname}>短信设置<{/block}> <{block name=bodylist}>       <div style="width:auto;overflow-x:hidden;overflow-y:auto;">          <div id="tagscontent">            <form method="post" name="form1" action="<{ofunc type=url link="/adminpage/other/module/smssetsave/datatype/json"}>" onsubmit="return subform('',this);">              <div>                 <table border="0" cellspacing="2"   class="list" name="table" id="table1" width="100%">                  <tbody>                     <tr onmouseover="this.bgColor='#F5F5F5';" onmouseout="this.bgColor='ffffff';" bgcolor="#ffffff">                      <td class="left" width="20%">选择短信发送类型</td>                      <td>                         <select name="smstype" id="smstype" onchange="doinfo();">                                <option value="2" selected >短信宝短信接口</option>                       </select>                       </td>                    </tr>                  </tbody>                </table>                <table border="0" cellspacing="2" cellpadding="4" class="list" name="table" id="table3" width="100%">                  <tbody>                                       <tr onmouseover="this.bgColor='#F5F5F5';" onmouseout="this.bgColor='ffffff';" bgcolor="#ffffff">                      <td class="left">短信宝用户名</td>                      <td><input type="text" name="sms86ac" id="sms86ac" value="<{$sms86ac}>" class="skey" style="width:250px;"></td>                    </tr>                    <tr onmouseover="this.bgColor='#F5F5F5';" onmouseout="this.bgColor='ffffff';" bgcolor="#ffffff">                      <td class="left">短信宝密码</td>                      <td><input type="password" name="sms86pd" id="sms86pd" value="<{$sms86pd}>" class="skey" style="width:250px;"></td>                    </tr>                  </tbody>                </table>                             </div>              <div class="blank20"></div>              <input type="hidden" name="tijiao" id="tijiao" value="do" class="skey" style="width:250px;">              <input type="hidden" name="saction" id="saction" value="siteset" class="skey" style="width:250px;">               <input type="submit" value="确认提交" class="button">            </form>          </div>         </div>     </div> <{/block}> | 
接下来我们去修改短信发送接口,打开项目\class\phonecode.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 
						118 
						119 
						120 
						121 
						122 
						123 
						124 
						125 
						126 
						127 
						128 
						129 
						130 
						131 
						132 
						133 
						134 
						135 
						136 
						137 
						138 
						139 
						140 
						141 
						142 
						143 
						144 
						145 
						146 
						147 
						148 
						149 
						150 
						151 
						152 
						153 
						154 
						155 
						156 
						157 
						158 
						159 
						160 
						161 
						162 
						163 
						164 
						165 
						166 
						167 
						168 
						169 
						170 
						171 
						172 
						173 
						174 
						175 
						176 
						177 
						178 
						179 
						180 
						181 
						182 
						183 
						184 
						185 
						186 
						187 
						188 
						189 
						190 
						191 
						192 
						193 
						194 
						195 
						196 
						197 
 | 
<?php  /** * modify 2016-11-23 * @class 手机验证码 * @brief 促销规则  */class  phonecode{        private $mysql;//数据库连接    //短信主要类容    private $maincontent = array(                                0=>'用户注册,验证码:',                                1=>'登录,验证码:',                                2=>'找回密码,验证码:',                                3=>'更换手机,号验证码:',                                4=>'手机快捷登录,验证码:',                                5=>'更换密码,验证码:',                                6=>'下单,验证码:',                                7=>'APP调用用户登录验证',                                8=>'新绑定手机号',                                9=>'您好,尊敬的会员,验证码为:',                            );   public   $qianming ;//短信签名    private $sendtype;//验证发送类型    private $typearray = array(0,1,2,3,4,5,6,7,8,9);//用户检测代码    private $phone;//手机号    private   $limittime = 120;//短信有效时间    private $code;//验证码;    private $timelong = 0;//短信失效时间        private $errId;       //初始化函数  type 0.用户注册  1登录验证 2.找回密码   3更换手机号  4手机快捷登录   5更换密码        //IFilter::act(IReq::get('phone'));        //初始化  $mysql 数据库连接  $sendtype 验证码类型=  phone 接受手机号      function __construct($mysql,$type,$phone=''){               $this->mysql = $mysql;          $this->sendtype =  $type;        $this->phone = empty($phone)?intval(IFilter::act(IReq::get('phone'))):$phone;         $msgqianming = '';        $msgqianming = Mysite::$app->config['msgqianming'];        if( !empty($msgqianming) ){            $this->qianming =  $msgqianming;        }else{            $this->qianming =  Mysite::$app->config['sitename'];        }                 $this->timelong = 0;        //$this->tablepre = Mysite::$app->config['mobileapp'];     }    public function sendother($msg){        $contents =  '【'.$this->qianming.'】'.$msg;         $url = 'http://api.smsbao.com/sms?u='.Mysite::$app->config['sms86ac'].'&p='.md5(Mysite::$app->config['sms86pd']).'&m='.$this->phone.'&c='.urlencode($contents);        logwrite('短信发送链接:'.$url);           $contentcccc =  file_get_contents($url);           logwrite('短信发送结果:'.$contentcccc);       }    //    public function sendcode(){                  if(!IValidate::suremobi($this->phone)){            $this->errId = '手机号格式错误';              return false;        }          if(!in_array($this->sendtype,$this->typearray)){              $this->errId = '未定义的发送类型';              return false;        }          if($this->sendtype == 2){              $checkmember = $this->mysql->select_one("select * from ".Mysite::$app->config['tablepre']."member where phone ='".$this->phone."'   order by uid desc limit 0,1");              if(empty($checkmember)){                    $this->errId = '手机对应用户不存在';                    return false;               }         }elseif($this->sendtype == 3){              $checkmember = $this->mysql->select_one("select * from ".Mysite::$app->config['tablepre']."member where phone ='".$this->phone."'   order by uid desc limit 0,1");              if(empty($checkmember)){                    $this->errId = '手机对应用户不存在';                    return false;               }         }elseif($this->sendtype == 4){                                                            }elseif($this->sendtype == 5){              $checkmember = $this->mysql->select_one("select * from ".Mysite::$app->config['tablepre']."member where phone ='".$this->phone."'   order by uid desc limit 0,1");              if(empty($checkmember)){                    $this->errId = '手机对应用户不存在';                    return false;               }         }elseif($this->sendtype == 0){              $checkmember = $this->mysql->select_one("select * from ".Mysite::$app->config['tablepre']."member where phone ='".$this->phone."'   order by uid desc limit 0,1");              if(!empty($checkmember)){                    $this->errId = '手机号对应用户已存在';                    return false;               }         }elseif($this->sendtype == 8){            $checkmember = $this->mysql->select_one("select * from ".Mysite::$app->config['tablepre']."member where phone ='".$this->phone."'   order by uid desc limit 0,1");              if(!empty($checkmember)){                    $this->errId = '手机号对应用户已存在';                    return false;               }         }         $checkphone = $this->mysql->select_one("select * from ".Mysite::$app->config['tablepre']."mobileapp where phone ='".$this->phone."'  and type='".$this->sendtype."' order by addtime desc limit 0,1");        if(!empty($checkphone)){            //$checktime = time()-$this->limittime;             if($checkphone['addtime'] > time()){                // $this->errId = '验证码还未失效';                $this->code = $checkphone['code'];                $this->timelong = $checkphone['addtime'] - time();                return true;            }        }        $mintime = strtotime(date('Y-m-d',time()));        $checkcounts = $this->mysql->counts("select * from ".Mysite::$app->config['tablepre']."mobileapp where phone ='".$this->phone."' and type='".$this->sendtype."' and addtime > ".$mintime." ");        if($checkcounts > 3){            $this->errId = '每天发送验证码不能超过3次';            return false;         }         $this->code = rand(1000,9999);          $data['phone'] = $this->phone;        $data['addtime'] = time()+$this->limittime;        $data['code'] = $this->code;        $data['type'] = $this->sendtype;        $this->mysql->insert(Mysite::$app->config['tablepre'].'mobileapp',$data);              $contents =  '【'.$this->qianming.'】'.$this->maincontent[$this->sendtype].$this->code;          $url = 'http://api.smsbao.com/sms?u='.Mysite::$app->config['sms86ac'].'&p='.md5(Mysite::$app->config['sms86pd']).'&m='.$this->phone.'&c='.urlencode($contents);  $contentcccc =  file_get_contents($url);          logwrite('短信发送链接:'. $url);             $this->timelong = $this->limittime;                  logwrite('短信发送结果:'.$contentcccc);            return true;     }    //校验验证码是否有效   $Inputcode 校验code    public function checkcode($Inputcode){        #$checkcancode = Mysite::$app->config['allowedcode'];        $checkcancode = Mysite::$app->config['regestercode'];                if($this->sendtype != 4){            if($checkcancode != 1){                     return true;             }         }        if(!IValidate::suremobi($this->phone)){            $this->errId = '手机号格式错误';              return false;        }          if(!in_array($this->sendtype,$this->typearray)){              $this->errId = '未定义的发送类型';              return false;        }         if(empty($Inputcode)){               $this->errId = '未设置验证码';              return false;        }        $checkphone = $this->mysql->select_one("select * from ".Mysite::$app->config['tablepre']."mobileapp where phone ='".$this->phone."' and type='".$this->sendtype."'  order by addtime desc limit 0,1");        if(!empty($checkphone)){            $checktime = time()-$this->limittime;             if($checkphone['addtime'] > $checktime){                  if($Inputcode != $checkphone['code']){                    $this->errId = '验证码错误';                    return false;                }                $this->code = $checkphone['code'];                return true;            }else{                $this->errId = '验证码已失效';                return false;            }        }else{              $this->errId = '该手机号未发送验证码';              return false;        }    }    public function getCode(){        return $this->code;     }    public function getError()    {        return $this->errId;    }    public function getTime(){        return  $this->timelong;    }  }?> | 
	好了,经过以上的替换,短信宝的短信平台已经替换成功了,我们去进行发送测试:
	
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,并且免审核了,短信内容3~5秒就可送达。
另外:我们已经开发好完整的外卖人短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类