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


待發短信

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

4001-021-502

工作時間

9:00-21:00

CRMEBV4.32新增短信寶短信接口

CRMEB商城系統是基于ThinkPhp6.0+Vue開發的一套新零售移動電商開源系統,包含商城、拼團、砍價、秒殺、優惠券、積分、分銷等功能,更適合企業二次開發。今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺的接口非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
前提:執行以下sql語句增加短信寶配置

1
2
3
4
5
6
7
INSERT INTO `eb_system_config_tab` (`id`, `pid`, `title`, `eng_title`, `status`, `info`, `icon`, `type`, `sort`) VALUES ('100''0''短信配置''smsbao''1''0''ios-chatboxes''0''0');
INSERT INTO `eb_system_config` ( `menu_name`, `type`, `input_type`, `config_tab_id`, `parameter`, `upload_type`, `required`, `width`, `high`, `value`, `info`, `desc`, `sort`, `status`)
VALUES ('smsbao_user''text''input''100''', 0, '''100', 0, '''短信寶賬號''短信寶賬號''0''1');
INSERT INTO `eb_system_config` ( `menu_name`, `type`, `input_type`, `config_tab_id`, `parameter`, `upload_type`, `required`, `width`, `high`, `value`, `info`, `desc`, `sort`, `status`)
VALUES ('smsbao_pwd''text''input''100''', 0, '''100', 0, '''短信寶密碼''短信寶密碼''0''1');
INSERT INTO `eb_system_config` ( `menu_name`, `type`, `input_type`, `config_tab_id`, `parameter`, `upload_type`, `required`, `width`, `high`, `value`, `info`, `desc`, `sort`, `status`)
VALUES ('sms_sign_name''text''input''100''', 0, '''100', 0, '''短信簽名''短信簽名''0''1');

1:打開項目:config\sms.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
'smsbao'=>[
     'template_id' => [
                //驗證碼
                'VERIFICATION_CODE_TIME' => '您的驗證碼是code,有效期為time分鐘。如非本人操作,可不用理會。',
                //支付成功
                'PAY_SUCCESS_CODE' => '您購買的商品已支付成功,支付金額pay_price元,訂單號order_id,感謝您的光臨!',
                //發貨提醒
                'DELIVER_GOODS_CODE' => '親愛的用戶nickname您的商品store_name,訂單號order_id已發貨,請注意查收',
                //確認收貨提醒
                'TAKE_DELIVERY_CODE' => '親,您的訂單order_id,商品store_name已確認收貨,感謝您的光臨!',
                //管理員下單提醒
                'ADMIN_PLACE_ORDER_CODE' => 'admin_name管理員,您有一筆已支付的訂單待處理,訂單號為order_id!',
                //管理員退貨提醒
                'ADMIN_RETURN_GOODS_CODE' => 'admin_name管理員,您有一筆支付成功的訂單待處理,訂單號order_id!',
                //管理員支付成功提醒
                'ADMIN_PAY_SUCCESS_CODE' => 'admin_name管理員,您有一筆支付成功的訂單待處理,訂單號order_id!',
                //管理員確認收貨
                'ADMIN_TAKE_DELIVERY_CODE' => 'admin_name管理員,您有一筆訂單已經確認收貨,訂單號order_id!',
                //改價提醒
                'PRICE_REVISION_CODE' => '您的訂單order_id,實際支付金額已被修改為pay_price',
                //訂單未支付
                'ORDER_PAY_FALSE' => '您有未付款訂單,訂單號為:order_id,商品數量有限,請及時付款。',
             ],
        ]

2:打開項目:crmeb\services\sms\Sms.php 屏蔽掉invokeClass方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    // protected function invokeClass($class)
    // {
    //     if (!class_exists($class)) {
    //         throw new \RuntimeException('class not exists: ' . $class);
    //     }
    //     $this->getConfigFile();
 
    //     if (!$this->config) {
    //         $this->config = Config::get($this->configFile . '.stores.' . $this->name, []);
    //     }
 
    //     $handleAccessToken = new AccessTokenServeService($this->config['account'] ?? '', $this->config['secret'] ?? '');
    //     $handle = Container::getInstance()->invokeClass($class, [$this->name, $handleAccessToken, $this->configFile]);
    //     $this->config = [];
    //     return $handle;
    // }

3:打開項目:crmeb\services\sms\storage 新增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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
 
namespace crmeb\services\sms\storage;
 
use crmeb\basic\BaseSms;
use think\exception\ValidateException;
use think\facade\Config;
 
class SmsBao extends BaseSms
{
    /**
     * accessKeyId
     * @var string
     */
    protected $accessKeyId;
    /**
     * accessKeySecret
     * @var string
     */
    protected $accessKeySecret;
    /**
     * 簽名
     * @var string
     */
    protected $signName = '';
 
    protected $name = 'smsbao';
    /**
     * 狀態
     * @var bool
     */
    protected $status;
    protected $templateIds = [];
    protected function initialize(array $config)
    {
        parent::initialize($config);
        $this->accessKeyId = sys_config('smsbao_user''');
        $this->accessKeySecret = sys_config('smsbao_pwd''');
        if ($this->accessKeyId && $this->accessKeySecret) {
            $this->status = true;
        else {
            $this->status = false;
        }
        $this->signName = $config['sign_name'] ?? null;
        if($this->signName == null){
            $this->signName  = sys_config('sms_sign_name''');
        }
        $this->templateIds = Config::get($this->configFile . '.stores.' . $this->name . '.template_id', []);
    }
    /**
     * 提取模板code
     * @param string $templateId
     * @return null
     */
    protected function getTemplateCode(string $templateId)
    {
        return $this->templateIds[$templateId] ?? null;
    }
    /**
     * 發送短信
     * @param $phone
     * @param $templateId
     * @param $data
     * @return bool|string
     */
    public function send($phone, $templateId, array $data = [])
    {
        $statusStr = array(
            "0" => "短信發送成功",
            "-1" => "參數不全",
            "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!",
            "30" => "密碼錯誤",
            "40" => "賬號不存在",
            "41" => "余額不足",
            "42" => "帳戶已過期",
            "43" => "IP地址限制",
            "50" => "內容含有敏感詞"
            );
 
        $smsapi = ";
        $user = $this->accessKeyId;
        $pass = md5($this->accessKeySecret);
        $tmp = $this->getTemplateCode($templateId);
        $content = str_replace(array_keys($data),array_values($data),$tmp);
        $content = '【'.$this->signName.'】'.$content;
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
        $result = $this->fetchContent($sendurl,'POST','') ;
        try {
            if($result == '0'){
                return true;
            }else{
                throw new ValidateException($statusStr[$result]);
            }
        }catch (\Exception $e) {
            throw new ValidateException($e->getMessage());
        }
    }
 
    private function fetchContent($url, $method, $body) {
        $ch = curl_init();
 
        if($method == 'POST') {
            curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
            curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
        else {
            $url .= '?'.$body;
        }
 
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "x-sdk-client" => "php/2.0.0"
        ));
 
        if(substr($url, 0,5) == 'https') {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
 
        $rtn = curl_exec($ch);
 
        if($rtn === false) {
            // 大多由設置等原因引起,一般無法保障后續邏輯正常執行,
            // 所以這里觸發的是E_USER_ERROR,會終止腳本執行,無法被try...catch捕獲,需要用戶排查環境、網絡等故障
            trigger_error("[CURL_" . curl_errno($ch) . "]: " . curl_error($ch), E_USER_ERROR);
        }
        curl_close($ch);
 
        return $rtn;
    }
}

4:打開項目:app\services\serve\ServeServices.php 修改驅動配置 大概在60行左右

1
2
3
4
5
6
7
8
9
10
    public function sms(array $config = [])
    {
        return app()->make(Sms::class, [    
            'smsbao',
        [
            'accessKeyId' => sys_config('smsbao_user'),
            'accessKeySecret' => sys_config('smsbao_pwd'),
            'signName' => sys_config('sms_sign_name'),
        ]]);
    }

經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:

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

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

開源插件

最新更新

電商類

CMS類

微信類

文章標簽