本插件系互亿无线针对ECJia到家V1.37.0开发,请按以下说明进行安装,插件内的所有文件均为对原文件的修改,如果你的系统经过二次开发,安装本插件之前,请仔细核对修改。
ECJia到家发送验证码短信及通知短信
1:打开项目:\vendor\royalcms\sms\config\sms.php 修改短信配置方面
env('SMS_DEFAULT', 'ihuyi'), 'fallback' => env('SMS_FALLBACK'), 'signName' => env('SMS_SIGNNAME'), 'agents' => [ /* * 互亿无线 */ 'ihuyi' => [ 'credentials' => [ 'appKey' => env('IHUYI_APPKEY'), 'appSecret' => env('IHUYI_APPSECRET'), ], 'executableFile' => 'Ihuyi', ], ], ];
2:打开项目\vendor\royalcms\sms\Royalcms\Component\Sms\Agents\ 创建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, ]; } /** * 发送信息 * * @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)); } /** * 查询账户余额 */ 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)); } /** * 转换返回的信息处理 * @param array $response * @return array $result * @return int $result[].code 返回0则成功,返回其它则错误 * @return string $result[].msg 返回消息 * @return string $result[].raw 接口返回的原生信息 * @return array $result[].data 数据信息 */ 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:接着在项目\content\plugins\创建文件: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:接着在项目\content\plugins\sms_ihuyi\ 创建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'] ]); } /** * 获取插件代号 * * @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); } /** * 加载语言包 * * @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:接着在项目\content\plugins\sms_ihuyi\创建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:接着在项目\content\plugins\sms_ihuyi\创建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, ]; } /** * 发送信息 * * @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)); } /** * 查询账户余额 */ 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)); } /** * 转换返回的信息处理 * @param array $response * @return array $result * @return int $result[].code 返回0则成功,返回其它则错误 * @return string $result[].msg 返回消息 * @return string $result[].raw 接口返回的原生信息 * @return array $result[].data 数据信息 */ 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:最后在项目\content\plugins\sms_ihuyi\创建新的文件夹languages\zh_CN\,名为:plugin.lang.php文件
'ihuyi的APIID:', 'app_secret' => 'ihuyi的APIKEY:', ); // end
经过上面的替换,互亿无线的短信平台已经替换成功了,可以正常使用了。进行测试发送
验证码已发送到您的手机,请查收!
输入验证码后,点击“开通体验账户”按钮可立即开通体验账户。