TxYunSms.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2021/2/2
  6. * Time: 17:52
  7. */
  8. namespace app\common\modules\sms\factory;
  9. use app\common\modules\sms\Sms;
  10. use app\common\services\txyunsms\SmsSingleSender;
  11. class TxYunSms extends Sms
  12. {
  13. public function _sendCode($mobile,$state,$ext = [])
  14. {
  15. switch ($this->template) {
  16. case 'register':
  17. $template = 'tx_templateCode';
  18. $ext = [$this->getCode($mobile)];
  19. break;
  20. case 'password':
  21. $template = 'tx_templateCodeForget';
  22. $ext = [$this->getCode($mobile)];
  23. break;
  24. case 'login':
  25. if(empty($this->sms['tx_templateCodeLogin'])){
  26. $template = 'tx_templateCode';
  27. }else{
  28. $template = 'tx_templateCodeLogin';
  29. }
  30. $ext = [$this->getCode($mobile)];
  31. break;
  32. case 'balance':
  33. $template = 'tx_templateBalanceCode';
  34. break;
  35. case 'member_recharge':
  36. $template = 'tx_templatereChargeCode';
  37. break;
  38. case 'goods':
  39. $template = 'tx_templateSendMessageCode';
  40. break;
  41. case 'withdraw_set':
  42. $template = 'tx_templateCode';
  43. $ext = [$this->getCode($mobile,$this->key)];
  44. break;
  45. default:
  46. return '短信发送失败:未知短信类型';
  47. }
  48. $ext = array_values($ext);
  49. if(empty($this->sms[$template])){
  50. return '发送失败,请检查短信配置!';
  51. }
  52. $sender = new SmsSingleSender(trim($this->sms['tx_sdkappid']), trim($this->sms['tx_appkey']));
  53. $response = $sender->sendWithParam($state, $mobile, $this->sms[$template], $ext, $this->sms['tx_signname'], "", ""); // 签名参数不能为空串
  54. $response = json_decode($response);
  55. if ($response->result != 0 || $response->errmsg != 'OK') {
  56. return $response->errmsg;
  57. }
  58. return true;
  59. }
  60. }