ShopXO是国内领先的商城系统提供商,为企业提供php商城系统、微信商城、小程序。小编发现ShopXO更新到2.3.3版本,就以替换短信接口为例告诉大家如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用
1:打开项目:\app\admin\view\default\sms\nav.html文件,替换以下代码
1
2
3
4
5
6
7
8
9
10
11
12
|
<ul class= "am-nav am-nav-pills table-nav m-b-10" > <li {{ if $nav_type eq 'sms' }}class= "am-active" {{/ if }} data-type= "sms" > <a href= "{{:MyUrl('admin/sms/index', ['type'=>'sms'])}}" >短信设置</a> </li> <li {{ if $nav_type eq 'message' }}class= "am-active" {{/ if }} data-type= "message" > <a href= "{{:MyUrl('admin/sms/index', ['type'=>'message'])}}" >消息模板</a> </li> </ul> <div class= "am-alert am-alert-warning am-radius" data-am-alert> <button type= "button" class= "am-close" >×</button> </div> |
2:打开项目:\app\admin\view\default\sms\index.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
|
{{include file= "public/header" /}} <!-- right content start --> <div class= "content-right" > <div class= "content" > <!-- table nav start --> {{include file= "sms/nav" " /}} <!-- table nav end --> <!-- form start --> <form class=" am-form form-validation view-save " action=" {{:MyUrl( 'admin/sms/save' )}} " method=" POST " request-type=" ajax-url " request-value=" {{:MyUrl( 'admin/sms/index' , [ 'type' => 'sms' ])}} "> <div class=" am-form-group "> <label>短信宝账号<span class=" am-form-group-label-tips ">填写短信宝账号</span></label> <input type=" text " name=" {{$data.common_sms_apikey.only_tag}} " placeholder=" {{$data.common_sms_apikey.name}} " data-validation-message=" {{$data.common_sms_apikey.error_tips}} " class=" am-radius " {{if !empty($data)}}value=" {{$data.common_sms_apikey.value}} "{{/if}} /> </div> <div class=" am-form-group "> <label>短信宝密码<span class=" am-form-group-label-tips ">填写短信宝密码</span></label> <input type=" text " name=" {{$data.common_sms_apisecret.only_tag}} " placeholder=" {{$data.common_sms_apisecret.name}} " data-validation-message=" {{$data.common_sms_apisecret.error_tips}} " class=" am-radius " {{if !empty($data)}}value=" {{$data.common_sms_apisecret.value}} "{{/if}} /> </div> <div class=" am-form-group "> <label>{{$data.common_sms_sign.name}}<span class=" am-form-group-label-tips ">{{$data.common_sms_sign.describe}}</span></label> <input type=" text " name=" {{$data.common_sms_sign.only_tag}} " placeholder=" {{$data.common_sms_sign.name}} " data-validation-message=" {{$data.common_sms_sign.error_tips}} " class=" am-radius " maxlength=" 16 " {{if !empty($data)}}value=" {{$data.common_sms_sign.value}} "{{/if}} /> </div> <div class=" am-form-group am-form-group-refreshing "> <button type=" submit " class=" am-btn am-btn-primary am-radius btn-loading-example am-btn-sm am-btn-block " data-am-loading=" {loadingText: '处理中...' } ">保存</button> </div> </form> <!-- form end --> </div> </div> <!-- right content end --> <!-- footer start --> {{include file=" public/footer" /}} <!-- footer end -- |
3:打开项目:\extend\base\Sms.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
|
public function SendCode($mobile, $code, $template_code, $sign_name = '' ) { // 单个验证码需要校验是否频繁 if (is_string($code)) { // 是否频繁操作 if (!$ this ->IntervalTimeCheck()) { $ this ->error = '防止造成骚扰,请勿频繁发送' ; return false ; } $codes = [ 'code' =>$code]; } else { $codes = $code; } $content = str_replace( 'code' ,$code,$template_code); $SignName = empty($sign_name) ? $ this ->signName : $sign_name; $url = 'http://api.smsbao.com/sms?u=' .$ this ->accessKeyId. '&p=' .md5($ this ->accessKeySecret). '&m=' .$mobile. '&c=【' .$SignName. '】' .$content; // 签名 // 请求参数 // $params = array ( //此处作了修改 // 'SignName' => $this->signName, // 'Format' => 'JSON', // 'Version' => '2017-05-25', // 'AccessKeyId' => $this->accessKeyId, // 'SignatureVersion' => '1.0', // 'SignatureMethod' => 'HMAC-SHA1', // 'SignatureNonce' => uniqid (), // 'Timestamp' => gmdate ( 'Y-m-d\TH:i:s\Z' ), // 'Action' => 'SendSms', // 'TemplateCode' => $template_code, // 'PhoneNumbers' => $mobile, // 'TemplateParam' => '{"code":"' . $code . '"}' // ); // //print_r($params);die; // // 计算签名并把签名结果加入请求参数 // $params ['Signature'] = $this->computeSignature ( $params, $this->accessKeySecret ); // 发送请求(此处作了修改) //$url = 'https://sms.aliyuncs.com/?' . http_build_query ( $params ); //$url = 'http://dysmsapi.aliyuncs.com/?' . http_build_query ( $params ); $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_TIMEOUT, 10 ); $result = curl_exec ( $ch ); curl_close ( $ch ); //$result = json_decode ( $result, true ); //print_r($result);//die; if ($result != 0) { $ this ->error = $result; return false ; } // 种session if (is_string($code)) { $ this ->KindofSession($code); } return true ; } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的ShopXO v2.3.3系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类