人人商城是一款针对的移动端购物消费的微信商城管理系统。它不仅能为您提供专业可靠的技术支持,还能完美适配企业商用。可添加多个公众号使用,具有强大的自定义功能,让您拥有个性化商城。本人对该系统还是比较熟悉的,今天我就来分享一下,如何进行二次开发。我以替换短信接口为例,一步一步的手把手教大家开发过程。
短信接口使用的是短信宝短信平台的短信接口,小伙伴一定会问为什么使用短信宝作为案例呢?原因很简单,因为短信宝的平台极其稳定,而且短信发送速度相当快捷,验证码和订单通知在3~5秒就能收到,用户体验非常好,所以我们公司一直和短信宝保持着合作关系,小伙伴们也可以去短信宝的官网(http://www.smsbao.com)注册一个账号,还有免费的短信条数送呢。
接下来我就说一下开发步骤:
1。先打开项目/core/com/sms.php文件,添加短信宝的发送接口代码:
<?php
if (!defined('IN_IA'))
{
exit('Access Denied');
}
class Sms_EweiShopV2ComModel extends ComModel
{
public function send($mobile, $tplid, $data, $replace = true)
{
global $_W;
$smsset = $this->sms_set();
$template = $this->sms_verify($tplid, $smsset);
if (empty($template['status']))
{
return $template;
}
$params = $this->sms_data($template['type'], $data, $replace, $template);
if ($template['type'] == 'juhe')
{
$data = array('mobile' => $mobile, 'tpl_id' => $template['smstplid'], 'tpl_value' => $params, 'key' => $smsset['juhe_key']);
$result = $this->http_post('http://v.juhe.cn/sms/send', $data);
if (empty($result) || (0 < $result['error_code']))
{
return array('status' => 0, 'message' => '短信发送失败(' . $result['error_code'] . '):' . $result['reason']);
}
}
if ($template['type'] == 'smsbao') {
$results = array(
'30' => '密码错误',
'40' => '账号不存在',
'41' => '余额不足',
'42' => '帐号过期',
'43' => 'IP地址限制',
'50' => '内容含有敏感词',
'51' => '手机号码不正确'
);
$url = 'http://api.smsbao.com/sms?u='.$smsset['smsbao_key'].'&p='.md5($smsset['smsbao_secret']).'&m='.$mobile.'&c='.'【'.$smsset['smsbao_sign'].'】'.$params;
$res = file_get_contents($url);
if ($res != 0) {
return array('status' => $res, 'message' => $results[$res]);
}
}
if ($template['type'] == 'dayu')
{
include_once EWEI_SHOPV2_VENDOR . 'dayu/TopSdk.php';
$dayuClient = new TopClient();
$dayuClient->appkey = $smsset['dayu_key'];
$dayuClient->secretKey = $smsset['dayu_secret'];
$dayuRequest = new AlibabaAliqinFcSmsNumSendRequest();
$dayuRequest->setSmsType('normal');
$dayuRequest->setSmsFreeSignName($template['smssign']);
$dayuRequest->setSmsParam($params);
$dayuRequest->setRecNum('' . $mobile);
$dayuRequest->setSmsTemplateCode($template['smstplid']);
$dayuResult = $dayuClient->execute($dayuRequest);
$dayuResult = (array) $dayuResult;
if (empty($dayuResult) || !empty($dayuResult['code']))
{
return array('status' => 0, 'message' => '短信发送失败(' . $dayuResult['sub_msg'] . '/code: ' . $dayuResult['code'] . '/sub_code: ' . $dayuResult['sub_code'] . ')');
}
}
if ($template['type'] == 'emay')
{
include_once EWEI_SHOPV2_VENDOR . 'emay/SMSUtil.php';
$balance = $this->sms_num('emay', $smsset);
if ($balance <= 0)
{
return array('status' => 0, 'message' => '短信发送失败(亿美软通余额不足, 当前余额' . $balance . ')');
}
$emayClient = new SMSUtil($smsset['emay_url'], $smsset['emay_sn'], $smsset['emay_pw'], $smsset['emay_sk'], array('proxyhost' => $smsset['emay_phost'], 'proxyport' => $smsset['pport'], 'proxyusername' => $smsset['puser'], 'proxypassword' => $smsset['ppw']), $smsset['emay_out'], $smsset['emay_outresp']);
$emayResult = $emayClient->send($mobile, '【' . $template['smssign'] . '】' . $params);
if (!empty($emayResult))
{
return array('status' => 0, 'message' => '短信发送失败(错误信息: ' . $emayResult . ')');
}
}
return array('status' => 1);
}
public function sms_set()
{
global $_W;
return pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_sms_set') . ' WHERE uniacid=:uniacid ', array(':uniacid' => $_W['uniacid']));
}
public function sms_temp()
{
global $_W;
$list = pdo_fetchall('SELECT id, `type`, `name` FROM ' . tablename('ewei_shop_sms') . ' WHERE status=1 and uniacid=:uniacid ', array(':uniacid' => $_W['uniacid']));
foreach ($list as $i => &$item )
{
if ($item['type'] == 'juhe')
{
$item['name'] = '[聚合]' . $item['name'];
}
else if ($item['type'] == 'dayu')
{
$item['name'] = '[大于]' . $item['name'];
}
else if ($item['type'] == 'emay')
{
$item['name'] = '[亿美]' . $item['name'];
}
}
unset($item);
return $list;
}
public function sms_num($type, $smsset = NULL)
{
if (empty($type))
{
return NULL;
}
if (empty($smsset) || !is_array($smsset))
{
$smsset = $this->sms_set();
}
if ($type == 'emay')
{
include_once EWEI_SHOPV2_VENDOR . 'emay/SMSUtil.php';
$emayClient = new SMSUtil($smsset['emay_url'], $smsset['emay_sn'], $smsset['emay_pw'], $smsset['emay_sk'], array('proxyhost' => $smsset['emay_phost'], 'proxyport' => $smsset['pport'], 'proxyusername' => $smsset['puser'], 'proxypassword' => $smsset['ppw']), $smsset['emay_out'], $smsset['emay_outresp']);
$num = $emayClient->getBalance();
if (!empty($smsset['emay_warn']) && !empty($smsset['emay_mobile']) && ($num < $smsset['emay_warn']) && (($smsset['emay_warn_time'] + (60 * 60 * 24)) < time()))
{
$emayClient = new SMSUtil($smsset['emay_url'], $smsset['emay_sn'], $smsset['emay_pw'], $smsset['emay_sk'], array('proxyhost' => $smsset['emay_phost'], 'proxyport' => $smsset['pport'], 'proxyusername' => $smsset['puser'], 'proxypassword' => $smsset['ppw']), $smsset['emay_out'], $smsset['emay_outresp']);
$emayResult = $emayClient->send($smsset['emay_mobile'], '【系统预警】' . '您的亿美软通SMS余额为:' . $num . ',低于预警值:' . $smsset['emay_warn'] . ' (24小时内仅通知一次)');
if (empty($emayResult))
{
pdo_update('ewei_shop_sms_set', array('emay_warn_time' => time()), array('id' => $smsset['id']));
}
}
return $num;
}
}
protected function sms_verify($tplid, $smsset)
{
global $_W;
$template = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_sms') . ' WHERE id=:id and uniacid=:uniacid ', array(':id' => $tplid, ':uniacid' => $_W['uniacid']));
$template['data'] = iunserializer($template['data']);
if (empty($template))
{
return array('status' => 0, 'message' => '模板不存在!');
}
if (empty($template['status']))
{
return array('status' => 0, 'message' => '模板未启用!');
}
if (empty($template['type']))
{
return array('status' => 0, 'message' => '模板类型错误!');
}
if ($template['type'] == 'juhe')
{
if (empty($smsset['juhe']))
{
return array('status' => 0, 'message' => '未开启聚合数据!');
}
if (empty($smsset['juhe_key']))
{
return array('status' => 0, 'message' => '未填写聚合数据Key!');
}
if (empty($template['data']) || !is_array($template['data']))
{
return array('status' => 0, 'message' => '模板类型错误!');
}
}
else if ($template['type'] == 'dayu')
{
if (empty($smsset['dayu']))
{
return array('status' => 0, 'message' => '未开启阿里大于!');
}
if (empty($smsset['dayu_key']))
{
return array('status' => 0, 'message' => '未填写阿里大于Key!');
}
if (empty($smsset['dayu_secret']))
{
return array('status' => 0, 'message' => '未填写阿里大于Secret!');
}
if (empty($template['data']) || !is_array($template['data']))
{
return array('status' => 0, 'message' => '模板类型错误!');
}
if (empty($template['smssign']))
{
return array('status' => 0, 'message' => '未填写阿里大于短信签名!');
}
}
else if ($template['type'] == 'emay')
{
if (empty($smsset['emay']))
{
return array('status' => 0, 'message' => '未开启亿美软通!');
}
if (empty($smsset['emay_url']))
{
return array('status' => 0, 'message' => '未填写亿美软通网关!');
}
if (empty($smsset['emay_sn']))
{
return array('status' => 0, 'message' => '未填写亿美软通序列号!');
}
if (empty($smsset['emay_pw']))
{
return array('status' => 0, 'message' => '未填写亿美软通密码!');
}
if (empty($smsset['emay_sk']))
{
return array('status' => 0, 'message' => '未填写亿美软通SessionKey!');
}
if (empty($template['smssign']))
{
return array('status' => 0, 'message' => '未填写亿美软通短信签名!');
}
}else if($template['type'] == 'smsbao'){
if (empty($smsset['smsbao'])) {
return array('status' => 0, 'message' => '未开启短信宝!');
}
if (empty($smsset['smsbao_key'])) {
return array('status' => 0, 'message' => '未填写短信宝帐号!');
}
if (empty($smsset['smsbao_secret'])) {
return array('status' => 0, 'message' => '未填写短信宝密码!');
}
if (empty($smsset['smsbao_sign'])) {
return array('status' => 0, 'message' => '未填写短信宝签名!');
}
}
return $template;
}
protected function sms_data($type, $data, $replace, $template)
{
if ($type == 'smsbao') {
$tempdata = $template['content'];
foreach ($data as $key => $value )
{
$tempdata = str_replace("{".$key."}", trim($value), $tempdata);
}
$result = $tempdata;
}
if ($replace)
{
if ($type == 'emay')
{
$tempdata = $template['content'];
foreach ($data as $key => $value )
{
$tempdata = str_replace('[' . $key . ']', $value, $tempdata);
}
$data = $tempdata;
}
else
{
$tempdata = iunserializer($template['data']);
foreach ($tempdata as &$td )
{
foreach ($data as $key => $value )
{
$td['data_shop'] = str_replace('[' . $key . ']', $value, $td['data_shop']);
}
}
unset($td);
$newdata = array();
foreach ($tempdata as $td )
{
$newdata[$td['data_temp']] = $td['data_shop'];
}
$data = $newdata;
}
}
if ($type == 'juhe')
{
$result = '';
$count = count($data);
$i = 0;
foreach ($data as $key => $value )
{
if ((0 < $i) && ($i < $count))
{
$result .= '&';
}
$result .= '#' . $key . '#=' . $value;
++$i;
}
}
else if ($type == 'dayu')
{
$result = json_encode($data);
}
else if ($type == 'emay')
{
$result = $data;
}
return $result;
}
protected function http_post($url, $postData)
{
$postData = http_build_query($postData);
$options = array( 'http' => array('method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postData, 'timeout' => 15 * 60) );
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if (!is_array($result))
{
$result = json_decode($result, true);
}
return $result;
}
public function callsms(array $params)
{
global $_W;
$tag = ((isset($params['tag']) ? $params['tag'] : ''));
$datas = ((isset($params['datas']) ? $params['datas'] : array()));
$tm = $_W['shopset']['notice'];
if (empty($tm))
{
$tm = m('common')->getSysset('notice');
}
$smsid = $tm[$tag . '_sms'];
$smsclose = $tm[$tag . '_close_sms'];
if (!empty($smsid) && empty($smsclose) && !empty($params['mobile']))
{
$sms_data = array();
foreach ($datas as $i => $value )
{
$sms_data[$value['name']] = $value['value'];
}
$this->send($params['mobile'], $smsid, $sms_data);
}
}
}
?>
2。打开项目/core/mobile/account/index.php文件,修改发送内容参数:
public function verifycode()
{
global $_W;
global $_GPC;
$set = $this->getWapSet();
$mobile = trim($_GPC['mobile']);
$temp = trim($_GPC['temp']);
$imgcode = trim($_GPC['imgcode']);
if (empty($mobile))
{
show_json(0, '请输入手机号');
}
if (empty($temp))
{
show_json(0, '参数错误');
}
if (!(empty($set['wap']['smsimgcode'])) && (($temp == 'sms_reg') || ($temp == 'sms_forget')))
{
if (empty($imgcode))
{
show_json(0, '请输入图形验证码');
}
$imgcodehash = md5(strtolower($imgcode) . $_W['config']['setting']['authkey']);
if ($imgcodehash != trim($_GPC['__code']))
{
show_json(-1, '请输入正确的图形验证码');
}
}
$member = pdo_fetch('select id,openid,mobile,pwd,salt from ' . tablename('ewei_shop_member') . ' where mobile=:mobile and mobileverify=1 and uniacid=:uniacid limit 1', array(':mobile' => $mobile, ':uniacid' => $_W['uniacid']));
if (($temp == 'sms_forget') && empty($member))
{
show_json(0, '此手机号未注册');
}
if (($temp == 'sms_reg') && !(empty($member)))
{
show_json(0, '此手机号已注册,请直接登录');
}
$sms_id = $set['wap'][$temp];
if (empty($sms_id))
{
show_json(0, '短信发送失败(NOSMSID)');
}
$key = '__ewei_shopv2_member_verifycodesession_' . $_W['uniacid'] . '_' . $mobile;
@session_start();
$code = random(5, true);
$shopname = $_W['shopset']['shop']['name'];
$ret = com('sms')->send($mobile, $sms_id, array('$code' => $code,'$mobile' => $mobile, '$shopname' => (!(empty($shopname)) ? $shopname : '商城名称')));
if ($ret['status'])
{
$_SESSION[$key] = $code;
$_SESSION['verifycodesendtime'] = time();
show_json(1, '短信发送成功');
}
show_json(0, $ret['message']);
}
3。 打开项目/core/web/sysset/sms/index.php,在set方法中增加关于短信宝的配置:
public function set()
{
global $_W;
global $_GPC;
$item = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_sms_set') . ' WHERE uniacid=:uniacid ', array(':uniacid' => $_W['uniacid']));
if ($_W['ispost']) {
$arr = array('juhe' => intval($_GPC['juhe']), 'juhe_key' => trim($_GPC['juhe_key']), 'dayu' => intval($_GPC['dayu']), 'dayu_key' => trim($_GPC['dayu_key']), 'dayu_secret' => trim($_GPC['dayu_secret']), 'emay' => intval($_GPC['emay']), 'emay_url' => trim($_GPC['emay_url']), 'emay_sn' => trim($_GPC['emay_sn']), 'emay_pw' => trim($_GPC['emay_pw']), 'emay_sk' => trim($_GPC['emay_sk']), 'emay_phost' => trim($_GPC['emay_phost']), 'emay_pport' => intval($_GPC['emay_pport']), 'emay_puser' => trim($_GPC['emay_puser']), 'emay_ppw' => trim($_GPC['emay_ppw']), 'emay_out' => intval($_GPC['emay_out']), 'emay_outresp' => (empty($_GPC['emay_outresp']) ? 30 : intval($_GPC['emay_outresp'])), 'emay_warn' => intval($_GPC['emay_warn']), 'emay_mobile' => intval($_GPC['emay_mobile']), 'smsbao' => intval($_GPC['smsbao']), 'smsbao_key' => trim($_GPC['smsbao_key']), 'smsbao_secret' => trim($_GPC['smsbao_secret']), 'smsbao_sign' => trim($_GPC['smsbao_sign']));
if (empty($item)) {
$arr['uniacid'] = $_W['uniacid'];
pdo_insert('ewei_shop_sms_set', $arr);
$id = pdo_insertid();
}
else {
pdo_update('ewei_shop_sms_set', $arr, array('id' => $item['id'], 'uniacid' => $_W['uniacid']));
}
show_json(1);
}
include $this->template();
}
4。 修改后台的模版文件,打开项目/template/web/sysset/sms/set.html,添加如下代码:
<div class="form-group-title">短信宝<kbd>推荐</kbd><small style="padding-left:10px;"><a target="_blank" href="http://www.smsbao.com">立即申请</a></small>
<span class="pull-right">
<input type="hidden" value="<?php echo $item['smsbao'];?>" name="smsbao" />
<input class="js-switch small" type="checkbox" <?php if(!empty($item['smsbao'])) {?>checked<?php }?>/>
</span>
</div>
<div class=" sms-smsbao" style="<?php if(empty($item['smsbao'])) { ?>display: none;<?php } ?>">
<div class="form-group">
<label class="col-sm-2 control-label must">短信宝帐号</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="smsbao_key" class="form-control valid" value="<?php echo $item['smsbao_key'];?>" data-rule-required="true">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label must">短信宝密码</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="smsbao_secret" class="form-control valid" value="<?php echo $item['smsbao_secret'];?>" data-rule-required="true">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label must">短信宝签名</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="smsbao_sign" class="form-control valid" value="<?php echo $item['smsbao_sign'];?>" data-rule-required="true">
</div>
</div>
</div>
打开项目/template/web/sysset/sms/temp/post.html,修改代码如下:
<form {ife 'sysset.sms.temp' $item}action="" method="post"{/if} class="form-horizontal form-validate" enctype="multipart/form-data">
<input type="hidden" name="template" value="{if !empty($item)}{$item['template']}{else}1{/if}" />
<div class="form-group">
<label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}" >模板名称</label>
<div class="col-sm-9 col-xs-12">
{ife 'sysset.sms.temp' $item}
<input type="text" name="name" class="form-control" value="{$item['name']}" placeholder="模版名称,例:订单创建成功通知(自定义)" data-rule-required='true' />
{else}
<div class='form-control-static'>{$item['name']}</div>
{/if}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}">服务商</label>
<div class="col-sm-9 col-xs-12">
{ife 'sysset.sms.temp' $item}
{if !empty($smsset['juhe']) || (!empty($item) && $item['type']=='juhe')}<label class="radio-inline"><input type="radio" class="sms-type" data-template="1" name="type" value="juhe" {if $item['type']=='juhe' || empty($item)}checked{/if} {if !empty($item['type'])}disabled{/if}> 聚合数据</label>{/if}
{if !empty($smsset['dayu']) || (!empty($item) && $item['type']=='dayu')}<label class="radio-inline"><input type="radio" class="sms-type" data-template="1" name="type" value="dayu" {if $item['type']=='dayu'} checked{/if} {if !empty($item['type'])}disabled{/if}> 阿里大于</label>{/if}
{if !empty($smsset['emay']) || (!empty($item) && $item['type']=='emay')}<label class="radio-inline"><input type="radio" class="sms-type" data-template="0" name="type" value="emay" {if $item['type']=='emay'} checked{/if} {if !empty($item['type'])}disabled{/if}> 亿美软通</label>{/if}
{if !empty($smsset['smsbao']) || (!empty($item) && $item['type']=='smsbao')}<label class="radio-inline"><input type="radio" class="sms-type" data-template="0" name="type" value="smsbao" {if $item['type']=='smsbao'} checked{/if} {if !empty($item['type'])}disabled{/if}> 短信宝(请参考已有的短信宝模板)</label>{/if}
<div class="help-block">注意:选择短信服务商请先至 <a href="{php echo webUrl('sysset/sms/set')}" target="_blank">短信接口设置</a> 页面设置好短信服务商的接口信息。(<span class="text-danger">保存后不可修改</span> )</div>
{else}
<div class='form-control-static'>{if $item['type']=='juhe'}聚合数据{elseif $item['type']=='dayu'}阿里大于{elseif $item['type']=='smsbao'}短信宝{elseif $item['type']=='emay'}亿美软通{/if}</div>
{/if}
</div>
</div>
<div class="form-group sms-template-1" style="{if !empty($item['template']) || empty($item)}display:block;{else}display:none;{/if}">
<label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}" >模板ID</label>
<div class="col-sm-9 col-xs-12">
{ife 'sysset.sms.temp' $item}
<input type="text" name="smstplid" class="form-control" value="{$item['smstplid']}" placeholder="短信模板ID,例:1234(短信服务商提供的模板ID)" data-rule-required='true' />
<div class="help-block">服务商提供的模板ID</div>
{else}
<div class='form-control-static'>{$item['smstplid']}</div>
{/if}
</div>
</div>
<div class="form-group sms-template-sign" style="{if $item['type']=='dayu' || $item['type']=='emay'}display:block;{else}display:none;{/if}">
<label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}" >短信签名</label>
<div class="col-sm-9 col-xs-12">
{ife 'sysset.sms.temp' $item}
<input type="text" name="smssign" class="form-control" value="{$item['smssign']}" placeholder="" data-rule-required='true' />
<div class="help-block">请填写短信签名(如果服务商是大于请填写审核成功的签名)</div>
{else}
<div class='form-control-static'>{$item['smssign']}</div>
{/if}
</div>
</div>
<div class="form-group sms-template-0" style="{if empty($item['template']) && !empty($item)}display:block;{else}display:none;{/if}">
<label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}" >短信内容</label>
<div class="col-sm-9 col-xs-12">
{ife 'sysset.sms.temp' $item}
<textarea class="form-control" name="content" placeholder="请填写短信内容" rows="4" style="resize: none" data-rule-required="true">{$item['content']}</textarea>
{else}
<div class='form-control-static'>{$item['content']}</div>
{/if}
</div>
</div>
<div class="form-group splitter sms-template-1"></div>
<div id="datas" class="sms-template-1" style="{if !empty($item['template']) || empty($item)}display:block;{else}display:none;{/if}">
{if empty($item['data'])}
{template 'sysset/sms/temp/tpl'}
{else}
{loop $item['data'] $data}
{template 'sysset/sms/temp/tpl'}
{/loop}
{/if}
</div>
{ife 'sysset.sms.temp' $item}
<div class="form-group sms-template-1" style="{if !empty($item['template']) || empty($item)}display:block;{else}display:none;{/if}">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-9 col-xs-12">
<a class="btn btn-default btn-add-type" href="javascript:;" onclick="addType();"><i class="fa fa-plus" title=""></i> 增加一条数据值</a>
</div>
</div>
{/if}
<div class="form-group">
<label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}">状态</label>
<div class="col-sm-9 col-xs-12">
{ife 'sysset.sms.temp' $item}
<label class="radio-inline"><input type="radio" name="status" value="0" {if empty($item['status'])}checked{/if}> 禁用</label>
<label class="radio-inline"><input type="radio" name="status" value="1" {if !empty($item['status'])}checked{/if}> 启用</label>
<div class="help-block">关闭后将不能调用</div>
{else}
<div class='form-control-static'>{if empty($item['status'])}禁用{else}启用{/if}</div>
{/if}
</div>
</div>
<div class="form-group"></div>
<div class="form-group">
<label class="col-sm-2 control-label" ></label>
<div class="col-sm-9 col-xs-12">
{ife 'sysset.sms.temp' $item}
<input type="submit" value="提交" class="btn btn-primary" />
{/if}
{ifp 'sysset.sms.temp.main'}
<input type="button" name="back" onclick='history.back()' {ifp 'sysset.sms.temp.add|sysset.sms.temp.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
{/if}
</div>
</div>
</form>
打开项目/template/web/sysset/sms/temp/index.html,修改代码如下:
{template '_header'}
<div class="page-heading">
<span class='pull-right'>
{ifp 'sysset.sms.temp.add'}
<a class='btn btn-primary btn-sm' href="{php echo webUrl('sysset/sms/temp/add')}"><i class="fa fa-plus"></i> 添加新模板</a>
{/if}
</span>
<h2>短信消息库管理</h2>
</div>
<form action="./index.php" method="get" class="form-horizontal form-search" role="form">
<input type="hidden" name="c" value="site"/>
<input type="hidden" name="a" value="entry"/>
<input type="hidden" name="m" value="ewei_shopv2"/>
<input type="hidden" name="do" value="web"/>
<input type="hidden" name="r" value="sysset.sms.temp"/>
<div class="page-toolbar row m-b-sm m-t-sm">
<div class="col-sm-4">
<div class="input-group-btn">
<button class="btn btn-default btn-sm" type="button" data-toggle='refresh'><i class='fa fa-refresh'></i></button>
{ifp 'sysset.sms.temp.edit'}
<button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle='batch' data-confirm="确认要启用?" data-href="{php echo webUrl('sysset/sms/temp/status', array('status'=>1))}"><i class='fa fa fa-circle'></i> 启用
</button>
<button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle='batch' data-confirm="确认要禁用?" data-href="{php echo webUrl('sysset/sms/temp/status', array('status'=>0))}"><i class='fa fa fa-circle-o'></i> 禁用
</button>
{/if}
{ifp 'sysset.sms.temp.delete'}
<button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle='batch-remove' data-confirm="确认要删除?" data-href="{php echo webUrl('sysset/sms/temp/delete')}"><i class='fa fa-trash'></i> 删除
</button>
{/if}
</div>
</div>
<div class="col-sm-7 pull-right">
<select name="type" class="form-control input-sm select-sm" style="width:120px;">
<option value="" {if $_GPC['type']==''}selected{/if}>服务商</option>
<option value="juhe" {if $_GPC['type']=='juhe'}selected{/if}>聚合数据</option>
<option value="dayu" {if $_GPC['type']=='dayu'}selected{/if}>阿里大于</option>
<option value="emay" {if $_GPC['type']=='emay'}selected{/if}>亿美软通</option>
<option value="smsbao" {if $_GPC['type']=='smsbao'}selected{/if}>短信宝</option>
</select>
<select name="status" class="form-control input-sm select-sm" style="width:80px;">
<option value="" {if $_GPC['status']==''}selected{/if}>状态</option>
<option value="0" {if $_GPC['status']=='0'}selected{/if}>关闭</option>
<option value="1" {if $_GPC['status']=='1'}selected{/if}>开启</option>
</select>
<div class="input-group">
<input type="text" class="input-sm form-control" name='keyword' value="{$_GPC['keyword']}" placeholder="请输入关键词"> <span class="input-group-btn">
<button class="btn btn-sm btn-primary" type="submit"> 搜索</button> </span>
</div>
</div>
</div>
</form>
{if count($list)>0}
<table class="table table-responsive table-hover">
<thead>
<tr>
<th style="width:25px;"><input type='checkbox'/></th>
<th>模板名称</th>
<th style="width: 100px; text-align: center;">服务商</th>
<th style="width: 80px; text-align: center;">状态</th>
{ifp 'sysset.sms.temp.testsend'}
<th style="width: 100px; text-align: center;">测试发送</th>
{/if}
<th style="width: 150px;">操作</th>
</tr>
</thead>
<tbody>
{loop $list $item}
<tr>
<td>
<input type='checkbox' value="{$item['id']}"/>
</td>
<td>{$item['name']}</td>
<td style="text-align: center;">
{if $item['type']=='juhe'}
<span class="label label-primary">聚合数据</span>
{elseif $item['type']=='dayu'}
<span class="label label-success">阿里大于</span>
{elseif $item['type']=='smsbao'}
<span class="label label-success">短信宝</span>
{elseif $item['type']=='emay'}
<span class="label label-warning">亿美软通</span>
{/if}
</td>
<td style="text-align: center;">
<span class="label
{if !empty($item['status'])}label-success{else}label-default{/if}"
{ifp 'sysset.sms.temp.edit'}
data-toggle="ajaxSwitch"
data-confirm = "确认{if !empty($item['status'])}关闭{else}开启{/if}吗?"
data-switch-value="{$item['status']}"
data-switch-value0="0|关闭|label label-default|{php echo webUrl('sysset/sms/temp/status',array('status'=>1,'id'=>$item['id']))}"
data-switch-value1="1|开启|label label-success|{php echo webUrl('sysset/sms/temp/status',array('status'=>0,'id'=>$item['id']))}"
{/if}>
{if !empty($item['status'])}开启{else}关闭{/if}
</span>
</td>
{ifp 'sysset.sms.temp.testsend'}
<td style="text-align: center;">
<a class="btn btn-primary btn-sm" data-toggle="ajaxModal" href="{php echo webUrl('sysset/sms/temp/testsend', array('id'=>$item['id']))}"><i class="fa fa-paper-plane-o"></i> 发送</a>
</td>
{/if}
<td>
{ifp 'sysset.sms.temp.edit|sysset.sms.temp.view'}
<a class='btn btn-default btn-sm' href="{php echo webUrl('sysset/sms/temp/edit', array('id' => $item['id']))}"><i class='fa fa-edit'></i> {ifp 'sysset.sms.temp.edit'}编辑{else}查看{/if}</a>
{/if}
{ifp 'sysset.sms.temp.delete'}
<a class='btn btn-default btn-sm' data-toggle='ajaxRemove' href="{php echo webUrl('sysset/sms/temp/delete', array('id' => $item['id']))}" data-confirm="确认删除此模板吗?"><i class='fa fa-trash'></i> 删除</a>
{/if}
</td>
</tr>
{/loop}
</tbody>
</table>
{$pager}
{else}
<div class='panel panel-default'>
<div class='panel-body' style='text-align: center;padding:30px;'>
暂时没有任何短信模板!
</div>
</div>
{/if}
</div>
{template '_footer'}
以上修改完成之后我们需要在数据库中添加几条数据,我们需要在根目录建立两个文件,smsbao_install.sql,代码如下:
alter table `ims_ewei_shop_sms_set` add `smsbao` tinyint(3) NOT NULL DEFAULT '0' ;
alter table `ims_ewei_shop_sms_set` add `smsbao_key` varchar(255) NOT NULL DEFAULT '';
alter table `ims_ewei_shop_sms_set` add `smsbao_secret` varchar(255) NOT NULL DEFAULT '';
alter table `ims_ewei_shop_sms_set` add `smsbao_sign` varchar(255) NOT NULL DEFAULT '';
第二个文件smsbao_install.php,代码如下:
<?php define('IN_SYS', true); require './framework/bootstrap.inc.php'; require './data/config.php'; if ($config['db']['host']) { $mysql_server_name = $config['db']['host']; $mysql_username = $config['db']['username']; $mysql_password = $config['db']['password']; $mysql_database = $config['db']['database']; $mysql_tablepre = $config['db']['tablepre']; }else{ $mysql_server_name = $config['db']['master']['host']; $mysql_username = $config['db']['master']['username']; $mysql_password = $config['db']['master']['password']; $mysql_database = $config['db']['master']['database']; $mysql_tablepre = $config['db']['master']['tablepre']; } $conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password) or die("error connecting") ; mysql_query("set names 'utf8'"); mysql_select_db($mysql_database); $newsql = sreadfile("smsbao_install.sql"); if ($mysql_tablepre != 'ims_') { $newsql = str_replace('ims_', $mysql_tablepre, $newsql); } $sqls = explode(";", $newsql); foreach ($sqls as $sql) { $sql = trim($sql); if (empty($sql)) { continue; } if(!$query =mysql_query($sql)) { echo "执行sql语句成功 ".mysql_error(); exit(); } } echo "<h4>人人店短信宝短信插件安装成功,请删除此文件。</h4>"; function sreadfile($filename) { $content = ''; if(function_exists('file_get_contents')) { @$content = file_get_contents($filename); } else { if(@$fp = fopen($filename, 'r')) { @$content = fread($fp, filesize($filename)); @fclose($fp); } } return $content; } ?>
注:如果你的人人店版本为3.5.0的话,或者有PC端的,那么还需要修改一个文件,在项目/plugin/pc/core/mobile/account/index.php,修改verifycode方法,代码如下:
public function verifycode()
{
global $_W;
global $_GPC;
$mobile = trim($_GPC['mobile']);
$temp = trim($_GPC['temp']);
if (empty($mobile) || empty($temp))
{
show_json(0, '参数错误');
}
$data = m('common')->getSysset('wap');
$sms_id = $data[$temp];
if (empty($sms_id))
{
show_json(0, '短信发送失败(NOSMSID)');
}
$key = '__ewei_shop_member_verifycodesession_' . $_W['uniacid'] . '_' . $mobile;
@session_start();
$code = random(5, true);
$shopname = $_W['shopset']['shop']['name'];
$ret = com('sms')->send($mobile, $sms_id, array('$code' => $code,'$mobile' => $mobile, '$shopname' => (!(empty($shopname)) ? $shopname : '商城名称')));
if ($ret['status'])
{
$_SESSION[$key] = $code;
$_SESSION['verifycodesendtime'] = time();
show_json(1, "短信发送成功");
}
show_json(0, $ret['message']);
}
至此短信宝短信接口已经开发完成了,在短信宝官网中也提供了插件下载地址:http://www.smsbao.com/plugin/153.html 小伙伴们可以对着短信宝短信插件,来看我这篇文章,这样会更直观一些。
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,并且免审核了,短信内容3~5秒就可送达。