• 4001-021-502
您的位置:短信宝 > 技术分享 > PHPSHE商城新增短信宝短信接口
PHPSHE商城新增短信宝短信接口
发表日期:2018-09-12    文章编辑:短信宝小编    浏览次数:

今天小编为大家更新phpshe商城系统1.7版本的短信插件,之前的版本插件已不能使用。下面带着大家一起进行新版本的替换,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。

首先我们打开项目\template\default\admin\setting_sms.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
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
<!--{include(pe_tpl('header.html'));}-->
<div class="right">
 <!--{include(pe_tpl('setting_menu.html'));}-->
 <div class="right_main">
  <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" /> 还没有账号? <a href="http://www.smsbao.com/reg" style="color: red;">请点击注册</a></td>
  </tr>
  <tr>
   <td align="right" width="150">短信宝密码:</td>
   <td><input type="text" name="info[sms_password]" value="{$info['sms_password']['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" />
    <a href="javascript:;" class="admin_btn mal10" id="sms_test" />发送测试短信</a>
    <span class="c888">(用于接收订单通知,多个用“,”隔开)</span
   </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>
 <div class="now">
  <a href="javascript:;" class="sel">短信通知<i></i></a>
 </div>
 <!--{foreach(array('user'=>'会员', 'admin'=>'管理员') as $user_type=>$user_name):}-->
 <div class="right_main">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="list">
  <tr>
   <th class="bgtt" width="50">序号</th>
   <th class="bgtt" width="">通知类型</th>
   <th class="bgtt" width="250">通知用户</th>
   <th class="bgtt" width="250">通知模板</th>
   <th class="bgtt" width="250">启用状态</th>
  </tr>
  <!--{$num=1}-->
  <!--{foreach($notice_list[$user_type] as $k=>$v):}-->
  <tr>
   <td>{$num++}</td>
   <td>{$v['notice_name']}</td>
   <td>{$user_name}</td>
   <td>
    <a href="admin.php?mod=notice&act=edit&type=sms&id={$v['notice_id']}" class="admin_edit" onclick="return pe_dialog(this, '修改短信模板', 850, 500, 'notice')">编辑</a>
   </td>
   <td class="layui-form">
    <input type="checkbox" <!--{if($v['notice_sms_state']):}-->checked<!--{endif;}--> lay-skin="switch" lay-text="开启|关闭" url="admin.php?mod=notice&act=sms_state&id={$v['notice_id']}&token={$pe_token}" />
   </td>
  </tr>
  <!--{endforeach;}-->
  </table>
 </div>
 <!--{endforeach;}-->
</div>
<link rel="stylesheet" href="{$pe['host_root']}include/plugin/layui/css/layui.css">
<script src="{$pe['host_root']}include/plugin/layui/layui.js"></script>
<script type="text/javascript">
$(function(){
 $("#sms_test").click(function(){
  $(this).attr("href", "admin.php?mod=setting&act=sms_test&user="+$(":input[name='info[sms_admin]']").val()+"&token={$pe_token}");
 })
})
layui.use(['form'], function(){
 form = layui.form;
 form.on('switch', function(data){
  var url = $(this).attr("url") + "&value=" + (this.checked ? 1 : 0)
  pe_getinfo(url);
 });
});
</script>
<!--{include(pe_tpl('footer.html'));}-->

接着我们打开项目\module\admin\setting.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/**
 
 
 */
