啦啦外卖跑腿是一款基于微擎框架用PHP+MYSQL开发的一套外卖跑腿送餐系统,是一款非常不错的系统,小编今天就以替换短信接口为例带大家进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先我们打开项目:\template\web\config\notice-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
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
|
< div class = "alert alert-warning" >开启此功能需要先开启短信功能并正确配置短信宝用户名和短信宝密码,< a href = "{php echo iurl('config/sms/set');}" target = "_blank" >现在去配置>></ a ></ div > < h3 >店员通知</ h3 > < 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" > < input type = "radio" value = "1" name = "clerk[status]" id = "clerk-status-1" {if $sms['clerk']['status'] == 1}checked{/if}> < label for = "clerk-status-1" >开启</ label > </ div > < div class = "radio radio-inline" > < input type = "radio" value = "0" name = "clerk[status]" id = "clerk-status-0" {if !$sms['clerk']['status']}checked{/if}> < label for = "clerk-status-0" >关闭</ label > </ div > < div class = "help-block" > < span class = "text-danger" >开启此功能需要先开启短信功能并正确配置短信宝用户名和短信宝密码</ span > </ div > </ 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 = "clerk[tts_code]" value = "{$sms['clerk']['tts_code']}" > < span class = "help-block" >< a href = "http://www.smsbao.com" target = "_blank" >联系短信宝客服</ a >报备模板后到达速度更快</ span > < span class = "help-block" > < strong class = "text-danger" >模板标题: 新外卖订单通知</ strong > < br > < strong class = "text-danger" >模板内容: 您好name,您的店铺store,有新的订单,订单总金额price元,请及时处理</ strong > </ span > </ div > </ div > < h3 >外卖订单配送员通知</ h3 > < 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" > < input type = "radio" value = "1" name = "deliveryer[status]" id = "deliveryer-status-1" {if $sms['deliveryer']['status'] == 1}checked{/if}> < label for = "deliveryer-status-1" >开启</ label > </ div > < div class = "radio radio-inline" > < input type = "radio" value = "0" name = "deliveryer[status]" id = "deliveryer-status-0" {if !$sms['deliveryer']['status']}checked{/if}> < label for = "deliveryer-status-0" >关闭</ label > </ div > < div class = "help-block" > < span class = "text-danger" >开启此功能需要先开启短信功能并正确配置短信宝用户名和短信宝密码</ span > </ div > </ 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 = "deliveryer[tts_code]" value = "{$sms['deliveryer']['tts_code']}" > < span class = "help-block" >< a href = "http://www.smsbao.com" target = "_blank" >联系短信宝客服</ a >报备模板后到达速度更快 </ span > < span class = "help-block" > < strong class = "text-danger" >模板标题: 新外卖配送订单通知</ strong > < br > < strong class = "text-danger" >模板内容: 您好name, 门店store有新的配送订单,快去抢单吧</ strong > </ span > </ div > </ div > {if check_plugin_perm('errander')} < h3 >跑腿订单配送员通知</ h3 > < 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" > < input type = "radio" value = "1" name = "errander_deliveryer[status]" id = "errander-deliveryer-status-1" {if $sms['errander_deliveryer']['status'] == 1}checked{/if}> < label for = "errander-deliveryer-status-1" >开启</ label > </ div > < div class = "radio radio-inline" > < input type = "radio" value = "0" name = "errander_deliveryer[status]" id = "errander-deliveryer-status-0" {if !$sms['errander_deliveryer']['status']}checked{/if}> < label for = "errander-deliveryer-status-0" >关闭</ label > </ div > < div class = "help-block" > < span class = "text-danger" >开启此功能需要先开启短信功能并正确配置短信宝用户名和短信宝密码</ span > </ div > </ 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 = "errander_deliveryer[tts_code]" value = "{$sms['errander_deliveryer']['tts_code']}" > < span class = "help-block" >< a href = "http://www.smsbao.com" target = "_blank" >联系短信宝客服</ a >报备模板后到达速度更快</ span > < span class = "help-block" > < strong class = "text-danger" >模板标题: 新跑腿配送订单通知</ strong > < br > < strong class = "text-danger" >模板内容: 您好name,平台有新的配送订单,本单可收益deliveryerfee元,快去抢单吧</ strong > </ span > </ div > </ div > {/if} < h3 >平台管理员变更配送员工作状态通知</ h3 > < 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" > < input type = "radio" value = "1" name = "work_status_change[status]" id = "work_status_change-1" {if $sms['work_status_change']['status'] == 1}checked{/if}> < label for = "work_status_change-1" >开启</ label > </ div > < div class = "radio radio-inline" > < input type = "radio" value = "0" name = "work_status_change[status]" id = "work_status_change-0" {if !$sms['work_status_change']['status']}checked{/if}> < label for = "work_status_change-0" >关闭</ label > </ div > < div class = "help-block" > < span class = "text-danger" >开启此功能需要先开启短信功能并正确配置短信宝用户名和短信宝密码</ span > </ div > </ 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 = "work_status_change[tts_code]" value = "{$sms['work_status_change']['tts_code']}" > < span class = "help-block" >< a href = "http://www.smsbao.com" target = "_blank" >联系短信宝客服</ a >报备模板后到达速度更快 </ span > < span class = "help-block" > < strong class = "text-danger" >模板标题: 配送员工作状态变更通知</ strong > < br > < strong class = "text-danger" >模板内容: 您好name,您的工作状态已变更为work_status_cn,如有疑问,请联系平台负责人</ strong > </ span > </ div > </ div > |
接着打开项目:\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
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
|
{itemplate 'public/header'} {if $op == 'set'} < div class = "page clearfix" > < h2 >{$_W['page']['title']}</ h2 > < form class = "form-horizontal form form-validate" id = "form1" action = "" method = "post" enctype = "multipart/form-data" > < div class = "alert alert-warning" >短信使用"短信宝"短信平台"。< a href = "http://www.smsbao.com/reg" target = "_blank" >立即申请</ a ></ 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" > < div class = "radio radio-inline" > < input type = "radio" value = "1" name = "status" id = "status-1" {if $sms['status'] == 1}checked{/if} required = "true" > < label for = "status-1" >开启</ label > </ div > < div class = "radio radio-inline" > < input type = "radio" value = "0" name = "status" id = "status-0" {if !$sms['status']}checked{/if} required = "true" > < label for = "status-0" >关闭</ label > </ div > < div class = "help-block" >开启短信功能后,所有门店都可以使用该短信设置.</ div > </ 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" > < div class = "radio radio-inline" > < input type = "radio" value = "1" name = "version" id = "version-1" {if $sms['version'] == 1 || empty($sms['version'])}checked{/if}> < label for = "version-1" >旧版</ label > </ div > < div class = "radio radio-inline" > < input type = "radio" value = "2" name = "version" id = "version-2" {if $sms['version'] == 2}checked{/if}> < label for = "version-2" >新版(2017年6月之后申请的)</ label > </ div > < div class = "radio radio-inline" > < input type = "radio" value = "3" name = "version" id = "version-3" {if $sms['version'] == 3}checked{/if}> < label for = "version-3" >短信宝短信平台</ label > </ div > < span class = "help-block" >由于阿里大于接口调整,需要根据申请时间来区分支付接口</ span > </ div > </ div > < div class = "form-group" > < label class = "col-xs-12 col-sm-3 col-md-2 control-label" >短信宝用户名(AppKey)</ label > < div class = "col-sm-9 col-xs-12" > < input type = "text" class = "form-control" name = "key" value = "{$sms['key']}" > < span class = "help-block" >还没有短信账号? < a href = "http://www.smsbao.com/reg" target = "_blank" >现在去创建</ a >。 如果是新版接口,此处填写:Access Key ID</ span > </ div > </ div > < div class = "form-group" > < label class = "col-xs-12 col-sm-3 col-md-2 control-label" >短信宝密码(AppSecret)</ label > < div class = "col-sm-9 col-xs-12" > < input type = "text" class = "form-control" name = "secret" value = "{$sms['secret']}" > < span class = "help-block" >如果是新版接口,此处填写:Access Key Secret</ 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 = "sign" value = "{$sms['sign']}" > < span class = "help-block" >请填写短信签名.</ span > </ div > </ div > < div class = "form-group" > < div class = "col-sm-9 col-xs-9 col-md-9" > < input type = "hidden" name = "token" value = "{$_W['token']}" > < input type = "submit" value = "提交" class = "btn btn-primary" > </ div > </ div > </ form > </ div > {/if} {if $op == 'template'} < div class = "page clearfix" > < h2 >{$_W['page']['title']}</ h2 > < form class = "form-horizontal form form-validate" id = "form1" action = "" method = "post" enctype = "multipart/form-data" > < 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 = "verify_code_tpl" value = "{$sms['verify_code_tpl']}" required = "true" > < span class = "help-block" >< a href = "http://www.smsbao.com" target = "_blank" >联系短信宝客服</ a >报备模板后到达速度更快</ span > < span class = "help-block" > < strong class = "text-danger" > 模板名称: 通用验证码< br > 模板详情: 验证码code,您正在使用***平台(注意:这里改成你自己的平台),需要进行验证,15分钟内有效,打死也不能告诉别人哦 </ strong > </ span > </ div > </ div > < div class = "form-group" > < div class = "col-sm-9 col-xs-9 col-md-9" > < input type = "hidden" name = "token" value = "{$_W['token']}" > < input type = "submit" value = "提交" class = "btn btn-primary" > </ div > </ div > </ form > </ div > {/if} {itemplate 'public/footer'} |
最后打开项目:\model\sms.mod.php 文件,替换sms_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
function sms_send( $type , $mobile , $content , $sid = 0) { 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, '平台已关闭短信功能' ); } if ( $config_sms [ 'set' ][ 'version' ] == 2) { date_default_timezone_set( 'GMT' ); $post = array ( 'PhoneNumbers' => $mobile , 'SignName' => $config_sms [ 'set' ][ 'sign' ], 'TemplateCode' => trim( $type ), 'TemplateParam' => json_encode( $content ), 'OutId' => '' , 'RegionId' => 'cn-hangzhou' , 'AccessKeyId' => $config_sms [ 'set' ][ 'key' ], 'Format' => 'json' , 'SignatureMethod' => 'HMAC-SHA1' , 'SignatureVersion' => '1.0' , 'SignatureNonce' => uniqid(), 'Timestamp' => date ( 'Y-m-d\\TH:i:s\\Z' ), 'Action' => 'SendSms' , 'Version' => '2017-05-25' ); ksort( $post ); $str = '' ; foreach ( $post as $key => $value ) { $str .= '&' . percentencode( $key ) . '=' . percentencode( $value ); } $stringToSign = 'GET' . '&%2F&' . percentencode( substr ( $str , 1)); $signature = base64_encode (hash_hmac( 'sha1' , $stringToSign , $config_sms [ 'set' ][ 'secret' ] . '&' , true)); $post [ 'Signature' ] = $signature ; $url = '' . http_build_query( $post ); $result = ihttp_get( $url ); if (is_error( $result )) { return $result ; } $result = @json_decode( $result [ 'content' ], true); if ( $result [ 'Code' ] != 'OK' ) { return error(-1, $result [ 'Message' ]); } } elseif ( $config_sms [ 'set' ][ 'version' ] == 1){ $post = array ( 'method' => 'alibaba.aliqin.fc.sms.num.send' , 'app_key' => $config_sms [ 'set' ][ 'key' ], 'timestamp' => date ( 'Y-m-d H:i:s' ), 'format' => 'json' , 'v' => '2.0' , 'sign_method' => 'md5' , 'sms_type' => 'normal' , 'sms_free_sign_name' => $config_sms [ 'set' ][ 'sign' ], 'rec_num' => $mobile , 'sms_template_code' => trim( $type ), 'sms_param' => json_encode( $content )); ksort( $post ); $str = '' ; foreach ( $post as $key => $val ) { $str .= $key . $val ; } $secret = $config_sms [ 'set' ][ 'secret' ]; $post [ 'sign' ] = strtoupper (md5( $secret . $str . $secret )); $query = '' ; foreach ( $post as $key => $val ) { $query .= $key . '=' . urlencode( $val ) . '&' ; } $query = substr ( $query , 0, -1); $url = ' ' . $query ; $result = ihttp_get( $url ); if (is_error( $result )) { return $result ; } $result = @json_decode( $result [ 'content' ], true); if (! empty ( $result [ 'error_response' ])) { if (isset( $result [ 'error_response' ][ 'sub_code' ])) { $msg = sms_error_code( $result [ 'error_response' ][ 'sub_code' ]); if ( empty ( $msg )) { $msg [ 'msg' ] = $result [ 'error_response' ][ 'sub_msg' ]; } } else { $msg [ 'msg' ] = $result [ 'error_response' ][ 'msg' ]; } return error(-1, $msg [ 'msg' ]); } } else { $tpl = str_replace ( array_keys ( $content ), array_values ( $content ), $type ); $url = 'http://api.smsbao.com/sms?u=' . $config_sms [ 'set' ][ 'key' ]. '&p=' .md5( $config_sms [ 'set' ][ 'secret' ]). '&m=' . $mobile . '&c=【' . $config_sms [ 'set' ][ 'sign' ]. '】' . $tpl ; $result = file_get_contents ( $url ); if ( $result == '0' ) { return true; } else { return false; } } return true; } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的啦啦外卖跑腿系统短信宝插件,点击此链接 下载及查看安装流程
最新更新
电商类
CMS类
微信类