niushop商城系统短信接口替换
Niushop是一款基于thinkphp5.0 MVC+service框架的開源軟件,方便二次開發(fā)與集成,今天我就來分享一下,如何進(jìn)行二次開發(fā)。我以替換短信接口為例,一步一步的手把手教大家開發(fā)過程,我們做演示的短信平臺(tái)是短信寶(http://www.smsbao.com)短信平臺(tái),我們公司和短信寶平臺(tái)合作好幾年了,他們的平臺(tái)非常穩(wěn)定,而且快速,注冊還送免費(fèi)測試短信,大家可以在短信寶平臺(tái)注冊一個(gè)賬號(hào),進(jìn)行測試。
首先,我們先更換后臺(tái)的顯示界面文件。打開模板文件,替換一下模板文件。打開項(xiàng)目/template/admin/Config/messageConfig.html,替換的代碼從138行~160行,代碼如下圖所示:
<div class="set-style"><dl><dt>是否開啟:</dt><dd style="width:5%;"><input id="sms_is_use" type="checkbox" class="checkbox" {if condition="$mobile_message.is_use=='1'"}checked="checked"{/if}/></dd><dd style="width:20%;color:#666;" class="showmessage">當(dāng)前使用短信寶短信配置</dd></dl><dl><dt>短信寶帳號(hào):</dt><dd><input id="app_key" type="text" value="{$mobile_message['value']['appKey']}" /> 立即<a href="http://www.smsbao.com" target="_blank">免費(fèi)注冊</a>短信寶賬號(hào)</dd></dl><dl><dt>短信寶密碼:</dt><dd><input id="secret_key" type="password" value="{$mobile_message['value']['secretKey']}" /></dd></dl><button class="edit_button" onclick="setConfigAjax();">提交</button> </div>打開項(xiàng)目/template/admin/Config/notifySmsTemplate.html,替換的代碼從191行~203行,代碼如下圖所示:
<div class="right_main"><div class="main-top">您正在編輯<a href="javascript:;" id="update_nameid"></a>通知模板</div><div class="qianming"><div style="width:75px;float:left;">模板:</div><input type="text" name="" id="template_titleid" value="{$template_select.template_title}" style="margin-right: 15px;"/></div><div class="qianming"> <input type="text" name="" id="signNameid" style="margin-right: 15px;" value="{$template_select.sign_name }"/> </div><div class="bl"><div style="width:75px;float:left;">可用變量:</div><div style="width:88%;float: left;font-size:13px;" id="user_variable">{foreach name="template_item_list" item="item_obj"}{$item_obj.replace_name}({$item_obj.item_name}),{/foreach}</div></div> </div>經(jīng)過替換后,所有的顯示都變成短信寶短信平臺(tái)的了。第一步完成。接下來替換發(fā)送短信的業(yè)務(wù)代碼。修改項(xiàng)目/data/extend/hook/Notify.php文件,代碼如下:
<?php namespace data\extend\hook;use data\model\WebSiteModel; use data\model\UserModel; use data\model\ConfigModel; use data\model\NoticeTemplateModel; use data\model\NsOrderGoodsModel; use data\model\NsOrderModel; use phpDocumentor\Reflection\Types\This; use data\model\NsOrderGoodsExpressModel; class Notify {public $result=array("code"=>0,"message"=>"success","param"=>"");/*** 郵件的配置信息* @var unknown*/public $email_is_open=0;public $email_host="";public $email_port="";public $email_addr="";public $email_id="";public $email_pass="";/*** 短信的配置信息* @var unknown*/public $mobile_is_open;public $appKey="";public $secretKey="";public $freeSignName="";public $shop_name;public $ali_use_type=0;/*** 得到系統(tǒng)通知的配置信息* @param unknown $shop_id*/private function getShopNotifyInfo($shop_id){$website_model=new WebSiteModel();$website_obj=$website_model->getInfo("1=1", "title");if(empty($website_obj)){$this->shop_name="NiuShop開源商城";}else{$this->shop_name=$website_obj["title"];}$config_model=new ConfigModel();#查看郵箱是否開啟$email_info=$config_model->getInfo(["instance_id"=>$shop_id, "`key`"=>"EMAILMESSAGE"], "*");if(!empty($email_info)){$this->email_is_open=$email_info["is_use"];$value=$email_info["value"];if(!empty($value)){$email_array=json_decode($value, true);$this->email_host=$email_array["email_host"];$this->email_port=$email_array["email_port"];$this->email_addr=$email_array["email_addr"];$this->email_id=$email_array["email_id"];$this->email_pass=$email_array["email_pass"];}}$mobile_info=$config_model->getInfo(["instance_id"=>$shop_id, "`key`"=>"MOBILEMESSAGE"], "*");if(!empty($mobile_info)){$this->mobile_is_open=$mobile_info["is_use"];$value=$mobile_info["value"];if(!empty($value)){$mobile_array=json_decode($value, true);$this->appKey=$mobile_array["appKey"];$this->secretKey=$mobile_array["secretKey"];$this->freeSignName=$mobile_array["freeSignName"];$this->ali_use_type=$mobile_array["user_type"];if(empty($this->ali_use_type)){$this->ali_use_type=0;}}}}public function sendSMS($appkey, $secret, $signName, $smsParam, $send_mobile, $template_code){$content = strtr($template_code,$smsParam);//替換模板中的變量$contents = '【'.$signName.'】'.$content;$url = 'http://api.smsbao.com/sms?u='.$appkey.'&p='.md5($secret).'&m='.$send_mobile.'&c='.$contents;$result = file_get_contents($url);return $result;}/*** 查詢模板的信息* @param unknown $shop_id* @param unknown $template_code* @param unknown $type* @return unknown*/private function getTemplateDetail($shop_id, $template_code, $type){$template_model=new NoticeTemplateModel();$template_obj=$template_model->getInfo(["instance_id"=>$shop_id, "template_type"=>$type, "template_code"=>$template_code]);return $template_obj;}/*** 處理阿里大于 的返回?cái)?shù)據(jù)* @param unknown $result*/private function dealAliSmsResult($result){$deal_result=array();try {if($this->ali_use_type==0){#舊用戶發(fā)送if(!empty($result)){if(!isset($result->result)){$result=json_decode(json_encode($result), true);#發(fā)送失敗$deal_result["code"]=$result["code"];$deal_result["message"]=$result["msg"];}else{#發(fā)送成功$deal_result["code"]=0;$deal_result["message"]="發(fā)送成功";}}}else{#新用戶發(fā)送if(!empty($result)){if($result->Code=="OK"){#發(fā)送成功$deal_result["code"]=0;$deal_result["message"]="發(fā)送成功";}else{#發(fā)送失敗$deal_result["code"]=-1;$deal_result["message"]=$result->Message;}}}} catch (\Exception $e) {$deal_result["code"]=-1;$deal_result["message"]="發(fā)送失敗!";}return $deal_result;}/*** 用戶注冊成功后* @param string $params*/public function registAfter($params=null){/*** 店鋪id*/$shop_id=$params["shop_id"];#查詢系統(tǒng)配置信息$this->getShopNotifyInfo(0);/*** 用戶id*/$user_id=$params["user_id"];$user_model=new UserModel();$user_obj=$user_model->get($user_id);$mobile="";$user_name="";$email="";if(empty($user_obj)){$user_name="用戶";}else{$user_name=$user_obj["user_name"];$mobile=$user_obj["user_tel"];$email=$user_obj["user_email"];}#短信驗(yàn)證if(!empty($mobile) && $this->mobile_is_open==1){$template_obj=$this->getTemplateDetail($shop_id, "after_register", "sms");if(!empty($template_obj) && $template_obj["is_enable"]==1){$sms_params=array("shop_name"=>$this->shop_name,"user_name"=>$user_name);$result=$this->sendSMS($this->appKey, $this->secretKey,$template_obj["sign_name"], $sms_params, $mobile, $template_obj["template_title"], $this->ali_use_type);$this->result["code"]=$result->code;$this->result["message"]=$result->msg;}else{$this->result["code"]=-1;$this->result["message"]="商家沒開啟短信模板!";}}else{$this->result["code"]=-1;$this->result["message"]="商家沒開啟短信模板!";}#郵箱驗(yàn)證if(!empty($email) && $this->email_is_open==1){$template_obj=$this->getTemplateDetail($shop_id, "after_register", "email");if(!empty($template_obj) && $template_obj["is_enable"]==1){$content=$template_obj["template_content"];$content=str_replace("{商場名稱}", $this->shop_name, $content);$content=str_replace("{用戶名稱}", $user_name, $content);$result=emailSend($this->email_host, $this->email_id, $this->email_pass, $this->email_addr, $email, $template_obj["template_title"], $content);if($result == '0'){$this->result["code"]=0;$this->result["message"]="發(fā)送成功!";}else{$this->result["code"]=$result;$this->result["message"]="發(fā)送失敗!";}}else{$this->result["code"]=-1;$this->result["message"]="商家沒開啟郵箱驗(yàn)證";}}else{$this->result["code"]=-1;$this->result["message"]="商家沒開啟郵箱驗(yàn)證";}return $this->result;}/*** 注冊短信驗(yàn)證* @param string $params*/public function registBefor($params=null){$rand = rand(100000,999999);$mobile=$params["mobile"];$shop_id=$params["shop_id"];#查詢系統(tǒng)配置信息$this->getShopNotifyInfo($shop_id);$result="";if(!empty($mobile) && $this->mobile_is_open==1){$template_obj=$this->getTemplateDetail($shop_id, "register_validate", "sms");if(!empty($template_obj) && $template_obj["is_enable"]==1){$sms_params=array();$this->result["param"]=$rand;if(!empty($this->appKey) && !empty($this->secretKey) && !empty($template_obj["sign_name"]) && !empty($template_obj["template_title"])){$sms_params=array("number"=>$rand."",);$result=$this->sendSMS($this->appKey, $this->secretKey,$template_obj["sign_name"], $sms_params, $mobile, $template_obj["template_title"], $this->ali_use_type);if ($result == '0') {$this->result["code"]=0;$this->result["message"]="發(fā)送成功!";$this->result["param"]=$rand;}else{$this->result["code"]= $result;$this->result["message"]="發(fā)送失敗!";$this->result["param"]=$rand;}}else{$this->result["code"]=-1;$this->result["message"]="短信配置信息有誤!";}}else{$this->result["code"]=-1;$this->result["message"]="短信通知模板有誤!";}}else{$this->result["code"]=-1;$this->result["message"]="店家沒有開啟短信驗(yàn)證";}return $this->result;}/*** 注冊郵箱驗(yàn)證* 已測試* @param string $params*/public function registEmailValidation($params=null){$rand = rand(100000,999999);$email=$params["email"];$shop_id=$params["shop_id"];#查詢系統(tǒng)配置信息$this->getShopNotifyInfo($shop_id);if(!empty($email) && $this->email_is_open==1){$template_obj=$this->getTemplateDetail($shop_id, "register_validate", "email");if(!empty($template_obj) && $template_obj["is_enable"]==1){$content=$template_obj["template_content"];$content=str_replace("{驗(yàn)證碼}", $rand, $content);if(!empty($this->email_host) && !empty($this->email_id) && !empty($this->email_pass) && !empty($this->email_addr)){$result=emailSend($this->email_host, $this->email_id, $this->email_pass, $this->email_addr, $email, $template_obj["template_title"], $content);$this->result["param"]=$rand;if($result){$this->result["code"]=0;$this->result["message"]="發(fā)送成功!";}else{$this->result["code"]=-1;$this->result["message"]="發(fā)送失敗!";}}else{$this->result["code"]=-1;$this->result["message"]="郵箱配置信息有誤!";}}else{$this->result["code"]=-1;$this->result["message"]="配置郵箱注冊驗(yàn)證模板有誤!";}}else{$this->result["code"]=-1;$this->result["message"]="店家沒有開啟郵箱驗(yàn)證";}return $this->result;}/*** 訂單發(fā)貨* @param string $params*/public function orderDelivery($params=null){#查詢系統(tǒng)配置信息$this->getShopNotifyInfo(0);$order_goods_ids=$params["order_goods_ids"];$order_goods_str=explode(",", $order_goods_ids);$result="";$user_name="";if(count($order_goods_str)>0){$order_goods_id=$order_goods_str[0];$order_goods_model=new NsOrderGoodsModel();$order_goods_obj=$order_goods_model->get($order_goods_id);$shop_id=$order_goods_obj["shop_id"];$order_id=$order_goods_obj["order_id"];$order_model=new NsOrderModel();$order_obj=$order_model->get($order_id);$user_name=$order_obj["receiver_name"];$buyer_id=$order_obj["buyer_id"];$goods_name=$order_goods_obj["goods_name"];$goods_sku=$order_goods_obj["sku_name"];$order_no=$order_obj["out_trade_no"];$order_money=$order_obj["pay_money"];$goods_money=$order_goods_obj["goods_money"];$mobile=$order_obj["receiver_mobile"];$goods_express_model=new NsOrderGoodsExpressModel();$express_obj=$goods_express_model->getInfo(["order_id"=>$order_id, "order_goods_id_array"=>$order_goods_ids], "*");$sms_params=array("shop_name"=>$this->shop_name,"user_name"=>$user_name,"goods_name"=>$goods_name,"goods_sku"=>$goods_sku,"order_no"=>$order_no,"order_money"=>$order_money,"goods_money"=>$goods_money,"express_company"=>$express_obj["express_name"],"express_no"=>$express_obj["express_no"]);#短信發(fā)送if(!empty($mobile) && $this->mobile_is_open==1){$template_obj=$this->getTemplateDetail($shop_id, "order_deliver", "sms");if(!empty($template_obj) && $template_obj["is_enable"]==1){$result=$this->sendSMS($this->appKey, $this->secretKey, $template_obj["sign_name"], $sms_params, $mobile, $template_obj["template_title"], $this->ali_use_type);}}// 郵件發(fā)送$user_model = new UserModel();$user_obj = $user_model->get($buyer_id);if (! empty($user_obj)) {$email = $user_obj["user_email"];if (! empty($email) && $this->email_is_open == 1) {$template_obj = $this->getTemplateDetail($shop_id, "order_deliver", "email");if (! empty($template_obj) && $template_obj["is_enable"] == 1) {$content = $template_obj["template_content"];$content = str_replace("{商場名稱}", $this->shop_name, $content);$content = str_replace("{用戶名稱}", $user_name, $content);$content = str_replace("{商品名稱}", $goods_name, $content);$content = str_replace("{商品規(guī)格}", $goods_sku, $content);$content = str_replace("{主訂單號(hào)}", $order_no, $content);$content = str_replace("{訂單金額}", $order_money, $content);$content = str_replace("{商品金額}", $goods_money, $content);$content = str_replace("{物流公司}", $express_obj["express_name"], $content);$content = str_replace("{快遞編號(hào)}", $express_obj["express_no"], $content);$result=emailSend($this->email_host, $this->email_id,$this->email_pass, $this->email_addr, $email, $template_obj["template_title"], $content);}}}}}/*** 訂單確認(rèn)* @param string $params*/public function orderComplete($params=null){#查詢系統(tǒng)配置信息$this->getShopNotifyInfo(0);$order_id=$params["order_id"];$order_model=new NsOrderModel();$order_obj=$order_model->get($order_id);$shop_id=$order_obj["shop_id"];$buyer_id=$order_obj["buyer_id"];$user_name=$order_obj["receiver_name"];$order_no=$order_obj["out_trade_no"];$order_money=$order_obj["pay_money"];$mobile=$order_obj["receiver_mobile"];$sms_params=array("shop_name"=>$this->shop_name,"user_name"=>$user_name,"order_no"=>$order_no,"order_money"=>$order_money);// 短信發(fā)送if (! empty($mobile) && $this->mobile_is_open == 1) {$template_obj = $this->getTemplateDetail($shop_id, "confirm_order", "sms");if (! empty($template_obj) && $template_obj["is_enable"] == 1) {$result = $this->sendSMS($this->appKey, $this->secretKey, $template_obj["sign_name"],$sms_params, $mobile, $template_obj["template_title"], $this->ali_use_type);}}// 郵件發(fā)送$user_model = new UserModel();$user_obj = $user_model->get($buyer_id);if (! empty($user_obj)) {$email = $user_obj["user_email"];if (! empty($email) && $this->email_is_open == 1) {$template_obj = $this->getTemplateDetail($shop_id, "confirm_order", "email");if (! empty($template_obj) && $template_obj["is_enable"] == 1) {$content = $template_obj["template_content"];$content = str_replace("{商場名稱}", $this->shop_name, $content);$content=str_replace("{用戶名稱}", $user_name, $content);$content=str_replace("{主訂單號(hào)}", $order_no, $content);$content=str_replace("{訂單金額}", $order_money, $content);$result=emailSend($this->email_host, $this->email_id,$this->email_pass, $this->email_addr, $email, $template_obj["template_title"], $content);}}}}/*** 訂單付款成功* @param string $params*/public function orderPay($params=null){#查詢系統(tǒng)配置信息$this->getShopNotifyInfo(0);$order_id=$params["order_id"];$order_model=new NsOrderModel();$order_obj=$order_model->get($order_id);$shop_id=$order_obj["shop_id"];$buyer_id=$order_obj["buyer_id"];$user_name=$order_obj["receiver_name"];$order_no=$order_obj["out_trade_no"];$order_money=$order_obj["pay_money"];$mobile=$order_obj["receiver_mobile"];$goods_money=$order_obj["goods_money"];$sms_params=array("shop_name"=>$this->shop_name,"user_name"=>$user_name,"order_no"=>$order_no,"order_money"=>$order_money,"goods_money"=>$goods_money);#短信發(fā)送if(!empty($mobile) && $this->mobile_is_open==1){$template_obj=$this->getTemplateDetail($shop_id, "pay_success", "sms");if(!empty($template_obj) && $template_obj["is_enable"]==1){$result=$this->sendSMS($this->appKey, $this->secretKey,$template_obj["sign_name"],$sms_params, $mobile, $template_obj["template_title"], $this->ali_use_type);}}#郵件發(fā)送$user_model=new UserModel();$user_obj=$user_model->get($buyer_id);if(!empty($user_obj)){$email=$user_obj["user_email"];if(!empty($email) && $this->email_is_open==1){$template_obj=$this->getTemplateDetail($shop_id, "pay_success", "email");if(!empty($template_obj) && $template_obj["is_enable"]==1){$content=$template_obj["template_content"];$content=str_replace("{商場名稱}", $this->shop_name, $content);$content=str_replace("{用戶名稱}", $user_name, $content);$content=str_replace("{主訂單號(hào)}", $order_no, $content);$content=str_replace("{訂單金額}", $order_money, $content);$content=str_replace("{商品金額}", $goods_money, $content);$result=emailSend($this->email_host, $this->email_id,$this->email_pass, $this->email_addr, $email, $template_obj["template_title"], $content);}}}}/*** 訂單創(chuàng)建成功* @param string $params*/public function orderCreate($params=null){#查詢系統(tǒng)配置信息$this->getShopNotifyInfo(0);$order_id=$params["order_id"];$order_model=new NsOrderModel();$order_obj=$order_model->get($order_id);$shop_id=$order_obj["shop_id"];$buyer_id=$order_obj["buyer_id"];$user_name=$order_obj["receiver_name"];$order_no=$order_obj["out_trade_no"];$order_money=$order_obj["pay_money"];$mobile=$order_obj["receiver_mobile"];$goods_money=$order_obj["goods_money"];$sms_params= array("shop_name"=>$this->shop_name,"user_name"=>$user_name,"order_no"=>$order_no,"order_money"=>$order_money,"goods_money"=>$goods_money);#短信發(fā)送if(!empty($mobile) && $this->mobile_is_open==1){$template_obj=$this->getTemplateDetail($shop_id, "create_order", "sms");if(!empty($template_obj) && $template_obj["is_enable"]==1){$result=$this->sendSMS($this->appKey, $this->secretKey,$template_obj["sign_name"],$sms_params, $mobile, $template_obj["template_title"], $this->ali_use_type);}}// 郵件發(fā)送$user_model = new UserModel();$user_obj = $user_model->get($buyer_id);if (! empty($user_obj)) {$email = $user_obj["user_email"];if (! empty($email) && $this->email_is_open == 1) {$template_obj = $this->getTemplateDetail($shop_id, "create_order", "email");if (! empty($template_obj) && $template_obj["is_enable"] == 1) {$content = $template_obj["template_content"];$content = str_replace("{商場名稱}", $this->shop_name, $content);$content = str_replace("{用戶名稱}", $user_name, $content);$content = str_replace("{主訂單號(hào)}", $order_no, $content);$content = str_replace("{訂單金額}", $order_money, $content);$content = str_replace("{商品金額}", $goods_money, $content);$result = emailSend($this->email_host, $this->email_id, $this->email_pass, $this->email_addr, $email, $template_obj["template_title"], $content);}}}}/*** 找回密碼* @param string $params* @return multitype:number string*/public function forgotPassword($params=null){$send_type=$params["send_type"];$send_param=$params["send_param"];$shop_id=$params["shop_id"];$this->getShopNotifyInfo($shop_id);$rand = rand(100000,999999);$template_obj=$this->getTemplateDetail($shop_id, "forgot_password", $send_type);if($send_type=="email"){#郵箱驗(yàn)證if($this->email_is_open==1){if(!empty($template_obj) && $template_obj["is_enable"]==1){#發(fā)送$content=$template_obj["template_content"];$content=str_replace("{驗(yàn)證碼}", $rand, $content);$result=emailSend($this->email_host, $this->email_id, $this->email_pass, $this->email_addr, $send_param, $template_obj["template_title"], $content);$this->result["param"]=$rand;if($result){$this->result["code"]=0;$this->result["message"]="發(fā)送成功!";}else{$this->result["code"]=-1;$this->result["message"]="發(fā)送失敗!";}}else{$this->result["code"]=-1;$this->result["message"]="商家沒有設(shè)置找回密碼的模板!";}}else{$this->result["code"]=-1;$this->result["message"]="商家沒開啟郵箱驗(yàn)證!";}}else{#短信驗(yàn)證if($this->mobile_is_open==1){if(!empty($template_obj) && $template_obj["is_enable"]==1){#發(fā)送$sms_params=array("number"=>$rand."");$result=$this->sendSMS($this->appKey, $this->secretKey,$template_obj["sign_name"],$sms_params, $send_param, $template_obj["template_title"], $this->ali_use_type);if ($result == '0') {$this->result["code"]=0;$this->result["message"]="發(fā)送成功!";$this->result["param"]=$rand;}else{$this->result["code"]= $result;$this->result["message"]="發(fā)送失敗!";$this->result["param"]=$rand;}}else{$this->result["code"]=-1;$this->result["message"]="商家沒有設(shè)置找回密碼的短信模板!";}}else{$this->result["code"]=-1;$this->result["message"]="商家沒開啟短信驗(yàn)證!";}}return $this->result;}/*** 用戶綁定手機(jī)號(hào)* @param string $params*/public function bindMobile($params=null){$rand = rand(100000,999999);$mobile=$params["mobile"];$shop_id=$params["shop_id"];$user_id=$params["user_id"];#查詢系統(tǒng)配置信息$this->getShopNotifyInfo($shop_id);if(!empty($mobile) && $this->mobile_is_open==1){$template_obj=$this->getTemplateDetail($shop_id, "bind_mobile", "sms");if(!empty($template_obj) && $template_obj["is_enable"]==1){$user_model=new UserModel();$user_obj=$user_model->get($user_id);$sms_params=array("number"=>$rand."","user_name"=>$user_obj["user_name"]);$this->result["param"]=$rand;if(!empty($this->appKey) && !empty($this->secretKey) && !empty($template_obj["sign_name"]) && !empty($template_obj["template_title"])){$result=$this->sendSMS($this->appKey, $this->secretKey,$template_obj["sign_name"], json_encode($sms_params), $mobile, $template_obj["template_title"], $this->ali_use_type);if ($result == '0') {$this->result["code"]=0;$this->result["message"]="發(fā)送成功!";$this->result["param"]=$rand;}else{$this->result["code"]= $result;$this->result["message"]="發(fā)送失敗!";$this->result["param"]=$rand;}}else{$this->result["code"]=-1;$this->result["message"]="短信配置信息有誤!";}}else{$this->result["code"]=-1;$this->result["message"]="短信通知模板有誤!";}}else{$this->result["code"]=-1;$this->result["message"]="店家沒有開啟短信驗(yàn)證";}return $this->result;}/*** 用戶綁定郵箱* @param string $params*/public function bindEmail($params=null){$rand = rand(100000,999999);$email=$params["email"];$shop_id=$params["shop_id"];$user_id=$params["user_id"];#查詢系統(tǒng)配置信息$this->getShopNotifyInfo($shop_id);if(!empty($email) && $this->email_is_open==1){$template_obj=$this->getTemplateDetail($shop_id, "bind_email", "email");if(!empty($template_obj) && $template_obj["is_enable"]==1){$user_model=new UserModel();$user_obj=$user_model->get($user_id);$content=$template_obj["template_content"];$content=str_replace("{驗(yàn)證碼}", $rand, $content);$content=str_replace("{用戶名稱}", $user_obj["user_name"], $content);$this->result["param"]=$rand;if(!empty($this->email_host) && !empty($this->email_id) && !empty($this->email_pass) && !empty($this->email_addr)){$result=emailSend($this->email_host, $this->email_id, $this->email_pass, $this->email_addr, $email, $template_obj["template_title"], $content);if($result){$this->result["code"]=0;$this->result["message"]="發(fā)送成功!";}else{$this->result["code"]=-1;$this->result["message"]="發(fā)送失敗!";}}else{$this->result["code"]=-1;$this->result["message"]="郵箱配置信息有誤!";}}else{$this->result["code"]=-1;$this->result["message"]="郵箱通知模板有誤!";}}else{$this->result["code"]=-1;$this->result["message"]="店家沒有開啟郵箱驗(yàn)證";}return $this->result;} }?>修改完成之后,短信寶的接口替換完成了,但是niushop1.05這個(gè)版本用戶注冊成功后發(fā)送短信失敗這個(gè)BUG在此次演示中也修復(fù)了,只需要修改項(xiàng)目/data/service/Member.php中的registerMember方法,代碼如下:
public function registerMember($user_name, $password, $email, $mobile, $user_qq_id, $qq_info, $wx_openid, $wx_info, $wx_unionid){if(trim($user_name) != ""){$is_false = $this->verifyValue($user_name, $password, "plain");}else{if($mobile != "" && $email ==""){$is_false = $this->verifyValue($user_name, $password, "mobile");}else{$is_false = $this->verifyValue($user_name, $password, "email");}}if(!$is_false){return USER_WORDS_ERROR;}$res = parent::add($user_name, $password, $email, $mobile, 0, $user_qq_id, $qq_info, $wx_openid, $wx_info, $wx_unionid, 1);if ($res > 0) {if ($mobile) {$params['shop_id'] = 0;$params['user_id'] = $res;$result = runhook('Notify', 'registAfter', $params);}//獲取默認(rèn)會(huì)員等級(jí)id$member_level = new NsMemberLevelModel();$level_info = $member_level->getInfo(['is_default' => 1], 'level_id');$member_level = $level_info['level_id'];$member = new NsMemberModel();$data = array('uid' => $res,'member_name' => $user_name,'member_level'=>$member_level,'reg_time' => date("Y-m-d H:i:s", time()));$retval = $member->save($data);// 注冊會(huì)員送積分$promote_reward_rule = new PromoteRewardRule();// 添加關(guān)注switch (NS_VERSION) {case NS_VER_B2C:break;case NS_VER_B2C_FX:if (! empty($_SESSION['source_uid'])) {// 判斷當(dāng)前版本$nfx_user = new NfxUser();$nfx_user->userAssociateShop($res, 0, $_SESSION['source_uid']);} else {// 判斷當(dāng)前版本$nfx_user = new NfxUser();$nfx_user->userAssociateShop($res, 0, 0);}break;}// 平臺(tái)贈(zèng)送積分$promote_reward_rule->RegisterMemberSendPoint(0, $res);// 直接登錄if (! empty($user_name)) {$this->login($user_name, $password);} elseif (! empty($mobile)) {$this->login($mobile, $password);} elseif (! empty($user_qq_id)) {$this->qqLogin($user_qq_id);} elseif (! empty($wx_openid)) {$this->wchatLogin($wx_openid);} elseif (! empty($wx_unionid)) {$this->wchatUnionLogin($wx_unionid);}}return $res;}這樣用戶注冊成功后也可以發(fā)送短信通知了,我們在添加短信模版的時(shí)候,會(huì)發(fā)現(xiàn)超過50個(gè)字符后的文字是沒有的,這是因?yàn)樵跀?shù)據(jù)庫中限制了模版的長度為50,我們只需要修改一下字段長度就可以了。在項(xiàng)目/application/shop/controller創(chuàng)建一個(gè)Smsbao.php文件,代碼如下:
<?php /*** Smsbao.php* 短信寶插件安裝,修改模板字段長度*/ namespace app\shop\controller; use think\Controller; use think\Db; class Smsbao extends Controller {/*** 修改長度為255*/public function index(){Db::query("alter table sys_notice_template modify column template_title varchar(255) not null");echo '短信寶插件安裝成功';} }我們只需要訪問 域名/shop/Smsbao.php看到短信寶插件安裝成功就證明字段修改成功。
經(jīng)過以上的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。
給大家?guī)讉€(gè)示例模版:
注冊成功:恭喜你成功注冊為shop_name的會(huì)員,會(huì)員名稱為:user_tel。 
 注:注冊成功發(fā)送短信僅限手機(jī)注冊,手機(jī)注冊會(huì)員名稱為手機(jī)號(hào),不能填寫user_name.
注冊驗(yàn)證:您的驗(yàn)證碼為:number,請(qǐng)不要告訴他人。
充值成功:user_name你好,恭喜你在shop_name充值成功,充值金額為:recharge_money。
確認(rèn)訂單:user_name你好,恭喜你在shop_name購物成功,訂單號(hào)為:order_no,訂單金額為:order_money,有任何疑問請(qǐng)咨詢客服。
付款成功:user_name你好,恭喜你在shop_name付款成功,訂單號(hào)為:order_no,訂單金額為:order_money,有任何疑問請(qǐng)咨詢客服。
下單成功:user_name你好,恭喜你在shop_name下單成功,訂單號(hào)為:order_no,訂單金額為:order_money,有任何疑問請(qǐng)咨詢客服。
總結(jié)
以上是生活随笔為你收集整理的niushop商城系统短信接口替换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 使用 gmail_如何更好地使用Gmai
- 下一篇: 网易云课堂数据分析师教程(云盘下载)
