WeCenter是一款知識(shí)型的社交化問(wèn)答開(kāi)源社區(qū)程序,專(zhuān)注于企業(yè)和行業(yè)社區(qū)內(nèi)容的整理、歸類(lèi)、檢索和再發(fā)行。 是中國(guó)首個(gè)基于 PHP + MYSQL 開(kāi)發(fā)的開(kāi)源化社交問(wèn)答社區(qū)。今天小編為大家講解weCenter_4.1.0版本的短信接口替換,使用的接口是我們短信寶群發(fā)平臺(tái)的短信接口,我們短信寶群發(fā)短信平臺(tái)非常穩(wěn)定,發(fā)送速度快,注冊(cè)還送測(cè)試短信,推薦大家使用。
1:打開(kāi)項(xiàng)目:\app\frontend\Account.php 修改短信開(kāi)關(guān)方法 大概在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( '網(wǎng)站尚未安裝或配置短信插件' , (string) url( 'account/register' )); } |
2:打開(kāi)項(xiàng)目:\plugins目錄增加smsbao插件目錄
1
2
3
4
5
6
7
|
- 目錄結(jié)構(gòu)如下 - smsbao -- config.php基本配置信息 -- info.php是插件的說(shuō)明、配置、菜單信息 -- Plugin.php 短信發(fā)送函數(shù) -- install.sql 安裝插件時(shí)數(shù)據(jù)庫(kù)操作腳本 -- uninstall.sql 卸載插件時(shí)數(shù)據(jù)庫(kù)操作腳本 |
3:短信核心發(fā)送函數(shù)在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 { /** * 安裝前的業(yè)務(wù)處理,可在此方法實(shí)現(xiàn),默認(rèn)返回true */ public function install() { return true ; } /** * 卸載前的業(yè)務(wù)處理,可在此方法實(shí)現(xiàn),默認(rèn)返回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" => "短信發(fā)送成功" , "-1" => "參數(shù)不全" , "-2" => "服務(wù)器空間不支持,請(qǐng)確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!" , "30" => "密碼錯(cuò)誤" , "40" => "賬號(hào)不存在" , "41" => "余額不足" , "42" => "帳戶(hù)已過(guò)期" , "43" => "IP地址限制" , "50" => "內(nèi)容含有敏感詞" ); try { /* 模板參數(shù): 若無(wú)模板參數(shù),則設(shè)置為空*/ $code = rand(100000,999999); $cache_code = Cache::get( 'sms_' .$param[ 'mobile' ]); // 通過(guò) client 對(duì)象調(diào)用 SendSms 方法發(fā)起請(qǐng)求。注意請(qǐng)求方法名與請(qǐng)求對(duì)象是對(duì)應(yīng)的 if (!$cache_code) { //發(fā)送短信 $content= '【' .$smsSign. '】' .str_replace( '{$code}' ,$code,$template); //要發(fā)送的短信內(nèi)容 $phone = $param[ 'mobile' ]; //要發(fā)送短信的手機(jī)號(hào)碼 $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' => '短信發(fā)送成功' ], JSON_UNESCAPED_UNICODE); } else { return json_encode([ 'code' => 0, 'msg' => $statusStr[$result]], JSON_UNESCAPED_UNICODE); } } return json_encode([ 'code' =>0, 'msg' => '驗(yàn)證碼5分鐘內(nèi)有效,請(qǐng)使用收到驗(yàn)證碼進(jìn)行填寫(xiě)' ],JSON_UNESCAPED_UNICODE); } catch (\Exception $e) { return json_encode([ 'code' =>0, 'msg' =>$e->getMessage()], JSON_UNESCAPED_UNICODE); } } return false ; } } |
經(jīng)過(guò)上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行測(cè)試發(fā)送:
報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開(kāi)發(fā)好完整的WeCenterV4.1.0系統(tǒng)短信寶插件,點(diǎn)擊此鏈接?下載及查看安裝流程。
最新更新
電商類(lèi)
CMS類(lèi)
微信類(lèi)