承接 mani/yii2-twiliosms 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mani/yii2-twiliosms

Composer 安装命令:

composer require mani/yii2-twiliosms

包简介

Twilio sms for sending otp messages to the users

README 文档

README

Twilio sms for sending otp messages to the users

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist rbt/yii2-twiliosms "*"

or add

"rbt/yii2-twiliosms": "*"

to the require section of your composer.json file.

Configuration

To use this extension, you have to configure the class and twilio account details in your application configuration: return[ 'components' => [ 'smsotp' =>[ 'class' => '\twiliosms\sms\Smssendotp',

            //Twilio Test credentials
            'Test_Account_id' => 'xxxxxxxxxxxxxxx',
            'Test_Auth_Token' => 'xxxxxxxxxxxxxxx',
            'Test_From_Number' => 'xxxxxxxxxxxxxxx',

            //Twilio Live credentials

            'Live_Account_id'  => 'xxxxxxxxxxxxxxx',
            'Live_Auth_Token'  => 'xxxxxxxxxxxxxxx',
            'Live_From_Number' => 'xxxxxxxxxxxxxxx',
	    //Here specify the mode whether it is live or test	
            'Send_Otp_Mode' => 'test',
	    
	    // If it is US use +1
            'Phone_Country_Code' => '+91' 
    	],
    ],
]

Usage

Once the extension is installed, follow the below steps to send an otp number to the given phone number and save the otp code into database.

Step 1: Run the below query in your database.

	CREATE TABLE IF NOT EXISTS `sendsms` (
	  `id` int(11) NOT NULL,
	  `phone_number` varchar(15) DEFAULT NULL,
	  `otp_number` varchar(6) DEFAULT NULL,
	  `status` tinyint(4) NOT NULL DEFAULT '0'
	) ENGINE=InnoDB DEFAULT CHARSET=utf8;

	ALTER TABLE `sendsms` ADD PRIMARY KEY (`id`);

	ALTER TABLE `sendsms` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

Step 2: Generate model Sendsms.php for the table sendsms.

Step 3: Create view file sendotp.php file in views/site folder.

	<?php
		use yii\helpers\Html;
		use yii\widgets\ActiveForm;

		/* @var $this yii\web\View */
		/* @var $model app\models\Sendsms */
		/* @var $form ActiveForm */
		$this->title = 'Send OTP';
		$this->params['breadcrumbs'][] = $this->title;
		?>
		<div class="site-sendotp">

			<?php if(Yii::$app->session->hasFlash('successMessage')){?>
			<div class="alert alert-success">
				<?=Yii::$app->session->getFlash('successMessage')?>
		    </div>
		    <?php } ?>

		    <?php if(Yii::$app->session->hasFlash('failureMessage')){?>
			<div class="alert alert-danger">
				<?=Yii::$app->session->getFlash('failureMessage')?>
		    </div>
		    <?php } ?>

		    <?php $form = ActiveForm::begin(); ?>
		        <?= $form->field($model, 'phone_number')->textInput(['type'=>'text','class' => 'phone']); ?> 
		        	    
		        <div class="form-group">
		            <?= Html::submitButton('Send OTP', ['class' => 'btn btn-primary']) ?>
		        </div>
		    <?php ActiveForm::end(); ?>

		</div><!-- site-sendotp -->

Step 4: Create one function like actionSendotp() in site controller.

	<?php
	namespace app\controllers;

	use Yii;
	use yii\filters\AccessControl;
	use yii\web\Controller;
	use yii\web\Response;
	use yii\filters\VerbFilter;
	use app\models\LoginForm;
	use app\models\ContactForm;
	use app\models\Sendsms;

	class SiteController extends Controller
	{
	   
	    /**
	     * Displays send otp page.
	     *
	     * @return string
	     */
	    public function actionSendotp()
	    {
	        $model = new Sendsms();
	        if (Yii::$app->request->post()) {
	            $mobile_number = $_POST['Sendsms']['phone_number'];
	            $otp_message_body = "Your Verification code is:";
	            $send_otp_mode = Yii::$app->smsotp->Send_Otp_Mode;

	            //Sending otp number to the given mobile number.
	            $send_otp = \twiliosms\sms\Smssendotp::sendMessage($mobile_number,$otp_message_body,$send_otp_mode);
	            //echo '<pre>';var_dump($send_otp);
	            //exit;
	            if ( $send_otp != false && $send_otp !='')
	            {
	                $phone_exist = Sendsms::find ()->where ( [ 
	                    'phone_number' => $mobile_number
	                ] )->one ();
	                //Checking phone number is already exist in database or not
	                if ($phone_exist)
	                {
	                    //updating otp code in database.
	                    $update_otp_number = Sendsms::findOne (['phone_number' => $mobile_number]);
	                    $update_otp_number->otp_number = $send_otp;
	                    if ($update_otp_number->update ( false )) {
	                        Yii::$app->session->setFlash('successMessage', "Successfully sent an OTP to your enter phone number");
	                    }
	                    else{
	                         Yii::$app->session->setFlash('failureMessage', "Some Internal server issue occured.");
	                    }

	                }else{
	                    //Inserting phone number and otp number to database.
	                    $model->phone_number = $mobile_number;
	                    $model->otp_number = $send_otp;
	                    if ($model->save ( false )) {
	                        Yii::$app->session->setFlash('successMessage', "Successfully sent an OTP to your enter phone number");
	                    }else{
	                        Yii::$app->session->setFlash('failureMessage', "Some Internal server issue occured.");
	                    }
	                }
	            }else{
	                Yii::$app->session->setFlash('failureMessage', "Unable to send OTP, please try again.!");
	                
	            }
	           
	        }
	        return $this->render('sendotp',['model'=>$model] );
	    }
	}

mani/yii2-twiliosms 适用场景与选型建议

mani/yii2-twiliosms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「extension」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mani/yii2-twiliosms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mani/yii2-twiliosms 我们能提供哪些服务?
定制开发 / 二次开发

基于 mani/yii2-twiliosms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2017-09-15