啦啦外卖跑腿是一款用PHP+MYSQL开发的一套外卖跑腿送餐系统,是一款非常不错的系统,小编今天就以替换短信接口为例带大家进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用
1:打开项目:addons\we7_wmall\template\web\config\sms.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
|
<div class= "form-group" > <label class= "col-xs-12 col-sm-3 col-md-2 control-label" >短信/语音平台</label> <div class= "col-sm-9 col-xs-12" > <div class= "radio radio-inline" onclick= "$('.setting-aliyun').show(); $('.setting-smsbao').hide(); $('.apply-aliyun').show(); $('.apply-smsbao').hide();" > <input type= "radio" value= "aliyun" name= "type" id= "type-aliyun" { if $sms[ 'type' ] == 'aliyun' || !$sms[ 'type' ]}checked{/ if } required= "true" > <label for = "type-aliyun" >阿里云</label> <div></div> </div> <div class= "radio radio-inline" onclick= "$('.setting-smsbao').show(); $('.setting-aliyun').hide(); $('.apply-smsbao').show(); $('.apply-aliyun').hide();" > <input type= "radio" value= "smsbao" name= "type" id= "type-smsbao" { if $sms[ 'type' ] == 'smsbao' }checked{/ if } required= "true" > <label for = "type-smsbao" >短信宝</label> </div> <div class= "apply-aliyun" { if $sms[ 'type' ] == 'aliyun' || !$sms[ 'type' ]}style= "display: block;" { else }style= "display: none;" {/ if }> <div class= "help-block" > <a href= "https://www.aliyun.com/product/sms?spm=5176.8142029.388261.400.e9396d3eYxsqzP" target= "_blank" >立即申请 "阿里云" 短信平台</a> </div> </div> <div class= "apply-smsbao" { if $sms[ 'type' ] == 'smsbao' }style= "display: block;" { else }style= "display: none;" {/ if }> <div class= "help-block" > </div> <div class= "help-block" > </div> </div> </div> </div> <div class= "setting-smsbao" { if $sms[ 'type' ] == 'smsbao' }style= "display: block;" { else }style= "display: none;" {/ if }> <div class= "form-group" > <label class= "col-xs-12 col-sm-3 col-md-2 control-label" >短信宝账号</label> <div class= "col-sm-9 col-xs-12" > <input type= "text" class= "form-control" name= "app_key" value= "{$sms['smsbao']['app_key']}" > <span class= "help-block" >还没有短信账号? <a href= "http://console.smsbao.com/#/register" target= "_blank" >现在去创建</a></span> </div> </div> <div class= "form-group" > <label class= "col-xs-12 col-sm-3 col-md-2 control-label" >短信宝密码</label> <div class= "col-sm-9 col-xs-12" > <input type= "text" class= "form-control" name= "app_secret" value= "{$sms['smsbao']['app_secret']}" > </div> </div> <div class= "form-group" > <label class= "col-xs-12 col-sm-3 col-md-2 control-label" >短信签名</label> <div class= "col-sm-9 col-xs-12" > <input type= "text" class= "form-control" name= "signature" value= "{$sms['smsbao']['signature']}" > <span class= "help-block" >请填写短信签名.</span> </div> </div> </div> |
2:打开项目:addons\we7_wmall\inc\web\config\sms.inc.php修改保存方法大概19行
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
|
if ($op == "set" ) { $_W[ "page" ][ "title" ] = "短信平台" ; if ($_W[ "ispost" ]) { $type = trim($_GPC[ "type" ]); if (!in_array($type, array( "aliyun" , "smsbao" ))) { imessage(error(-1, "请选择短信/语音平台" ), "" , "ajax" ); } if ($type == "smsbao" ) { intval($_GPC[ "status" ]); trim($_GPC[ "app_key" ]); trim($_GPC[ "app_secret" ]); trim($_GPC[ "signature" ]); $sms = array( "status" => intval($_GPC[ "status" ]), "type" => $type, "smsbao" => array( "app_key" => trim($_GPC[ "app_key" ]), "app_secret" => trim($_GPC[ "app_secret" ]), "signature" => trim($_GPC[ "signature" ]))); } else { if ($type == "aliyun" ) { intval($_GPC[ "status" ]); intval($_GPC[ "version" ]); trim($_GPC[ "key" ]); trim($_GPC[ "secret" ]); trim($_GPC[ "sign" ]); $sms = array( "status" => intval($_GPC[ "status" ]), "type" => $type, "version" => intval($_GPC[ "version" ]), "key" => trim($_GPC[ "key" ]), "secret" => trim($_GPC[ "secret" ]), "sign" => trim($_GPC[ "sign" ])); } } set_system_config( 'sms.set' , $sms); imessage(error(0, '短信平台设置成功' ), ireferer(), 'ajax' ); } $sms = $_config[ "sms" ][ "set" ]; } |
3:打开项目:addons\we7_wmall\inc\mobile\system\common\code.inc.php 修改为短信宝发送类型
1
2
3
4
5
6
7
8
|
if (is_error($result)) { if ($config_sms[ "set" ][ "type" ] == "smsbao" ) { slog( "huaweiSms" , "短信宝短信通知验证码" , $content, $result[ "message" ]); } else { slog( 'alidayuSms' , '阿里大鱼短信通知验证码' , $content, $result[ "message" ]); } exit($result[ "message" ]); } |
4:打开项目:addons\we7_wmall\class\sms.class.php 修改大概25行 增加短信宝类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
public static function create($type = "" , $scene = "code" ) { global $_W; if (empty($type)) { if ($scene == "yinsihao" ) { $config = get_plugin_config( "yinsihao.basic" ); } else { $config = $_W[ "we7_wmall" ][ "config" ][ "sms" ][ "set" ]; } $type = !empty($config[ "type" ]) ? $config[ "type" ] : "aliyun" ; } if ($type == "smsbao" ) { mload()->classs( "smsbao.sms" ); return new SmsbaoSms(); } if (check_plugin_perm( 'iglobal' ) && $_W[ "we7_wmall" ][ "config" ][ "iglobal" ][ "sms_type" ] == 1) { mload()->classs( "aliglobal.sms" ); return new AliGlobalSms(); } mload()->classs( 'aliyun.sms' ); return new AliyunSms(); } |
5:打开项目:addons\we7_wmall\class 当前目录增加smsbao.sms.class.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
|
<?php defined( 'IN_IA' ) or exit( 'Access Denied' ); load()->func( 'communication' ); class SmsbaoSms{ public function __construct() { } public function sendCode($template, $mobile, $content, $sid) { global $_W; $config_sms = $_W[ 'we7_wmall' ][ 'config' ][ 'sms' ]; if (!is_array($config_sms[ 'set' ])) { return error(-1, '平台没有设置短信参数' ); } if (empty($config_sms[ 'set' ][ 'status' ])) { return error(-1, '平台已关闭短信功能' ); } $appKey = $config_sms[ 'set' ][ 'smsbao' ][ 'app_key' ]; $appSecret = $config_sms[ 'set' ][ 'smsbao' ][ 'app_secret' ]; $signature = $config_sms[ 'set' ][ 'smsbao' ][ 'signature' ]; $statusStr = array( "0" => "短信发送成功" , "-1" => "参数不全" , "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!" , "30" => "密码错误" , "40" => "账号不存在" , "41" => "余额不足" , "42" => "帐户已过期" , "43" => "IP地址限制" , "50" => "内容含有敏感词" ); $user = $appKey; //短信平台帐号 $pass = md5($appSecret); //短信平台密码 $phone = $mobile; //要发送短信的手机号码 $code = array_values($content)[0]; $content = '【' .$signature. '】' .str_replace( '${code}' ,$code,$template); $sendurl = $smsapi. "sms?u=" .$user. "&p=" .$pass. "&m=" .$phone. "&c=" .urlencode($content); $result =file_get_contents($sendurl) ; if (is_error($result)) { return $result; } if ($result != '0' ) { return error(-1, $statusStr[$result]); } return true ; } } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的独立版-啦啦外卖V45.6短信宝插件,点击此链接 下载及查看安装流
最新更新
电商类
CMS类
微信类