Jshop小程序商城,是一款开源的电商系统,包含微信小程序、支付宝小程序、APP、公众号和H5端,为大中小企业提供移动电子商务优秀的解决方案。小编对他还是比较了解的,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是v2.05版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
打开项目:\addons 新增一个Smsbao文件夹
打开项目:\addons\Smsbao 新增一个config.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
|
<form class = "layui-form" action= "#" method= "post" > <div style= "padding: 30px;" class = "layui-form layui-form-pane" > <div class = "layui-tab-content" > <div class = "layui-form-item" > <label class = "layui-form-label" >短信宝账号:</label> <div class = "layui-input-block" > <input type= "text" name= "setting[sms_account]" required lay-verify= "required" placeholder= "" autocomplete= "off" value= "{$config.sms_account}" class = "layui-input" > </div> <label class = "layui-input-block" >还没有注册账号<a target= "_blank" style= "color: red" href= "http://www.smsbao.com/reg" >立即注册</a></label> </div> </div> <div class = "layui-tab-content" > <div class = "layui-form-item" > <label class = "layui-form-label" >短信宝密码:</label> <div class = "layui-input-block" > <input type= "text" name= "setting[sms_password]" required lay-verify= "required" placeholder= "" autocomplete= "off" value= "{$config.sms_password}" class = "layui-input" > </div> </div> </div> <div class = "layui-tab-content" > <div class = "layui-form-item" > <label class = "layui-form-label" >短信宝签名:</label> <div class = "layui-input-block" > <input type= "text" name= "setting[sms_prefix]" value= "{$config.sms_prefix}" required lay-verify= "required" placeholder= "" autocomplete= "off" class = "layui-input" > </div> </div> </div> <div class = "layui-tab-content" > </div> </div> <script> layui. use ( 'element' , function () { //监听提交 var $ = layui.jquery , element = layui.element; }); </script> </form> |
打开项目:\addons\Smsbao 新增一个config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<?php return [ 'sms_account' =>[ 'title' => '用户账号' , 'value' => '' , ], 'sms_password' =>[ 'title' => '用户密码' , 'value' => '' , ], 'sms_prefix' =>[ 'title' => '短信签名' , 'value' => 'jshop' , ] ]; |
打开项目:\addons\Smsbao 新增一个Smsbao.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
|
<?php namespace addons\Smsbao; // 注意命名空间规范 use myxland\addons\Addons; use app\common\model\Addons as addonsModel; /** * mms1086短信通道 */ class Smsbao extends Addons { // 该插件的基础信息 public $info = [ 'name' => 'Smsbao' , // 插件标识 'title' => 'Smsbao短信插件' , // 插件名称 'description' => 'Smsbao发送短信插件,请勿和其它短信通道一起使用' , // 插件简介 'status' => 0, // 状态 'author' => 'xiaole' , 'version' => '0.1' ]; /** * 插件安装方法 * @return bool */ public function install() { return true; } /** * 插件卸载方法 * @return bool */ public function uninstall() { return true; } /** * 实现的testhook钩子方法 * @return mixed */ public function sendsms( $params ) { $result = [ 'status' => false, 'data' => [], 'msg' => '发送失败' ]; $addonModel = new addonsModel(); $setting = $addonModel ->getSetting( $this ->info[ 'name' ]); if ( $params [ 'params' ][ 'code' ] == 'seller_order_notice' ) { $params [ 'params' ][ 'mobile' ] = getSetting( 'shop_mobile' ); if (! $params [ 'params' ][ 'mobile' ]) { $result [ 'msg' ] = '商户手机号不存在' ; return $result ; } } $sms_password = md5( $setting [ 'sms_password' ]); //为了演示效果,此密码从配置文件中取,如果正式使用,请删除此行,并在后台店铺设置里配置密码即可。 $content = '【' . $setting [ 'sms_prefix' ] . '】' . $params [ 'params' ][ 'content' ] ; //$content = iconv("utf-8","gb2312",$content); $content = urlencode( $content ); //内容 $str = $smsapi . "sms?u=" . $setting [ 'sms_account' ]. "&p=" . $sms_password . "&m=" . $params [ 'params' ][ 'mobile' ]. "&c=" . $content ; $re = file_get_contents ( $str ); if ( $re == 0){ $result [ 'msg' ] = '发送成功' ; $result [ 'status' ] = true; } else { $result [ 'msg' ] = '发送失败' ; $result [ 'status' ] = false; } return $result ; } public function config( $params = []) { $this ->assign( 'config' , $params ); return $this ->fetch( 'config' ); } } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的Jshopv2.05短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类