AliDayuSms.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2021/2/2
  6. * Time: 15:33
  7. */
  8. namespace app\common\modules\sms\factory;
  9. use app\common\modules\sms\Sms;
  10. use iscms\Alisms\SendsmsPusher;
  11. class AliDayuSms extends Sms
  12. {
  13. public function sendBalance($mobile, $ext)
  14. {
  15. return ;
  16. }
  17. public function sendGoods($mobile, $ext)
  18. {
  19. return;
  20. }
  21. public function sendMemberRecharge($mobile, $ext)
  22. {
  23. return;
  24. }
  25. public function _sendCode($mobile, $state, $ext = null)
  26. {
  27. switch ($this->template) {
  28. case 'register':
  29. list($result['template'], $result['params']) = [$this->sms['templateCode'], @explode("\n", $this->sms['product'])];
  30. break;
  31. case 'password':
  32. list($result['template'], $result['params']) = [$this->sms['templateCodeForget'], @explode("\n", $this->sms['forget'])];
  33. break;
  34. case 'login':
  35. if(empty($this->sms['templateCodeLogin'])){
  36. list($result['template'], $result['params']) = [$this->sms['templateCode'], @explode("\n", $this->sms['product'])];
  37. }else{
  38. list($result['template'], $result['params']) = [$this->sms['templateCodeLogin'], @explode("\n", $this->sms['login'])];
  39. }
  40. break;
  41. default:
  42. return '短信发送失败:未知短信类型';
  43. }
  44. $code = $this->getCode($mobile,$this->key);
  45. if (count($result['params']) > 1) {
  46. $nparam['code'] = "{$code}";
  47. foreach ($result['params'] as $param) {
  48. $param = trim($param);
  49. $explode_param = explode("=", $param);
  50. if (!empty($explode_param[0])) {
  51. $nparam[$explode_param[0]] = "{$explode_param[1]}";
  52. }
  53. }
  54. $content = json_encode($nparam);
  55. } else {
  56. $explode_param = explode("=", $result['params'][0]);
  57. $content = json_encode(array('code' => (string)$code, 'product' => $explode_param[1]));
  58. }
  59. $top_client = new \iscms\AlismsSdk\TopClient(trim($this->sms['appkey']), trim($this->sms['secret']));
  60. $name = trim($this->sms['signname']);
  61. $templateCode = trim($result['template']);
  62. config([
  63. 'alisms.KEY' => trim($this->sms['appkey']),
  64. 'alisms.SECRETKEY' => trim($this->sms['secret'])
  65. ]);
  66. $sms = new SendsmsPusher($top_client);
  67. $res = $sms->send($mobile, $name, $content, $templateCode);
  68. if (!isset($res->result->success)) {
  69. return $res->msg . '/' . $res->sub_msg;
  70. }
  71. return true;
  72. }
  73. }