小狐貍ai創作系統是一款基于ThinkPHP框架開發的開源AI問答小程序,它以小狐貍為形象,為用戶提供了智能而互動的聊天體驗。今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺的接口非常穩定,發送速度快,注冊就送測試短信,推薦大家使用
1:打開項目:config\sms.php 新增短信寶配置模板
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?php// +----------------------------------------------------------------------// | 短信寶短信設置// +----------------------------------------------------------------------return [ // 短信寶賬號 'sms_user' => '',//填寫短信寶賬號 // 短信寶密碼 'sms_password' => '',//填寫短信寶密碼 // 短信簽名 'sms_sign' => '',//填寫短信簽名 // 短信模板 'sms_template' => "您的驗證碼是{code}。如非本人操作,請忽略本短信",]; |
2:打開項目:extend\FoxSms 新增Smsbao.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
|
<?phpnamespace FoxSms;class Smsbao{ private static $appid = ''; private static $appkey = ''; public function __construct($appid = '', $appkey = '') { self::$appid = $appid; self::$appkey = $appkey; } public function sendSms($phoneNumber, $templId, $params, $sign = '') { $statusStr = array( "0" => "短信發送成功", "-1" => "參數不全", "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!", "30" => "密碼錯誤", "40" => "賬號不存在", "41" => "余額不足", "42" => "帳戶已過期", "43" => "IP地址限制", "50" => "內容含有敏感詞" ); $user =self::$appid; //短信平臺帳號 $pass = md5(self::$appkey); //短信平臺密碼 $sign = '【'.$sign.'】'; $content= $sign.str_replace('{code}',$params['code'],$templId); $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phoneNumber."&c=".urlencode($content); $result =file_get_contents($sendurl) ; if ($result == '0'){ return [ 'errno' => 0 ]; } return [ 'errno' => 1, 'message' => $statusStr[$result] ]; }} |
3:打開項目:app\common.php 修改發送函數 大概547行
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
function sendSms($site_id, $type, $phone, $param = []){ $config = getSystemSetting($site_id, 'sms'); $channel = empty($config['channel']) ? 'smsbao' : $config['channel']; if ($channel == 'smsbao') { $Sms = new \FoxSms\Smsbao(config('sms')['sms_user'],config('sms')['sms_password']); return $Sms->sendSms($phone, config('sms')['sms_template'],$param, config('sms')['sms_sign']); } elseif ($channel == 'tencent') { $Sms = new \FoxSms\Tencent($config['tencent_appid'], $config['tencent_appkey']); $tempId = $config['tencent_' . $type . '_tpl']; $signName = $config['tencent_signname']; $params = []; foreach ($param as $v) { $params[] = $v; } return $Sms->sendSms($phone, $tempId, $params, $signName); } else { return [ 'errno' => 1, 'message' => '未啟用短信功能' ]; }} |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的小狐貍AI_V2.2.2系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類