螢火小程序商城,是一款開源的電商系統(tǒng),為中小企業(yè)提供最佳的新零售解決方案。采用穩(wěn)定的MVC框架開發(fā),執(zhí)行效率、擴(kuò)展性、穩(wěn)定性值得信賴。永久更新維護(hù),界面美觀大方。小編對(duì)他還是比較了解的,今天小編就以新增短信接口為例,給大家講解一下如何進(jìn)行二次開發(fā),我們今天講解的是2.0版本,使用的短信接口是我們短信寶短信群發(fā)平臺(tái)的短信接口,我們短信寶短信群發(fā)平臺(tái)的接口非常穩(wěn)定,發(fā)送速度快,注冊就送測試短信,推薦大家使用
1:打開項(xiàng)目:app\common\library\sms\Config.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
|
public static function getEasySmsConfig(array $smsConfig): array { return [ // HTTP 請求的超時(shí)時(shí)間(秒) 'timeout' => 5.0, // 默認(rèn)發(fā)送配置 'default' => [ // 網(wǎng)關(guān)調(diào)用策略,默認(rèn):順序調(diào)用 'strategy' => OrderStrategy::class, // 默認(rèn)可用的發(fā)送網(wǎng)關(guān) 'gateways' => [$smsConfig[ 'default' ]], ], // 可用的網(wǎng)關(guān)配置 'gateways' => [ 'aliyun' => [ 'access_key_id' => $smsConfig[ 'engine' ][ 'aliyun' ][ 'AccessKeyId' ], 'access_key_secret' => $smsConfig[ 'engine' ][ 'aliyun' ][ 'AccessKeySecret' ], 'sign_name' => $smsConfig[ 'engine' ][ 'aliyun' ][ 'sign' ], ], 'qcloud' => [ 'sdk_app_id' => $smsConfig[ 'engine' ][ 'qcloud' ][ 'SdkAppID' ], 'secret_id' => $smsConfig[ 'engine' ][ 'qcloud' ][ 'AccessKeyId' ], 'secret_key' => $smsConfig[ 'engine' ][ 'qcloud' ][ 'AccessKeySecret' ], 'sign_name' => $smsConfig[ 'engine' ][ 'qcloud' ][ 'sign' ], ], 'qiniu' => [ 'access_key' => $smsConfig[ 'engine' ][ 'qiniu' ][ 'AccessKey' ], 'secret_key' => $smsConfig[ 'engine' ][ 'qiniu' ][ 'SecretKey' ], ], 'smsbao' => [ 'user' => $smsConfig[ 'engine' ][ 'smsbao' ][ 'user' ], 'password' => $smsConfig[ 'engine' ][ 'smsbao' ][ 'password' ], ], ] ]; } |
2:打開項(xiàng)目:app\common\library\sms\Driver.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
32
33
|
public function sendSms(string $acceptPhone, string $templateCode, array $templateParams): bool { // 實(shí)例化EasySms $easySmsConfig = Config::getEasySmsConfig($ this ->smsConfig); $easySms = new EasySms($easySmsConfig); try { // 執(zhí)行發(fā)送短信 $result = $easySms->send($acceptPhone, [ 'content' => function ($gateway)use($templateParams,$templateCode){ return str_replace( '${' .array_keys($templateParams)[0]. '}' ,array_values($templateParams)[0],$templateCode); }, 'template' => $templateCode, 'data' => $ this ->getSmsTemplateData($templateParams), ]); // 短信發(fā)送成功的錯(cuò)誤處理 $sendStatus = $ this ->resultHandle($result); } catch (NoGatewayAvailableException $e) { // 短信發(fā)送異常的錯(cuò)誤處理 $sendStatus = false ; $ this ->exceptionHandle($e); } // 記錄日志 helper::logInfo( '發(fā)送短信' , [ 'gateway' => $ this ->smsConfig[ 'default' ], 'acceptPhone' => $acceptPhone, 'templateCode' => $templateCode, 'templateParams' => $templateParams, 'sendStatus' => $sendStatus, ]); // 存在異常時(shí)拋錯(cuò) $sendStatus === false && throwError($ this ->getError()); return $sendStatus; } |
3:打開項(xiàng)目:app\common\model\store\Setting.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
|
SettingEnum::SMS => [ 'key' => SettingEnum::SMS, 'describe' => '短信通知' , 'values' => [ 'default' => 'aliyun' , // 短信服務(wù)渠道 'engine' => [ // 阿里云 'aliyun' => [ 'name' => '阿里云短信' , 'AccessKeyId' => '' , 'AccessKeySecret' => '' , 'sign' => '螢火商城' // 短信簽名 ], // 騰訊云 'qcloud' => [ 'name' => '騰訊云短信' , 'SdkAppID' => '' , 'AccessKeyId' => '' , 'AccessKeySecret' => '' , 'sign' => '螢火商城' // 短信簽名 ], // 七牛云 'qiniu' => [ 'name' => '七牛云短信' , 'AccessKey' => '' , 'SecretKey' => '' , 'sign' => '螢火商城' // 短信簽名 ], // 短信寶 'smsbao' => [ 'name' => '短信寶短信' , 'user' => '' , 'password' => '' , ], ], // 短信通知場景 'scene' => [ // 短信驗(yàn)證碼 SettingSmsSceneEnum::CAPTCHA => [ 'name' => '短信驗(yàn)證碼 (通知用戶)' , // 場景名稱 'isEnable' => false , // 是否開啟 'templateCode' => '' , // 模板ID 'content' => '驗(yàn)證碼%s,您正在進(jìn)行身份驗(yàn)證,打死不要告訴別人哦!' , 'variables' => [ 'aliyun' => [ '${code}' ], 'qiniu' => [ '${code}' ], 'smsbao' => [ '${code}' ], 'qcloud' => [ '{1}' ], ] ], // 新付款訂單 SettingSmsSceneEnum::ORDER_PAY => [ 'name' => '新付款訂單 (通知商家)' , // 場景名稱 'isEnable' => false , // 是否開啟 'templateCode' => '' , // 模板ID 'acceptPhone' => '' , // 接收手機(jī)號(hào) 'content' => '您有一條新訂單,訂單號(hào)為:%s,請注意查看' , 'variables' => [ 'aliyun' => [ '${order_no}' ], 'qiniu' => [ '${order_no}' ], 'smsbao' => [ '${order_no}' ], 'qcloud' => [ '{1}' ], ] ], ] ], ], |
4:打開前端項(xiàng)目:src\views\setting\Sms.vue 大概72行增加短信寶頁面(此處修改后需要編譯)
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
|
<div v-show= "form.getFieldValue('default') === 'qcloud'" > <a-form-item label= "SdkAppID" :labelCol= "labelCol" :wrapperCol= "wrapperCol" required> <a-input v-decorator= "[`engine.qcloud.SdkAppID`]" /> </a-form-item> <a-form-item label= "AccessKeyId" :labelCol= "labelCol" :wrapperCol= "wrapperCol" required> <a-input v-decorator= "[`engine.qcloud.AccessKeyId`]" /> </a-form-item> <a-form-item label= "AccessKeySecret" :labelCol= "labelCol" :wrapperCol= "wrapperCol" required > <a-input v-decorator= "[`engine.qcloud.AccessKeySecret`]" /> </a-form-item> <a-form-item label= "短信簽名 Sign" :labelCol= "labelCol" :wrapperCol= "wrapperCol" required> <a-input v-decorator= "[`engine.qcloud.sign`]" /> </a-form-item> </div> <!-- 七牛云配置 --> <div v-show= "form.getFieldValue('default') === 'qiniu'" > <a-form-item label= "AccessKey" :labelCol= "labelCol" :wrapperCol= "wrapperCol" required> <a-input v-decorator= "[`engine.qiniu.AccessKey`]" /> </a-form-item> <a-form-item label= "SecretKey" :labelCol= "labelCol" :wrapperCol= "wrapperCol" required> <a-input v-decorator= "[`engine.qiniu.SecretKey`]" /> </a-form-item> </div> <!-- 短信寶配置 --> <div v-show= "form.getFieldValue('default') === 'smsbao'" > <a-form-item label= "user" :labelCol= "labelCol" :wrapperCol= "wrapperCol" required> <a-input v-decorator= "[`engine.smsbao.user`]" /> </a-form-item> <a-form-item label= "password" :labelCol= "labelCol" :wrapperCol= "wrapperCol" required> <a-input v-decorator= "[`engine.smsbao.password`]" /> </a-form-item> </div> |
經(jīng)過上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行測試發(fā)送:
報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開發(fā)好完整的yoshopV2.0系統(tǒng)短信寶插件,點(diǎn)擊此鏈接?下載及查看安裝流程。
最新更新
電商類
CMS類
微信類