EyunzhuMobileCodePlugin.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace plugins\eyunzhu_mobile_code;
  3. //Demo插件英文名,改成你的插件英文就行了
  4. use cmf\lib\Plugin;
  5. use plugins\eyunzhu_mobile_code\ChuanglanSmsHelper\ChuanglanSmsApi;
  6. class EyunzhuMobileCodePlugin extends Plugin
  7. {
  8. public $info = [
  9. 'name' => 'EyunzhuMobileCode',
  10. 'title' => '手机验证码插件',
  11. 'description' => '忆云竹手机验证码插件',
  12. 'status' => 1,
  13. 'author' => 'eyunzhu',
  14. 'version' => '1.0',
  15. ];
  16. public $has_admin = 0;//插件是否有后台管理界面
  17. public function install() //安装方法必须实现
  18. {
  19. return true;//安装成功返回true,失败false
  20. }
  21. public function uninstall() //卸载方法必须实现
  22. {
  23. return true;//卸载成功返回true,失败false
  24. }
  25. //实现的send_mobile_verification_code钩子方法
  26. public function sendMobileVerificationCode($param)
  27. {
  28. $mobile = $param['mobile'];//手机号
  29. $code = $param['code'];//验证码
  30. $config = $this->getConfig();
  31. $expire_minute = intval($config['expire_minute']);
  32. $expire_minute = empty($expire_minute) ? 30 : $expire_minute;
  33. $expire_time = time() + $expire_minute * 60;
  34. $msg = $config['template'] . $code;
  35. $ChuanglanSmsApi = new ChuanglanSmsApi();
  36. $sendSMS_result = $ChuanglanSmsApi->sendSMS($config, $mobile, $msg);
  37. $sendSMS_result = json_decode($sendSMS_result);
  38. if ($sendSMS_result->code == '0') {
  39. $result = [
  40. 'error' => 0,
  41. 'message' => '验证码发送成功',
  42. 'expire_time' => $expire_time,
  43. ];
  44. } else {
  45. $result = [
  46. 'error' => 1,
  47. 'message' => $sendSMS_result->errorMsg //服务商返回结果错误
  48. ];
  49. }
  50. return $result;
  51. }
  52. }