定制 fotografde/cakephp-sms 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fotografde/cakephp-sms

最新稳定版本:1.0.2

Composer 安装命令:

composer require fotografde/cakephp-sms

包简介

SMS Plugin for CakePHP

README 文档

README

Build Status Minimum PHP Version License Total Downloads

Send SMS with CakePHP.

Usage

App::uses('CakeSms', 'Sms.Network/Sms');

$CakeSms = new CakeSms('default');
$CakeSms->to('+491234567890');
$CakeSms->from('+841234567890');
$CakeSms->send('Hello world!');

Installation via Composer

"require": {
	"fotografde/cakephp-sms": ">=1.0.0"
}

Configuration

Load plugin in Config/bootstrap.php

CakePlugin::load('Sms');

Create Config/sms.php

class SmsConfig {
	public $default = array(
		'transport' => 'Clickatell', // will use class ClickatellSmsTransport
	);
}

Implement a transport class under Lib/Network/Sms/. We recommend implementing Xi SMS, this way for example:

/**
 * Send SMS through SMS provider Clickatell
 */

use Xi\Sms\Gateway\ClickatellGateway;

App::uses('AbstractSmsTransport', 'Sms.Network/Sms');

class ClickatellSmsTransport extends AbstractSmsTransport {

	const CLICKATELL_API_ID = 'XXXX';
	const CLICKATELL_USER = 'YYYY';
	const CLICKATELL_PASSWORD = 'ZZZZ';

	/**
	 * Sends an SMS Through Clickatell
	 * We could also consider using this library: http://github.com/arcturial/clickatell
	 *
	 * @param CakeSms $sms
	 * @return bool Success
	 */
	public function send(CakeSms $sms) {
		$gw = new ClickatellGateway(
			self::CLICKATELL_API_ID,
			self::CLICKATELL_USER,
			self::CLICKATELL_PASSWORD
		);

		$service = new Xi\Sms\SmsService($gw);

		$msg = new Xi\Sms\SmsMessage(
			$sms->message(),
			self::parsePhoneNumber($sms->from()),
			self::parsePhoneNumber($sms->to())
		);

		$response = $service->send($msg);

		return !empty($response);
	}
	
	/**
	 * Parses a phone number to fit Clickatell requirements
	 * from +49123[...] to 49123[...]
	 *
	 * @param array|string $phoneNumber
	 * @return array|string|bool
	 */
	public static function parsePhoneNumber($phoneNumber) {
		if (is_array($phoneNumber)) {
			return array_map('self::parsePhoneNumber', $phoneNumber);
		}
		if (preg_match('/^\+([0-9]+)$/', (string) $phoneNumber, $matches)) {
			return $matches[1];
		}
		return false;
	}
}

统计信息

  • 总下载量: 73.22k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 13
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-11