1:打開(kāi)項(xiàng)目:\common\framework\drivers\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
90
91
92
93
94
95
96
97
|
<?phpnamespace Rhymix\Framework\Drivers\SMS;/** * The CoolSMS SMS driver. */class SmsBao extends Base implements \Rhymix\Framework\Drivers\SMSInterface{ /** * API specifications. */ protected static $_spec = array( 'max_recipients' => 1000, 'sms_max_length' => 90, 'sms_max_length_in_charset' => 'CP949', 'lms_supported' => true, 'lms_supported_country_codes' => array(82), 'lms_max_length' => 2000, 'lms_max_length_in_charset' => 'CP949', 'lms_subject_supported' => true, 'lms_subject_max_length' => 40, 'mms_supported' => true, 'mms_supported_country_codes' => array(82), 'mms_max_length' => 2000, 'mms_max_length_in_charset' => 'CP949', 'mms_subject_supported' => true, 'mms_subject_max_length' => 40, 'image_allowed_types' => array('jpg', 'gif', 'png'), 'image_max_dimensions' => array(2048, 2048), 'image_max_filesize' => 300000, 'delay_supported' => true, ); /** * Config keys used by this driver are stored here. */ protected static $_required_config = array('api_key', 'api_secret'); /** * Check if the current SMS driver is supported on this server. * * This method returns true on success and false on failure. * * @return bool */ public static function isSupported() { return true; } /** * Send a message. * * This method returns true on success and false on failure. * * @param array $messages * @param object $original * @return bool */ public function send(array $messages, \Rhymix\Framework\SMS $original) { try { $sender = new \Nurigo\Api\Message($this->_config['api_key'], $this->_config['api_secret']); $status = true; foreach ($messages as $i => $message) { $statusStr = array( "0" => "短信發(fā)送成功", "-1" => "參數(shù)不全", "-2" => "服務(wù)器空間不支持,請(qǐng)確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!", "30" => "密碼錯(cuò)誤", "40" => "賬號(hào)不存在", "41" => "余額不足", "42" => "帳戶已過(guò)期", "43" => "IP地址限制", "50" => "內(nèi)容含有敏感詞" ); $user = $this->_config['api_key']; //短信平臺(tái)帳號(hào) $pass = md5($this->_config['api_secret']); //短信平臺(tái)密碼 $content=$message->content;//要發(fā)送的短信內(nèi)容 $phone = implode(',', $message->to);//要發(fā)送短信的手機(jī)號(hào)碼 $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content); $result =file_get_contents($sendurl) ; if ($result !=0) { $error_codes = implode(', ', $statusStr[$result] ?: array('Unknown')); $original->addError('Error (' . $error_codes . ') while sending message ' . ($i + 1) . ' of ' . count($messages) . ' to ' . $phone); $status = false; } } return $status; } catch (\Nurigo\Exceptions\CoolsmsException $e) { $message->errors[] = class_basename($e) . ': ' . $e->getMessage(); return false; } }} |
2:打開(kāi)項(xiàng)目:modules\member\member.controller.php 修改大概3559行代碼
|
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
|
function procMemberSendVerificationSMS(){ $config = MemberModel::getMemberConfig(); if ($config->phone_number_verify_by_sms !== 'Y') { throw new Rhymix\Framework\Exceptions\FeatureDisabled; } $phone_country = Context::get('phone_country'); $phone_number = Context::get('phone_number'); if ($config->phone_number_default_country && (!$phone_country || $config->phone_number_hide_country === 'Y')) { $phone_country = $config->phone_number_default_country; } if (preg_match('/[A-Z]{3}/', $phone_country)) { $phone_country_calling_code = preg_replace('/[^0-9]/', '', Rhymix\Framework\i18n::getCallingCodeByCountryCode($phone_country)); if (!$phone_country_calling_code) { return new BaseObject(-1, 'msg_invalid_phone_country'); } } else { return new BaseObject(-1, 'msg_invalid_phone_country'); } if (!preg_match('/[0-9]{2,}/', $phone_number)) { return new BaseObject(-1, 'msg_invalid_phone_number'); } if ($phone_country === 'KOR' && !Rhymix\Framework\Korea::isValidPhoneNumber($phone_number)) { return new BaseObject(-1, 'msg_invalid_phone_number'); } $is_special = ($config->special_phone_number && $config->special_phone_number === preg_replace('/[^0-9]/', '', $phone_number)); $code = intval(mt_rand(100000, 999999)); $_SESSION['verify_by_sms'] = array( 'country' => $phone_country, 'number' => $phone_number, 'code' => $is_special ? intval($config->special_phone_code) : $code, 'status' => false, ); if ($is_special) { return new BaseObject(0, 'verify_by_sms_code_sent'); } $sms = new Rhymix\Framework\SMS; $sms->addTo($phone_number, $phone_country_calling_code); $content = '【' . Context::get('site_module_info')->settings->title . '】 ' . sprintf(lang('member.verify_by_sms_message'), $code); $sms->setContent($content); $result = $sms->send(); if ($result && config('sms.type') !== 'dummy') { return new BaseObject(0, 'verify_by_sms_code_sent'); } else { return new BaseObject(0, 'verify_by_sms_error'); }} |
經(jīng)過(guò)上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行測(cè)試發(fā)送:
報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開(kāi)發(fā)好完整的Rhymix_V2.0.16系統(tǒng)短信寶插件,點(diǎn)擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類