WeCenter是一款知識型的社交化問答開源社區程序,專注于企業和行業社區內容的整理、歸類、檢索和再發行。 是中國首個基于 PHP + MYSQL 開發的開源化社交問答社區。今天小編為大家講解weCenter_4.1.1版本的短信接口替換,使用的接口是我們短信寶群發平臺的短信接口,我們短信寶群發短信平臺非常穩定,發送速度快,注冊還送測試短信,推薦大家使用。
1:打開項目:\app\frontend\Account.php 修改短信開關方法 大概在179行
1
2
3
4
|
$register_type = $ this ->settings[ 'register_type' ]; if (($register_type == 'mobile' || $register_type == 'all' ) && !(get_plugins_config( 'sms' , 'base' ) && get_plugins_config( 'sms' , 'base' )!= 'N' )) { $ this ->error( '網站尚未安裝或配置短信插件' , (string) url( 'account/register' )); } |
2:打開項目:\plugins目錄增加smsbao插件目錄
1
2
3
4
5
6
7
|
- 目錄結構如下 - smsbao -- config.php基本配置信息 -- info.php是插件的說明、配置、菜單信息 -- Plugin.php 短信發送函數 -- install.sql 安裝插件時數據庫操作腳本 -- uninstall.sql 卸載插件時數據庫操作腳本 |
3:短信核心發送函數在Plugin.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
|
<?php namespace plugins\smsbao; use app\common\controller\Plugins; use think\facade\Cache; class Plugin extends Plugins { /** * 安裝前的業務處理,可在此方法實現,默認返回true */ public function install() { return true ; } /** * 卸載前的業務處理,可在此方法實現,默認返回true */ public function uninstall() { return true ; } public function enable() { return true ; } public function disable() { return true ; } public function sms($param=[]) { $smsConfig = $ this ->getConfig(); if ($smsConfig[ 'base' ][ 'enable' ]== 'N' ) { return json_encode([ 'code' =>0, 'msg' => '短信功能未啟用' ], JSON_UNESCAPED_UNICODE); } //短信寶短信 if ($smsConfig[ 'base' ][ 'enable' ]== 'smsbao' ) { $sms_user = $smsConfig[ 'smsbao' ][ 'sms_user' ]; $sms_pwd = md5($smsConfig[ 'smsbao' ][ 'sms_pwd' ]); // 簽名 $smsSign = $smsConfig[ 'smsbao' ][ 'SignName' ]; // 模板 $template = $smsConfig[ 'smsbao' ][ 'TemplateCode' ]; $statusStr = array( "0" => "短信發送成功" , "-1" => "參數不全" , "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!" , "30" => "密碼錯誤" , "40" => "賬號不存在" , "41" => "余額不足" , "42" => "帳戶已過期" , "43" => "IP地址限制" , "50" => "內容含有敏感詞" ); try { /* 模板參數: 若無模板參數,則設置為空*/ $code = rand(100000,999999); $cache_code = Cache::get( 'sms_' .$param[ 'mobile' ]); // 通過 client 對象調用 SendSms 方法發起請求。注意請求方法名與請求對象是對應的 if (!$cache_code) { //發送短信 $content= '【' .$smsSign. '】' .str_replace( '{$code}' ,$code,$template); //要發送的短信內容 $phone = $param[ 'mobile' ]; //要發送短信的手機號碼 $sendurl = $smsapi. "sms?u=" .$sms_user. "&p=" .$sms_pwd. "&m=" .$phone. "&c=" .urlencode($content); $result =file_get_contents($sendurl) ; if ($result == '0' ) { Cache::set( 'sms_' .$param[ 'mobile' ],$code,60*5); return json_encode([ 'code' => 1, 'msg' => '短信發送成功' ], JSON_UNESCAPED_UNICODE); } else { return json_encode([ 'code' => 0, 'msg' => $statusStr[$result]], JSON_UNESCAPED_UNICODE); } } return json_encode([ 'code' =>0, 'msg' => '驗證碼5分鐘內有效,請使用收到驗證碼進行填寫' ],JSON_UNESCAPED_UNICODE); } catch (\Exception $e) { return json_encode([ 'code' =>0, 'msg' =>$e->getMessage()], JSON_UNESCAPED_UNICODE); } } return false ; } } |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的WeCenterV4.1.1系統短信寶插件,點擊此鏈接?下載及查看安裝流程。
最新更新
電商類
CMS類
微信類