91成人在线播放_欧美一区二区视频在线观看_91精品国产高清久久久久久_国产精品久久亚洲不卡4k岛国


待發短信

在線客服
產品支持 短信寶客服
合作渠道 渠道合作
服務咨詢

4001-021-502

工作時間

9:00-21:00

niushopV6版新增短信寶短信接口

NIUSHOP V6 使用NIUCLOUD-ADMIN底層框架設計, 國內首家唯一支持TP8框架 ,前端采用市面最流行的技術棧 Vite+TypeScript+Vue3+ElementPlus ,后端采用 THINKPHP8、PHP8 語言搭建。今天小編以新增短信接口為例告訴大家如何進行二次開發,使用的短信接口是我們短信寶短信群發平臺的接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
下面具體給大家說一下每個文件的作用及代碼。
1:在niucloud\app\dict\sys\SmsDict.php大約25行左右增加短信寶枚舉類,代碼如下:

1
2
    //短信寶短信
    public const SMSBAO = 'smsbao';

接著在67行左右增加短信寶配置參數,代碼如下:

1
2
3
4
5
6
7
8
9
10
11
    self::SMSBAO => [
        'name' => '短信寶',
        //配置參數
        'params' => [
             'sign' => '短信簽名',
             'username' => '短信寶賬號',
             'secret_key' => 'APP_KEY'
        ],
        'encrypt_params' => [],
        'component' => '/src/app/views/setting/components/sms-smsbao.vue',
    ],

2:在niucloud\core\sms 目錄下 新增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
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
<?php
namespace core\sms;
 
use core\exception\NoticeException;
use Exception;
 
 
class Smsbao extends BaseSms
{
 
    protected $username = '';
    protected $secret_key = '';
    protected $sign = '';
    protected $smsapi = ";
    protected $statusStr = array(
        "0" => "短信發送成功",
        "-1" => "參數不全",
        "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!",
        "30" => "密碼錯誤",
        "40" => "賬號不存在",
        "41" => "余額不足",
        "42" => "帳戶已過期",
        "43" => "IP地址限制",
        "50" => "內容含有敏感詞"
        );
 
    /**
     * @param array $config
     * @return void
     */
    protected function initialize(array $config = [])
    {
        parent::initialize($config);
        $this->username = $config[ 'username' ] ?? '';
        $this->secret_key = $config[ 'secret_key' ] ?? '';
        $this->sign = $config[ 'sign' ] ?? '';
    }
 
 
    /**
     * 發送短信
     * @param string $mobile
     * @param string $template_id
     * @param array $data
     * @return array
     */
    public function send(string $mobile, string $template_id, array $data = [])
    {
        try {
            $search = array_map(function($key) {
                return '{' . $key . '}'// 將鍵轉換為 {key} 形式
            }, array_keys($data));
 
            $replace = array_values($data); // 替換內容為數組的值
            // 執行替換
            $content = str_replace($search, $replace, $template_id);
            $url = $this->smsapi.'?u='.$this->username.'&p='.$this->secret_key.'&m='.$mobile.'&c=【'.$this->sign.'】'.$content;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30 );
            $response = curl_exec($ch);
            curl_close($ch);
            throw new NoticeException($this->statusStr[$response]);
        catch (Exception $e) {
            throw new NoticeException($e->getMessage());
        }
    }
 
    public function modify(string $sign, string $mobile, string $code)
    {
    }
 
    public function template(int $page = 0, int $limit = 10, int $type = 1)
    {
    }
 
    public function apply(string $title, string $content, int $type)
    {
    }
 
    public function localTemplate(int $type, int $page, int $limit)
    {
    }
 
    public function record($id)
    {
    }
}

3:在admin\src\app\lang\zh-cn\setting.sms.json 文件中增加前端國際化變量參數

1
2
3
4
5
6
7
8
9
{
      "smsbao":"短信寶",
      "smsbaoSign":"短信簽名",
      "smsbaoUsername""短信寶賬號",
      "smsbaoApiKey""API_KEY",
      "smsbaoSignPlaceholder":"請輸入短信簽名",
      "smsbaoUsernamePlaceholder":"請輸入短信寶賬號",
      "smsbaoApiKeyPlaceholder":"請輸入API_KEY"
}

4:在admin\src\app\views\setting\components 目錄下新增 sms-smsbao.vue 短信寶配置文件

好了經過以上的添加,短信寶的短信平臺已經替換成功了,可以正常使用了

報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。

另外:我們已經開發好完整的niushopV6版系統短信寶插件,點擊此鏈接 下載及查看安裝流程。

開源插件

最新更新

電商類

CMS類

微信類

文章標簽