ShopXO是国内领先的商城系统提供商,为企业提供php商城系统、微信商城、小程序。小编发现ShopXO更新到6.7.0版本,就以替换短信接口为例告诉大家如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。下面具体给大家说一下每个文件的作用及代码。
1.首先打开项目app\admin\lang\zh.php文件,替换配置短信信息,大约在552~554行左右,代码如下
|
1
2
3
|
'top_tips' => '短信宝管理地址','top_to_smsbao_tips' => '点击去短信宝购买短信', |
2:接着打开app\admin\view\default\sms\tips.html 替换购买短信按钮跳转链接配置
|
1
2
3
4
5
6
7
8
|
<div class="am-operate-stretch-tips"> <div class="title"> <i class="iconfont icon-tips"></i> <strong title="{{:MyLang('operate_list_tips_msg')}}">{{:MyLang('operate_list_tips_button_text')}}</strong> <i class="iconfont icon-retract-diagonal contract" title="{{:MyLang('operate_list_tips_retract_text')}}"></i> </div> <p class="am-text-xs">{{:MyLang('sms.top_tips')}} <a href="{{:MyLang('sms.top_to_smsbao_url')}}" class="am-margin-left-sm" target="_blank">{{:MyLang('sms.top_to_smsbao_tips')}} <i class="am-icon-external-link"></i></a> </p></div> |
3:接着打开app\lang\zh.php 替换短信日志平台的枚举类型添加及相关信息设置,替换common_sms_log_platform_list 、common_sms_apikey、common_sms_apisecret变量的属性
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
// 短信日志平台 'common_sms_log_platform_list' => [ 'smsbao' => '短信宝', ],'common_sms_apikey' => [ 'name' => '短信宝账号', 'desc' => '短信宝账号', 'tips' => '请填写短信宝账号', ],'common_sms_apisecret' => [ 'name' => '短信宝API key', 'desc' => '短信宝API key', 'tips' => '请填写短信宝API key', ], |
4:接着打开项目app\service\ConstService.php 替换短信日志平台的枚举类型配置
|
1
2
3
4
|
// 短信日志平台'common_sms_log_platform_list' => [ 'smsbao' => ['value' => 'smsbao', 'name' => MyLang('common_sms_log_platform_list.smsbao')], ], |
5:接着打开项目extend\base\Sms.php ,替换SmsRequest短信发送函数及GetErrorMessage 获取返回信息函数
|
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
|
public function SmsRequest($mobile, $template_value, $sign_name = '', $template_var = []) { // 签名 $sign_name = empty($sign_name) ? $this->sign_ame : $sign_name; // 短信发送钩子 $hook_name = 'plugins_extend_sms_send_request_handle'; $ret = array_filter(MyEventTrigger($hook_name, [ 'hook_name' => $hook_name, 'is_backend' => true, 'sign_name' => $sign_name, 'mobile' => $mobile, 'template_value' => $template_value, 'template_var' => $template_var, ])); // 存在返回值,并且存在code和mag参数,则认为是钩子处理短信的发送 if(!empty($ret)) { // 处理钩子数据 $ret = EventReturnHandle($ret); if($ret['code'] != 0) { $this->error = $ret['msg']; return false; } return true; } // 请求参数 $request_params = [ 'SignName' => $sign_name, 'Format' => 'JSON', 'Version' => '2017-05-25', 'AccessKeyId' => $this->access_key_id, 'SignatureVersion' => '1.0', 'SignatureMethod' => 'HMAC-SHA1', 'SignatureNonce' => uniqid(), 'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'), 'Action' => 'SendSms', 'TemplateCode' => $template_value, 'PhoneNumbers' => $mobile, ]; // 携带参数 if(!empty($template_var)) { if(!is_array($template_var)) { $template_var = ['code'=>$template_var]; } $request_params['SmsContent'] = str_replace('{code}',$template_var['code'],$template_value); } $url = $request_url.'?u='.$this->access_key_id.'&p='.$this->access_key_secret.'&m='.$mobile.'&c=【'.$sign_name.'】'.$request_params['SmsContent']; // 添加短信日志 if($this->is_log == 1) { $log = SmsLogService::SmsLogAdd('smsbao', $mobile, $sign_name, $template_value, $template_var, $request_url, $request_params); if($log['code'] != 0) { $this->error = $log['msg']; return false; } } // 远程请求 $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 ); if($result == '0') { // 日志回调 if($this->is_log == 1) { SmsLogService::SmsLogResponse($log['data']['id'], 1, $result, time()-$log['data']['add_time']); } return true; } // 错误原因 $this->error = $this->GetErrorMessage($result); // 日志回调 if($this->is_log == 1) { SmsLogService::SmsLogResponse($log['data']['id'], 2, $result, time()-$log['data']['add_time'], $this->error); } return false; }public function GetErrorMessage($status) { // 阿里云的短信 乱八七糟的(其实是用的阿里大于) $message = [ "0" => "短信发送成功", "-1" => "参数不全", "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!", "30" => "密码错误", "40" => "账号不存在", "41" => "余额不足", "42" => "帐户已过期", "43" => "IP地址限制", "50" => "内容含有敏感词" ]; if(isset($message[$status])) { return $message[$status]; } return $status; } |
好了经过以上的添加,短信宝的短信平台已经替换成功了,可以正常使用了

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的ShopXO系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类