ElisoftSms.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. use app\platform\modules\system\models\SystemSetting;
  12. use GuzzleHttp\Client;
  13. class ElisoftSms extends Sms
  14. {
  15. public function sendBalance($mobile, $ext)
  16. {
  17. return ;
  18. }
  19. public function sendGoods($mobile, $ext)
  20. {
  21. return;
  22. }
  23. public function sendMemberRecharge($mobile, $ext)
  24. {
  25. return;
  26. }
  27. public function _sendCode($mobile, $state, $ext = null)
  28. {
  29. try {
  30. if (!app('plugins')->isEnabled('elisoftsms')) {
  31. throw new \Exception('未开启验证码,请联系管理员!');
  32. }
  33. $setting = SystemSetting::settingLoad('sms', 'system_sms');
  34. $code = $this->getCode($mobile,$this->key);
  35. $msg = '【' . $this->sms['elisoft_signname'] . '】' . '您的验证码是:' . $code . '。请不要把验证码泄露给其他人。如非本人操作,可不用理会!';
  36. $account = $this->sms['elisoft_account'];
  37. $passward = $this->sms['elisoft_password'];
  38. if($setting['interior_sms_type']==1){
  39. $param = [
  40. 'c' => urlencode($msg),
  41. 'p' => $mobile,
  42. ];
  43. $sms = new \Yunshop\Elisoftsms\services\ElisoftSmsService($account,$passward);
  44. $res = $sms->setAction('sendbatch')->send($param);
  45. if ($res['result'] != 1) {
  46. throw new \Exception($res['errormsg']);
  47. }
  48. }else{
  49. $msgArr=[
  50. '-1'=>'Uid或密码为空',
  51. '-2'=>'下发号码为空',
  52. '-3'=>'下发内容为空',
  53. '-4'=>'内容超长',
  54. '-5'=>'下发号码超长',
  55. '-6'=>'uid或密码不正确',
  56. '-7'=>'短信余额不足',
  57. '-8'=>'IP地址鉴权不对',
  58. '-9'=>'协议类型不对',
  59. '-99'=>'系统异常'
  60. ];
  61. $url="http://3qdx.com:18002/send.do";
  62. $param=['uid'=>$setting['klws_account'],'pw'=>md5($setting['klws_password'].date('YmdHis')),'mb'=>$mobile,'tm'=>date('YmdHis'),'ms'=>$msg];
  63. $url=$url.'?'.http_build_query($param);
  64. $client = new Client();
  65. $res=$client->get($url)->getBody()->getContents();
  66. if (in_array($res,['-1','-2','-3','-4','-5','-6','-7','-8','-9','-99'])) {
  67. throw new \Exception($res);
  68. }
  69. }
  70. return true;
  71. } catch (\Exception $e) {
  72. \Log::debug('elisoftsms短信'.$e->getMessage(),[isset($res)?$res:'',isset($param)?$param:'']);
  73. return $e->getMessage();
  74. }
  75. }
  76. }