本插件系互億無(wú)線針對(duì)ECJia到家V1.37.0開(kāi)發(fā),請(qǐng)按以下說(shuō)明進(jìn)行安裝,插件內(nèi)的所有文件均為對(duì)原文件的修改,如果你的系統(tǒng)經(jīng)過(guò)二次開(kāi)發(fā),安裝本插件之前,請(qǐng)仔細(xì)核對(duì)修改。
ECJia到家發(fā)送驗(yàn)證碼短信及通知短信
1:打開(kāi)項(xiàng)目:\vendor\royalcms\sms\config\sms.php 修改短信配置方面
env('SMS_DEFAULT', 'ihuyi'), 'fallback' => env('SMS_FALLBACK'), 'signName' => env('SMS_SIGNNAME'), 'agents' => [ /* * 互億無(wú)線 */ 'ihuyi' => [ 'credentials' => [ 'appKey' => env('IHUYI_APPKEY'), 'appSecret' => env('IHUYI_APPSECRET'), ], 'executableFile' => 'Ihuyi', ], ], ];
2:打開(kāi)項(xiàng)目\vendor\royalcms\sms\Royalcms\Component\Sms\Agents\ 創(chuàng)建ihuyi.php
config = $config; $this->transformConfig(); } public function transformConfig() { $credentials = Arr::pull($this->config, 'credentials'); $this->appKey = Arr::pull($credentials, 'appKey'); $this->appSecret = Arr::pull($credentials, 'appSecret'); } protected function authParams() { return [ 'u' => $this->appKey, 'p' => $this->appSecret, ]; } /** * 發(fā)送信息 * * @see \Royalcms\Component\Sms\Contracts\SmsAgent::send() */ public function send($mobile) { $url = self::HOST.'account='.$this->appKey.'&password='.md5($this->appSecret).'&mobile='.$mobile.'&content='.$this->content.'&format=json'; $ret = file_get_contents($url); return $this->transformerResponse('send',json_decode($ret)); } /** * 查詢(xún)賬戶余額 */ public function balance() { $url = 'https://106.ihuyi.com/webservice/sms.php?method=GetNum&account='.$this->appKey.'&password='.md5($this->appSecret).'&format=json'; $ret = file_get_contents($url); return $this->transformerResponse('balance',json_decode($ret)); } /** * 轉(zhuǎn)換返回的信息處理 * @param array $response * @return array $result * @return int $result[].code 返回0則成功,返回其它則錯(cuò)誤 * @return string $result[].msg 返回消息 * @return string $result[].raw 接口返回的原生信息 * @return array $result[].data 數(shù)據(jù)信息 */ public function transformerResponse($type,$response) { if($type=='send'){ $result=new SendResponse(); $result->setMsgid($response['msg']); $result->setCode($response['code'] == '2' ? 0 : $response['code']); $result->setDescription($response['msg']); $result->getDescription($response['msg']); }else{ $result=new BalanceResponse(); $result->setBalance($response['num']); $result->setCode($response['code'] == '2' ? 0 : $response['code']); $result->setDescription($response['msg']); $result->getDescription($response['msg']); } return $result; } }
3:接著在項(xiàng)目\content\plugins\創(chuàng)建文件:sms_ihuyi\config.php
'sms_ihuyi', 'check_balance' => true, 'forms' => array( array('name' => 'app_key', 'type' => 'text', 'value' => ''), array('name' => 'app_secret', 'type' => 'text', 'value' => ''), ), );
4:接著在項(xiàng)目\content\plugins\sms_ihuyi\ 創(chuàng)建sms_ihuyi.class.php文件
setAgentConfig(); $this->agent = royalcms('sms')->driver('ihuyi'); } public function setAgentConfig() { RC_Config::set('sms::sms.agents.ihuyi.credentials', [ 'appKey' => $this->config['app_key'], 'appSecret' => $this->config['app_secret'], 'appsign' => $this->config['app_sign'] ]); } /** * 獲取插件代號(hào) * * @see \Ecjia\System\Plugin\PluginInterface::getCode() */ public function getCode() { return $this->loadConfig('sms_code'); } /** * 加載配置文件 * * @see \Ecjia\System\Plugin\PluginInterface::loadConfig() */ public function loadConfig($key = null, $default = null) { return $this->loadPluginData(RC_Plugin::plugin_dir_path(__FILE__) . 'config.php', $key, $default); } /** * 加載語(yǔ)言包 * * @see \Ecjia\System\Plugin\PluginInterface::loadLanguage() */ public function loadLanguage($key = null, $default = null) { $locale = RC_Config::get('system.locale'); return $this->loadPluginData(RC_Plugin::plugin_dir_path(__FILE__) . '/languages/'.$locale.'/plugin.lang.php', $key, $default); } } // end
5:接著在項(xiàng)目\content\plugins\sms_ihuyi\創(chuàng)建sms_ihuyi.php文件
__FILE__, 'config' => $config); return RC_Api::api('sms', 'plugin_install', $param); } public static function uninstall() { $config = include(RC_Plugin::plugin_dir_path(__FILE__) . 'config.php'); $param = array('file' => __FILE__, 'config' => $config); return RC_Api::api('sms', 'plugin_uninstall', $param); } public static function royalcms_sms_agent_filter($factories) { require_once RC_Plugin::plugin_dir_path(__FILE__) . 'Ihuyi.php'; $factories['ihuyi'] = 'Ihuyi'; return $factories; } } Ecjia_PluginManager::extend('sms_ihuyi', function() { require_once RC_Plugin::plugin_dir_path(__FILE__) . 'sms_ihuyi.class.php'; return new sms_ihuyi(); }); RC_Plugin::register_activation_hook(__FILE__, array('plugin_sms_ihuyi', 'install')); RC_Plugin::register_deactivation_hook(__FILE__, array('plugin_sms_ihuyi', 'uninstall')); RC_Hook::add_filter('royalcms_sms_agent_filter', array( 'plugin_sms_ihuyi', 'royalcms_sms_agent_filter' )); // end
6:接著在項(xiàng)目\content\plugins\sms_ihuyi\創(chuàng)建ihuyi.php文件
config = $config; $this->transformConfig(); } public function transformConfig() { $credentials = Arr::pull($this->config, 'credentials'); $this->appKey = Arr::pull($credentials, 'appKey'); $this->appSecret = Arr::pull($credentials, 'appSecret'); } protected function authParams() { return [ 'u' => $this->appKey, 'p' => $this->appSecret, ]; } /** * 發(fā)送信息 * * @see \Royalcms\Component\Sms\Contracts\SmsAgent::send() */ public function send($mobile) { $url = self::HOST.'account='.$this->appKey.'&password='.md5($this->appSecret).'&mobile='.$mobile.'&content='.$this->content.'&format=json'; $ret = file_get_contents($url); return $this->transformerResponse('send',json_decode($ret)); } /** * 查詢(xún)賬戶余額 */ public function balance() { $url = 'https://106.ihuyi.com/webservice/sms.php?method=GetNum&account='.$this->appKey.'&password='.md5($this->appSecret).'&format=json'; $ret = file_get_contents($url); return $this->transformerResponse('balance',json_decode($ret)); } /** * 轉(zhuǎn)換返回的信息處理 * @param array $response * @return array $result * @return int $result[].code 返回0則成功,返回其它則錯(cuò)誤 * @return string $result[].msg 返回消息 * @return string $result[].raw 接口返回的原生信息 * @return array $result[].data 數(shù)據(jù)信息 */ public function transformerResponse($type,$response) { if($type=='send'){ $result=new SendResponse(); $result->setMsgid($response['msg']); $result->setCode($response['code'] == '2' ? 0 : $response['code']); $result->setDescription($response['msg']); $result->getDescription($response['msg']); }else{ $result=new BalanceResponse(); $result->setBalance($response['num']); $result->setCode($response['code'] == '2' ? 0 : $response['code']); $result->setDescription($response['msg']); $result->getDescription($response['msg']); } return $result; } }
7:最后在項(xiàng)目\content\plugins\sms_ihuyi\創(chuàng)建新的文件夾languages\zh_CN\,名為:plugin.lang.php文件
'ihuyi的APIID:', 'app_secret' => 'ihuyi的APIKEY:', ); // end
經(jīng)過(guò)上面的替換,互億無(wú)線的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行測(cè)試發(fā)送
驗(yàn)證碼已發(fā)送到您的手機(jī),請(qǐng)查收!
輸入驗(yàn)證碼后,點(diǎn)擊“開(kāi)通體驗(yàn)賬戶”按鈕可立即開(kāi)通體驗(yàn)賬戶。