SparkShop(星火商城)是基于thinkphp6 + elementui的开源免费可商用的高性能商城系统;包含小程序商城、H5商城、公众号商城、PC商城、App,支持页面diy、秒杀、优惠券、积分、分销、会员等级。营销功能采用插件化的方式方便扩展、二次开发没系统大小任意控制。小编带着大家一起开发SparkShopV1.1.8的短信宝插件接口。我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
1.首先打开项目\app\admin\view\default\system 目录,替换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
|
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < title >短信配置</ title > < link rel = "stylesheet" href = "{__CSS__}/element_ui.css" /> < link rel = "stylesheet" href = "{__CSS__}/style.css" /> < script src = "{__JS__}/vue2.js" ></ script > < script src = "{__JS__}/element_ui.js" ></ script > < script src = "{__JS__}/axios.min.js" ></ script > < script src = "{__JS__}/request.js" ></ script > </ head > < body > < div id = "app" > < div class = "app-loading" v-if = "pageLoading" > < div class = "app-loading__logo" > < img src = "{__IMG__}/logo.png" /> </ div > < div class = "app-loading__loader" ></ div > < div class = "app-loading__title" >{$title}</ div > </ div > < el-card class = "box-card" v-else> < div slot = "header" class = "clearfix" > < span >短信配置</ span > </ div > < el-tabs v-model = "activeName" > < el-tab-pane label = "短信配置" name = "first" > < el-form ref = "form" :model = "form" label-width = "120px" > < el-form-item label = "短信宝账号" > < el-input v-model = "form.access_key_id" style = "width: 500px" ></ el-input > </ el-form-item > < el-form-item label = "短信API Key" > < el-input v-model = "form.access_key_secret" style = "width: 500px" ></ el-input > </ el-form-item > < el-form-item label = "短信签名" > < el-input v-model = "form.sign_name" style = "width: 500px" ></ el-input > </ el-form-item > < el-form-item > < el-button type = "primary" @ click = "save" >立即保存</ el-button > </ el-form-item > </ el-form > < div style = "margin-top: 30px;font-size: 13px" >* 还没注册 "短信宝"? < a href = "https://console.smsbao.com/#/register" target = "_blank" style = "color: red" > 点击此处去注册。 </ a ></ div > </ el-tab-pane > < el-tab-pane label = "模板设置" name = "second" > < el-form ref = "form" :model = "form" label-width = "150px" > < el-form-item label = "通用模板" > < el-input v-model = "form.com_sms_code" style = "width: 500px" ></ el-input > < span >示例:您的验证码为: {code},如非本人操作,请忽略本短信</ span > </ el-form-item > < el-form-item label = "用户登录模板" > < el-input v-model = "form.login_sms_code" style = "width: 500px" ></ el-input > </ el-form-item > < el-form-item label = "用户注册模板" > < el-input v-model = "form.reg_sms_code" style = "width: 500px" ></ el-input > </ el-form-item > < el-form-item label = "密码找回模板" > < el-input v-model = "form.forget_sms_code" style = "width: 500px" ></ el-input > </ el-form-item > < el-form-item label = "手机号码绑定模板" > < el-input v-model = "form.bind_sms_code" style = "width: 500px" ></ el-input > </ el-form-item > < el-form-item > < el-button type = "primary" @ click = "save" >立即保存</ el-button > </ el-form-item > </ el-form > </ el-tab-pane > </ el-tabs > </ el-card > </ div > < script > new Vue({ el: '#app', data: function () { return { pageLoading: true, form: {}, baseIndex: '/{:config("shop.backend_index")}/', activeName: 'first' } }, mounted() { this.pageLoading = false this.getBaseInfo() }, methods: { async getBaseInfo() { let res = await request.get(this.baseIndex + 'system/sms') this.form = res.data }, async save() { let res = await request.post(this.baseIndex + 'system/sms', this.form) if (res.code == 0) { this.$message.success('保存成功') } else { this.$message.error(res.msg) } } } }) </ script > < style > a {text-decoration:none;} </ style > </ body > </ html > |
2.接着打开项目\sparkshop\extend\utils\SparkTools.php 文件,替换68行代码:
1
|
$smsProvider = new SmsProvider( 'smsbao' ); |
3.接着打开项目\sparkshop\extend\strategy\sms\impl目录,新增SmsbaoSmsImpl.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
|
<?php namespace strategy\sms\impl; use Darabonba\OpenApi\Models\Config; use strategy\sms\SmsInterface; use think\facade\Log; class SmsbaoSmsImpl implements SmsInterface { private $statusStr = array( "0" => "短信发送成功" , "-1" => "参数不全" , "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!" , "30" => "密码错误" , "40" => "账号不存在" , "41" => "余额不足" , "42" => "帐户已过期" , "43" => "IP地址限制" , "50" => "内容含有敏感词" , "51" => "手机号码不正确" ); private function curl_get($sendurl){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $sendurl); curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER[ "HTTP_USER_AGENT" ]); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); $result = curl_exec($ch); curl_close($ch); return $result; } public function send($param) { try { $user = $param[ "accessKeyId" ]; $apikey = $param[ "accessKeySecret" ]; $codeStr = $param[ "code" ]; $codeData = json_decode($codeStr, true ); $TemplateContent = str_replace( '{code}' , $codeData[ 'code' ], $param[ "templateCode" ]); $content = '【' .$param[ "signName" ]. '】' .$TemplateContent; $sendurl = $ this ->sendUrl. "u=" .$user. "&p=" .$apikey. "&m=" .$param[ "phone" ]. "&c=" .urlencode($content); $result = $ this ->curl_get($sendurl); if ($result == 0) { return dataReturn(0, '发送成功' ); } else { return dataReturn(-1, '发送失败:' .$ this ->statusStr[$result]); } } catch (\Exception $error) { Log::error( "短信失败:" . $error->getMessage()); return dataReturn(-1, '发送失败' ); } return dataReturn(0, '发送成功' ); } } |
4.接着打开项目\extend\strategy\sms\SmsProvider.php 文件,引入SmsbaoSmsImpl类并在25行左右增加以下代码:
1
2
3
|
if ($type == 'smsbao' ) { $ this ->strategy = new SmsbaoSmsImpl(); } |
好了经过以上的添加,短信宝的短信平台已经替换成功了,可以正常使用了
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的SparkShop商城系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类