互億無線 · 文檔中心

ECJia到家V1.37.0短信插件


插件說明

本插件系互億無線針對ECJia到家V1.37.0開發(fā),請按以下說明進(jìn)行安裝,插件內(nèi)的所有文件均為對原文件的修改,如果你的系統(tǒng)經(jīng)過二次開發(fā),安裝本插件之前,請仔細(xì)核對修改。

功能介紹

ECJia到家發(fā)送驗(yàn)證碼短信及通知短信

安裝步驟

1:打開項(xiàng)目:\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:打開項(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));

    }
    
    /**
     * 查詢賬戶余額
     */
    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則成功,返回其它則錯誤
     * @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']
        ]);
    }
    
    
	/**
	 * 獲取插件代號
	 *  
     * @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:接著在項(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));

    }
    
    /**
     * 查詢賬戶余額
     */
    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則成功,返回其它則錯誤
     * @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)過上面的替換,互億無線的短信平臺已經(jīng)替換成功了,可以正常使用了。進(jìn)行測試發(fā)送

現(xiàn)在注冊,即享新用戶禮包!

在線咨詢
電話咨詢

服務(wù)熱線:

4008 808 898

服務(wù)熱線(工作時間):

4008 808 898

業(yè)務(wù)咨詢(非工作時間):

售后咨詢(非工作時間):

驗(yàn)證碼已發(fā)送到您的手機(jī),請查收!

輸入驗(yàn)證碼后,點(diǎn)擊“開通體驗(yàn)賬戶”按鈕可立即開通體驗(yàn)賬戶。

收不到短信驗(yàn)證碼?
互億無線不提供接碼服務(wù),接碼用戶請勿點(diǎn)擊開通按鈕。
×