AliYunSms.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2021/2/2
  6. * Time: 16:05
  7. */
  8. namespace app\common\modules\sms\factory;
  9. use app\common\modules\sms\Sms;
  10. class AliYunSms extends Sms
  11. {
  12. public function _sendCode($mobile, $state, $ext = null)
  13. {
  14. switch ($this->template) {
  15. case 'register':
  16. $template = 'aly_templateCode';
  17. $ext = ["number" => $this->getCode($mobile)];
  18. break;
  19. case 'password':
  20. $template = 'aly_templateCodeForget';
  21. $ext = ["number" => $this->getCode($mobile)];
  22. break;
  23. case 'login':
  24. if(empty($this->sms['aly_templateCodeLogin'])){
  25. $template = 'aly_templateCode';
  26. }else{
  27. $template = 'aly_templateCodeLogin';
  28. }
  29. $ext = ["number" => $this->getCode($mobile)];
  30. break;
  31. case 'balance':
  32. $template = 'aly_templateBalanceCode';
  33. break;
  34. case 'member_recharge':
  35. $template = 'aly_templatereChargeCode';
  36. break;
  37. case 'goods':
  38. $template = 'aly_templateSendMessageCode';
  39. break;
  40. case 'withdraw_set':
  41. $template = 'aly_templateCode';
  42. $ext = ["number" => $this->getCode($mobile,$this->key)];
  43. break;
  44. default:
  45. return '短信发送失败:未知短信类型';
  46. }
  47. if(empty($this->sms[$template])){
  48. return '发送失败,请检查短信配置!';
  49. }
  50. $aly_sms = new \app\common\services\aliyun\AliyunSMS(trim($this->sms['aly_appkey']), trim($this->sms['aly_secret']));
  51. $response = $aly_sms->sendSms(
  52. $this->sms['aly_signname'], // 短信签名
  53. $this->sms[$template], // 短信模板编号
  54. $mobile, // 短信接收者
  55. $ext //封装好的数据
  56. );
  57. if ($response->Code != 'OK' || $response->Message != 'OK') {
  58. return $response->Message;
  59. }
  60. return true;
  61. }
  62. }