$menumark 'setting';
pe_lead('hook/cache.hook.php');
switch ($act) {
 //####################// 积分设置 //####################//
 case 'point':
  if (isset($_p_pesubmit)) {
   pe_token_match();
   $sql "update `".dbpre."setting` set `setting_value` = case `setting_key`
    when 'point_state' then '".pe_dbhold($_p_info['point_state'])."'
    when 'point_money' then '".pe_dbhold($_p_info['point_money'])."'
    when 'point_reg' then '".pe_dbhold($_p_info['point_reg'])."'
    when 'point_login' then '".pe_dbhold($_p_info['point_login'])."'
    when 'point_comment' then '".pe_dbhold($_p_info['point_comment'])."' else `setting_value` end";
   if ($db->sql_update($sql)) {
    cache_write('setting');
    pe_success('设置成功!');
   }
   else {
    pe_error('设置失败...');
   }
  }
  $info $db->index('setting_key')->pe_selectall('setting');  
  $seo = pe_seo($menutitle='积分设置''''''admin');
  include(pe_tpl('setting_point.html'));  
 break;
 //####################// 短信设置 //####################//
 case 'sms':
  if (isset($_p_pesubmit)) {
   pe_token_match();
   $sql "update `".dbpre."setting` set `setting_value` = case `setting_key`
    when 'sms_key' then '".pe_dbhold($_p_info['sms_key'])."'
    when 'sms_password' then '".pe_dbhold($_p_info['sms_password'])."'
    when 'sms_sign' then '".pe_dbhold($_p_info['sms_sign'])."'
    when 'sms_admin' then '".pe_dbhold($_p_info['sms_admin'])."' else `setting_value` end";
   if ($db->sql_update($sql)) {
    cache_write('setting');
    pe_success('设置成功!');
   }
   else {
    pe_error('设置失败...');
   }
  }
  $info $db->index('setting_key')->pe_selectall('setting'); 
  $notice_list $db->index('notice_obj|notice_type')->pe_selectall('notice');
  $seo = pe_seo($menutitle='短信设置''''''admin');
  include(pe_tpl('setting_sms.html'));
 break;
 //####################// 短信测试 //####################//
 case 'sms_test':
  pe_token_match();
  if (!$_g_user) pe_error('管理员手机号未填写...');
  foreach (explode(','$_g_useras $k=>$v) {
   if (!$vcontinue;
   $sql_set[$k]['noticelog_type'] = 'sms';
   $sql_set[$k]['noticelog_user'] = pe_dbhold($v);
   $sql_set[$k]['noticelog_name'] = '';
   $sql_set[$k]['noticelog_text'] = "尊敬的用户:您好,这是一条测试短信";
   $sql_set[$k]['noticelog_atime'] = time();   
  }
  if ($db->pe_insert('noticelog'$sql_set)) {
   pe_success('发送成功!');
  }
  else {
   pe_error('发送失败...');
  }
 break;
 //####################// 邮箱设置 //####################//
 case 'email':
  if (isset($_p_pesubmit)) {
   pe_token_match();
   $sql "update `".dbpre."setting` set `setting_value` = case `setting_key`
    when 'email_smtp' then '".pe_dbhold($_p_info['email_smtp'])."'
    when 'email_ssl' then '".pe_dbhold($_p_info['email_ssl'])."'
    when 'email_port' then '".pe_dbhold($_p_info['email_port'])."'
    when 'email_name' then '".pe_dbhold($_p_info['email_name'])."'
    when 'email_pw' then '".pe_dbhold($_p_info['email_pw'])."'
    when 'email_nname' then '".pe_dbhold($_p_info['email_nname'])."'
    when 'email_admin' then '".pe_dbhold($_p_info['email_admin'])."' else `setting_value` end";
   if ($db->sql_update($sql)) {
    cache_write('setting');
    pe_success('设置成功!');
   }
   else {
    pe_error('设置失败...');
   }
  }
  $info $db->index('setting_key')->pe_selectall('setting');
  $notice_list $db->index('notice_obj|notice_type')->pe_selectall('notice');   
  $seo = pe_seo($menutitle='邮箱设置''''''admin');
  include(pe_tpl('setting_email.html'));  
 break;
 //####################// 邮件测试 //####################//
 case 'email_test':
  pe_token_match();
  if (!$_g_user) pe_error('管理员邮箱未填写...');
  foreach (explode(','$_g_useras $k=>$v) {
   if (!$vcontinue;
   $sql_set[$k]['noticelog_type'] = 'email';
   $sql_set[$k]['noticelog_user'] = pe_dbhold($v);
   $sql_set[$k]['noticelog_name'] = 'PHPSHE商城系统测试邮件';
   $sql_set[$k]['noticelog_text'] = '尊敬的用户:您好,欢迎使用简好网络旗下软件 - PHPSHE商城系统<br/><br/>简好网络官网:http://www.phpshe.com<br/><br/>邮件发送日期:'.pe_date(time());
   $sql_set[$k]['noticelog_atime'] = time();   
  }
  if ($db->pe_insert('noticelog'$sql_set)) {
   pe_success('发送成功!');
  }
  else {
   pe_error('发送失败...');
  
 break;
 //####################// 会员设置 //####################//
 case 'user':
  if (isset($_p_pesubmit)) {
   pe_token_match();
   if ($_p_info['cashout_min'] <= 0) $_p_info['cashout_min'] = 0.1;
   $sql "update `".dbpre."setting` set `setting_value` = case `setting_key`
    when 'web_guestbuy' then '".intval($_p_info['web_guestbuy'])."'
    when 'web_checkphone' then '".intval($_p_info['web_checkphone'])."'
    when 'web_checkemail' then '".intval($_p_info['web_checkemail'])."'
    when 'cashout_min' then '".round($_p_info['cashout_min'], 1)."'
    when 'cashout_fee' then '".(round($_p_info['cashout_fee'], 2)/100)."'
    when 'tg_state' then '".intval($_p_info['tg_state'])."'
    when 'tg_fc1' then '".(round($_p_info['tg_fc1'], 2)/100)."'
    when 'tg_fc2' then '".(round($_p_info['tg_fc2'], 2)/100)."'
    when 'tg_fc3' then '".(round($_p_info['tg_fc3'], 2)/100)."' else `setting_value` end";
   if ($db->sql_update($sql)) {
    cache_write('setting');
    pe_success('设置成功!');
   }
   else {
    pe_error('设置失败...');
   }
  }
  $info $db->index('setting_key')->pe_selectall('setting');
  $seo = pe_seo($menutitle='会员设置''''''admin');
  include(pe_tpl('setting_user.html'));
 break;
 //####################// 网站设置 //####################//
 default:
  if (isset($_p_pesubmit)) {
   pe_token_match();
   if ($_FILES['web_logo']['size']) {
    pe_lead('include/class/upload.class.php');
    $upload new upload($_FILES['web_logo']);
    $_p_info['web_logo'] = $upload->filehost;
    $sqlset .= "when 'web_logo' then '{$upload->filehost}'";
   }
   if ($_FILES['wap_logo']['size']) {
    pe_lead('include/class/upload.class.php');
    $upload new upload($_FILES['wap_logo']);
    $_p_info['wap_logo'] = $upload->filehost;
    $sqlset .= "when 'wap_logo' then '{$upload->filehost}'";
   }
   if ($_FILES['web_qrcode']['size']) {
    pe_lead('include/class/upload.class.php');
    $upload new upload($_FILES['web_qrcode']);
    $_p_info['web_qrcode'] = $upload->filehost;
    $sqlset .= "when 'web_qrcode' then '{$upload->filehost}'";
   }
   $sql "update `".dbpre."setting` set `setting_value` = case `setting_key` {$sqlset}
    when 'web_title' then '".pe_dbhold($_p_info['web_title'])."'
    when 'web_keywords' then '".pe_dbhold($_p_info['web_keywords'])."'
    when 'web_description' then '".pe_dbhold($_p_info['web_description'])."'
    when 'web_copyright' then '".pe_dbhold($_p_info['web_copyright'])."'
    when 'web_icp' then '".pe_dbhold($_p_info['web_icp'])."'
    when 'web_phone' then '".pe_dbhold($_p_info['web_phone'])."'
    when 'web_qq' then '".pe_dbhold($_p_info['web_qq'])."'
    when 'web_hotword' then '".pe_dbhold($_p_info['web_hotword'])."'
    when 'web_wlname' then '".pe_dbhold($_p_info['web_wlname'])."'
    when 'web_tongji' then '".pe_dbhold($_p_info['web_tongji'], 'all')."' else `setting_value` end";
   if ($db->sql_update($sql)) {
    cache_write('setting');
    pe_success('设置成功!');
   }
   else {
    pe_error('设置失败...');
   }
  
  $info $db->index('setting_key')->pe_selectall('setting');
  $seo = pe_seo($menutitle='网站设置''''''admin');
  include(pe_tpl('setting_base.html'));
 break;
}
?>

接着我们打开项目\hook\qunfa.hook.php文件,替换qunfa_sms方法:

?
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
function qunfa_sms($phone$text$qunfa_id = 0) {
 global $db$cache_setting;
 
  $url 'http://api.smsbao.com/sms?u='.$cache_setting['sms_key'].'&p='.md5($cache_setting['sms_password']).'&m='.$phone.'&c=【'.$cache_setting['sms_sign'].'】'.$text;
  $result file_get_contents($url);
 
 //更新或插入发送日志
 $sql_set['noticelog_stime'] = time();
 if ($result == 0) {
  $results['result'] = true;
  $results['show'] = '发送成功';
  $sql_set['noticelog_state'] = 'success';   
 }
 else {
  $sql_set['noticelog_state'] = 'fail';   
  $sql_set['noticelog_error'] = $result;
 }
 if ($qunfa_id) {
  $db->pe_update('noticelog'array('noticelog_id'=>$qunfa_id), pe_dbhold($sql_set));
 }
 else {
  $sql_set['noticelog_type'] = 'sms';
  $sql_set['noticelog_user'] = $phone;   
  $sql_set['noticelog_name'] = '';
  $sql_set['noticelog_text'] = $text;
  $sql_set['noticelog_atime'] = time();
  $db->pe_insert('noticelog', pe_dbhold($sql_set));
 }
 return $results;
}

最后我们在项目的根目录下创建smsbao.php文件,代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
<?php
 
/**
 * Smsbao.php
 * 短信宝插件安装,增加密码字段
 */
include('./common.php');
$sql_set['setting_key'] = 'sms_password'
$sql_set['setting_value'] = ''
$db->pe_insert('setting',$sql_set);
echo '短信宝插件安装成功,请删除smsbao.php文件';

经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。

另外:我们已经开发好完整的phpshe商城系统短信宝插件,点击此链接 下载及查看安装流程。

短信宝-做更好用的短信验证码短信营销短信群发服务平台。超过9,000个网站始终信任短信宝。通过稳定快捷的短信,短信宝帮助他们缩短了90%的人工服务处理时间,同时降低了81%由于通讯故障导致的废单率,一切变得轻松可控!

Copyright © 2010-2014 smsbao.com All Rights Reserved
上海子橙电子科技有限公司 沪ICP备14008182号-2 上海市松江区广富林路658弄215号

展开