ShopXO是國內領先的商城系統提供商,為企業提供php商城系統、微信商城、小程序。小編發現ShopXO更新到6.5.0版本,就以替換短信接口為例告訴大家如何進行二次開發,使用的短信接口是我們短信寶短信群發平臺的接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
1:下面具體給大家說一下每個文件的作用及代碼,app\admin\lang\zh.php是插件的短信配置信息,代碼如下
1
2
3
4
5
6
7
8
9
10
11
12
13
|
// 短信設置 'sms' => [ // 基礎導航 'base_nav_list' => [ [ 'name' => '短信設置' , 'type' => 'index' ], [ 'name' => '消息模板' , 'type' => 'message' ], ], 'top_tips' => '短信寶管理地址' , 'top_to_smsbao_tips' => '點擊去短信寶購買短信' , 'base_item_admin_title' => '后臺' , 'base_item_index_title' => '前端' , ], |
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-contract 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 是短信日志平臺的枚舉類型添加及相關信息設置
1
2
3
4
5
6
7
8
9
|
// 短信日志平臺 'common_sms_log_platform_list' => [ 'smsbao' => '短信寶' , ], 'common_sms_apikey' => [ 'name' => '短信寶賬號' , 'desc' => '短信寶賬號' , 'tips' => '請填寫短信寶賬號' , ], |
4:app\service\ConstService.php 是短信日志平臺的枚舉類型配置
1
2
3
|
'common_sms_log_platform_list' => [ 'smsbao' => [ 'value' => 'smsbao' , 'name' => MyLang( 'common_sms_log_platform_list.smsbao' )], ], |
5: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
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
|
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, '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=' .md5($ 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 ; } |
好了經過以上的添加,短信寶的短信平臺已經替換成功了,可以正常使用了
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的ShopXOV6.5系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類