CRMEB商城系統(tǒng)是基于ThinkPhp6.0+Vue開發(fā)的一套新零售移動(dòng)電商開源系統(tǒng),包含商城、拼團(tuán)、砍價(jià)、秒殺、優(yōu)惠券、積分、分銷等功能,更適合企業(yè)二次開發(fā)。今天小編就以新增短信接口為例,給大家講解一下如何進(jìn)行二次開發(fā),使用的短信接口是我們短信寶短信群發(fā)平臺(tái)的短信接口,我們短信寶短信群發(fā)平臺(tái)的接口非常穩(wěn)定,發(fā)送速度快,注冊(cè)就送測(cè)試短信,推薦大家使用。
1: 打開項(xiàng)目:\app\admin\controller\sms\SmsConfig.php 修改大概28行代碼
1
2
3
4
5
6
7
8
9
10
|
public function index(){ $type = input( 'type' )!=0?input( 'type' ):0; $tab_id = input( 'tab_id' ); if (!$tab_id) $tab_id = 1; $ this ->assign( 'tab_id' ,$tab_id); $list = ConfigModel::getAll($tab_id)->toArray(); $list[0][ 'info' ] = '短信寶賬號(hào)' ; $list[0][ 'desc' ] = '短信寶賬號(hào)' ; $list[1][ 'info' ] = '短信寶密碼' ; $list[1][ 'desc' ] = '短信寶密碼' ; |
2: 打開項(xiàng)目:\app\admin\view\sms\sms_config\index.php 修改大概56行代碼
1
2
3
4
5
6
7
8
|
<div class= "ibox-content" > <div id= "app" > <Alert type= "success" >如果還沒有開通短信賬號(hào),可以<a target= "_blank" href= "http://www.gjrencai.com/reg" style= "color: #0000ff" >立即注冊(cè)</a> </Alert> </div> <div class= "p-m m-t-sm" id= "configboay" > </div> </div> |
3:打開項(xiàng)目:\app\admin\view\sms\sms_template_apply\index.php 修改大概45行代碼
1
2
3
|
<div class= "layui-btn-container" > <button type= "button" class= "layui-btn layui-btn-sm" onclick= "$eb.createModalFrame(this.innerText,'{:Url('create')}')" >添加模板</button> </div> |
4: 打開項(xiàng)目:\app\admin\controller\sms\SmsTemplateApply.php 修改模板相關(guān)方法
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
<?php namespace app\admin\controller\sms; use app\admin\controller\AuthController; use crmeb\services\FormBuilder; use crmeb\services\JsonService; use crmeb\services\SMSService; use crmeb\services\UtilService; use think\facade\Route; use app\admin\model\routine\RoutineTemplate as RoutineModel; /** * 短信模板申請(qǐng) * Class SmsTemplateApply * @package app\admin\controller\sms */ class SmsTemplateApply extends AuthController { /** * 顯示資源列表 * * @return string */ public function index() { // $sms = new SMSService(); // if(!$sms::$status) return $this->failed('請(qǐng)先填寫短信配置'); return $ this ->fetch(); } /** * 異步獲取模板列表 */ public function lst() { //重新獲取模板 $tem = new RoutineModel(); $lst = $tem->where( 'status' ,0)->select()->toArray(); foreach($lst as $k=>$v) { $lst[$k][ 'id' ]= $v[ 'id' ]; $lst[$k][ 'templateid' ]= $v[ 'tempid' ]; $lst[$k][ 'title' ]= $v[ 'name' ]; $lst[$k][ 'mark' ]= "" ; $lst[$k][ 'type' ]= $v[ 'tempkey' ]; $lst[$k][ 'status' ]= 1; $lst[$k][ 'content' ]= $v[ 'content' ]; $lst[$k][ 'add_time' ]= date( "Y-m-d H:i" , $v[ 'add_time' ]); } return JsonService::successlayui( '' ,$lst); } /** * 顯示創(chuàng)建資源表單頁(yè). * * @return string * @throws \FormBuilder\exception\FormBuilderException */ public function create() { $field = [ FormBuilder::input( 'title' , '模板名稱' ), FormBuilder::textarea( 'text' , '模板內(nèi)容示例' , '【您的短信簽名】您的驗(yàn)證碼是:{$code},有效期為{$time}分鐘。如非本人操作,可不用理會(huì)。模板中的{$code}和{$time}需要替換成對(duì)應(yīng)的變量,請(qǐng)開發(fā)者知曉。修改此項(xiàng)無(wú)效!' ), FormBuilder::input( 'content' , '模板內(nèi)容' )->type( 'textarea' ), FormBuilder::input( 'number' , '模板id' ), FormBuilder::radio( 'type' , '模板類型' ,1)->options([[ 'label' => '驗(yàn)證碼' , 'value' =>1],[ 'label' => '通知' , 'value' =>2],[ 'label' => '推廣' , 'value' =>3]]) ]; $form = FormBuilder::make_post_form( '申請(qǐng)短信模板' ,$field,Route::buildUrl( 'save' ),2); $ this ->assign(compact( 'form' )); return $ this ->fetch( 'public/form-builder' ); } /** * 保存新建的資源 */ public function save() { $tem = []; $data = UtilService::postMore([ [ 'title' , '' ], [ 'content' , '' ], [ 'type' ,0], [ 'number' , '' ] ]); //組裝數(shù)據(jù) $tem = array( 'tempkey' =>$data[ 'type' ], 'name' =>$data[ 'title' ], 'content' =>$data[ 'content' ], 'tempid' =>$data[ 'number' ], 'add_time' =>time() ); if (!strlen(trim($data[ 'title' ]))) return JsonService::fail( '請(qǐng)輸入模板名稱' ); if (!strlen(trim($data[ 'content' ]))) return JsonService::fail( '請(qǐng)輸入模板內(nèi)容' ); if (!strlen(trim($data[ 'number' ]))) return JsonService::fail( '請(qǐng)輸入模板id' ); $id = RoutineModel::insert($tem); if ($id) return JsonService::success( '申請(qǐng)成功' ); } } |
5:打開項(xiàng)目:\crmeb\services\SMSService.php 修改發(fā)送方法
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
|
public static function send($phone, $template, array $param) { $ret = []; self::auto(); $teModel = new RoutineTemplate(); $content = $teModel->where( 'tempid' ,$template)->find()[ 'content' ]; foreach($param as $key => $value) { $content = str_replace( '{$' . "$key" . '}' ,$value,$content); } $statusStr = array( "0" => "短信發(fā)送成功" , "-1" => "參數(shù)不全" , "-2" => "服務(wù)器空間不支持,請(qǐng)確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!" , "30" => "密碼錯(cuò)誤" , "40" => "賬號(hào)不存在" , "41" => "余額不足" , "42" => "帳戶已過期" , "43" => "IP地址限制" , "50" => "內(nèi)容含有敏感詞" ); $user = self::$SMSAccount; //短信平臺(tái)帳號(hào) $pass = md5(self::$SMSToken); //短信平臺(tái)密碼 $content = $content; //要發(fā)送的短信內(nèi)容 $phone = $phone; //要發(fā)送短信的手機(jī)號(hào)碼 $sendurl = $smsapi. "sms?u=" .$user. "&p=" .$pass. "&m=" .$phone. "&c=" .urlencode($content); $result = file_get_contents($sendurl) ; $ret[ "status" ] = $result; $ret[ "msg" ] = $statusStr[$result]; return $ret; } |
經(jīng)過上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行測(cè)試發(fā)送:
報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開發(fā)好完整的CRMEB_V3.12系統(tǒng)短信寶插件,點(diǎn)擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類