| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace plugins\eyunzhu_mobile_code;
- //Demo插件英文名,改成你的插件英文就行了
- use cmf\lib\Plugin;
- use plugins\eyunzhu_mobile_code\ChuanglanSmsHelper\ChuanglanSmsApi;
- class EyunzhuMobileCodePlugin extends Plugin
- {
- public $info = [
- 'name' => 'EyunzhuMobileCode',
- 'title' => '手机验证码插件',
- 'description' => '忆云竹手机验证码插件',
- 'status' => 1,
- 'author' => 'eyunzhu',
- 'version' => '1.0',
- ];
- public $has_admin = 0;//插件是否有后台管理界面
- public function install() //安装方法必须实现
- {
- return true;//安装成功返回true,失败false
- }
- public function uninstall() //卸载方法必须实现
- {
- return true;//卸载成功返回true,失败false
- }
- //实现的send_mobile_verification_code钩子方法
- public function sendMobileVerificationCode($param)
- {
- $mobile = $param['mobile'];//手机号
- $code = $param['code'];//验证码
- $config = $this->getConfig();
- $expire_minute = intval($config['expire_minute']);
- $expire_minute = empty($expire_minute) ? 30 : $expire_minute;
- $expire_time = time() + $expire_minute * 60;
- $msg = $config['template'] . $code;
- $ChuanglanSmsApi = new ChuanglanSmsApi();
- $sendSMS_result = $ChuanglanSmsApi->sendSMS($config, $mobile, $msg);
- $sendSMS_result = json_decode($sendSMS_result);
- if ($sendSMS_result->code == '0') {
- $result = [
- 'error' => 0,
- 'message' => '验证码发送成功',
- 'expire_time' => $expire_time,
- ];
- } else {
- $result = [
- 'error' => 1,
- 'message' => $sendSMS_result->errorMsg //服务商返回结果错误
- ];
- }
- return $result;
- }
- }
|