[轉]人人店短信插件開發

本文轉自:https://blog.csdn.net/mindev/article/details/75088344javascript

人人商城是一款針對的移動端購物消費的微信商城管理系統。它不只能爲您提供專業可靠的技術支持,還能完美適配企業商用。可添加多個公衆號使用,具備強大的自定義功能,讓您擁有個性化商城。本人對該系統仍是比較熟悉的,今天我就來分享一下,如何進行二次開發。我以替換短信接口爲例,一步一步的手把手教你們開發過程。php

短信接口使用的是短信寶短信平臺的短信接口,小夥伴必定會問爲何使用短信寶做爲案例呢?緣由很簡單,由於短信寶的平臺極其穩定,並且短信發送速度至關快捷,驗證碼和訂單通知在3~5秒就能收到,用戶體驗很是好,因此咱們公司一直和短信寶保持着合做關係,小夥伴們也能夠去短信寶的官網(http://www.smsbao.com)註冊一個帳號,還有免費的短信條數送呢。html

接下來我就說一下開發步驟: 1。先打開項目/core/com/sms.php文件,添加短信寶的發送接口代碼:java

<?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文件,修改發送內容參數:mysql

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方法中增長關於短信寶的配置:web

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,添加以下代碼:ajax

<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,修改代碼以下:sql

<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,代碼以下:json

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秒就可送達。

相關文章
相關標籤/搜索