逍遥商城是一个以PHP+MySQL进行开发的开源B2C商城。在广大站长里面挺受喜爱,小编对他还是很了解,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是V1.1.1版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
1:打开项目:\admin\template\setting_sms.html 大概在10行修改为短信宝短信页面
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
|
<div class= "right" > <!--{include(pe_tpl( 'setting_menu.html' , 'admin' ));}--> <div class= "right_main" > <div class= "tixing corg" > <p>短信使用的是短信宝,可以先注册一个短信宝的帐号<a href= "http://smsbao.com/reg" class= "cblue" target= "_blank" >申请帐号</a></p> </div> <form method= "post" id= "form" > <table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" class= "wenzhang mat20 mab20" > <tr> <td align= "right" width= "150" >短信宝账号:</td> <td><input type= "text" name= "info[sms_key]" value= "{$info['sms_key']['setting_value']}" class= "inputall input300" /></td> </tr> <tr> <td align= "right" width= "150" >短信宝密码:</td> <td><input type= "text" name= "info[sms_secret]" value= "{$info['sms_secret']['setting_value']}" class= "inputall input300" /></td> </tr> <tr> <td align= "right" >短信宝签名:</td> <td><input type= "text" name= "info[sms_sign]" value= "{$info['sms_sign']['setting_value']}" class= "inputall input300" /> <span class= "c999" >(例:逍遥商城 要与短信宝中的签名保持一致哦)</span></td> </tr> <tr> <td align= "right" >管理员手机号:</td> <td> <input type= "text" name= "info[sms_admin]" value= "{$info['sms_admin']['setting_value']}" class= "inputall input300" /> </td> </tr> <tr> <td></td> <td> <input type= "hidden" name= "pesubmit" /> <input type= "hidden" name= "pe_token" value= "{$pe_token}" /> <input type= "submit" value= "提 交" class= "tjbtn" /> </td> </tr> </table> </form> </div> |
2:打开项目:\hook\notice.hook.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
|
if ($notice[ 'user' ][ 'notice_sms_state' ] && $info[ 'user_phone' ]) { $info_list[ 'noticelog_type' ] = 'sms' ; $info_list[ 'noticelog_user' ] = $info[ 'user_phone' ]; $info_list[ 'noticelog_name' ] = '' ; $info_list[ 'noticelog_text' ] = "【{$cache_setting['sms_sign']}】" .notice_tag_replace($notice[ 'user' ][ 'notice_sms_text' ], $info); $info_list[ 'noticelog_atime' ] = time(); if (isset($_SESSION[ 'sms_param' ])){ $sms_param = "{" .rtrim($_SESSION[ 'sms_param' ], "," ). "}" ; if (qunfa_sms($info[ 'user_phone' ],$sms_param,$notice[ 'user' ][ 'notice_sms_text' ])){ $info_list[ 'noticelog_state' ] = 'success' ; } else { $info_list[ 'noticelog_state' ] = 'fail' ; } unset($_SESSION[ 'sms_param' ]); } $sql_set[] = pe_dbhold($info_list); } //发送管理员短信通知 if ($notice[ 'admin' ][ 'notice_sms_state' ] && $cache_setting[ 'sms_admin' ]) { foreach (explode( ',' , $cache_setting[ 'sms_admin' ]) as $v) { $info_list[ 'noticelog_type' ] = 'sms' ; $info_list[ 'noticelog_user' ] = $v; $info_list[ 'noticelog_name' ] = '' ; $info_list[ 'noticelog_text' ] = "【{$cache_setting['sms_sign']}】" .notice_tag_replace($notice[ 'admin' ][ 'notice_sms_text' ], $info); $info_list[ 'noticelog_atime' ] = time(); if (isset($_SESSION[ 'sms_param' ])){ $sms_param = '{' .rtrim($_SESSION[ 'sms_param' ], "," ). '}' ; if (qunfa_sms($cache_setting[ 'sms_admin' ],$sms_param,$notice[ 'admin' ][ 'notice_sms_text' ])){ $info_list[ 'noticelog_state' ] = 'success' ; } else { $info_list[ 'noticelog_state' ] = 'fail' ; } unset($_SESSION[ 'sms_param' ]); } $sql_set[] = pe_dbhold($info_list); } } if (is_array($sql_set)) $db->pe_insert( 'noticelog' , $sql_set); add_wechat_noticelog($user_id, $type, $info); } function remove_quote(&$str) { if (preg_match( "/^\'/" ,$str)){ $str = substr($str, 1, strlen($str) - 1); } //判断字符串是否以'"'结束 if (preg_match("/\'$/",$str)){ $str = substr($str, 0, strlen($str) - 1);; } return $str; } |
3:打开项目:\hook\qunfa.hook.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
|
function qunfa_sms($phone, $text, $templateid= null , $qunfa_id = 0) { global $db, $cache_setting; if ($templateid == null ){ $content = $text; } else { $sms_param = trim($text, "}" ); $sms_param = trim($sms_param, "{" ); $tpl = $templateid; $arr = explode( ',' ,$sms_param); foreach ($arr as $v) { $key = explode( ':' ,$v); $str = remove_quote($key[1]); $tpl=str_replace( '${' .$key[0]. '}' ,$str,$tpl); } $content = '【' .$cache_setting[ 'sms_sign' ]. '】' .$tpl; } $user = $cache_setting[ 'sms_key' ]; //短信平台帐号 $pass = md5($cache_setting[ 'sms_secret' ]); //短信平台密码 $content = $content; //要发送的短信内容 $phone = $phone; //要发送短信的手机号码 $sendurl = $smsapi. "sms?u=" .$user. "&p=" .$pass. "&m=" .$phone. "&c=" .urlencode($content); $result =file_get_contents($sendurl); if ($result == 0){ return array( 'result' => true , 'show' => '发送成功' ); } else { return array( 'result' => false , 'show' => '发送失败' ); } } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的逍遥商城V1.1.1系统系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类