SmsPublicTemp.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\adminapi\controller\v1\notification\sms;
  3. use app\adminapi\controller\AuthController;
  4. use crmeb\exceptions\AdminException;
  5. use crmeb\services\sms\Sms;
  6. use crmeb\services\UtilService;
  7. /**
  8. * 公共短信模板
  9. * Class SmsPublicTemp
  10. * @package app\admin\controller\sms
  11. */
  12. class SmsPublicTemp extends AuthController
  13. {
  14. /**
  15. * @var Sms
  16. */
  17. protected $smsHandle;
  18. public function initialize()
  19. {
  20. parent::initialize(); // TODO: Change the autogenerated stub
  21. $this->smsHandle = new Sms('yunxin', [
  22. 'sms_account' => sys_config('sms_account'),
  23. 'sms_token' => sys_config('sms_token'),
  24. 'site_url' => sys_config('site_url')
  25. ]);
  26. if (!$this->smsHandle->isLogin()) {
  27. throw new AdminException('请先填写短息配置');
  28. }
  29. }
  30. /**
  31. * 异步获取公共模板列表
  32. */
  33. public function index()
  34. {
  35. $where = UtilService::getMore([
  36. ['is_have', ''],
  37. ['page', 1],
  38. ['limit', 20],
  39. ]);
  40. $templateList = $this->smsHandle->publictemp($where);
  41. if ($templateList['status'] == 400) return $this->fail($templateList['msg']);
  42. $arr = $templateList['data']['data'];
  43. foreach ($arr as $key => $value) {
  44. switch ($value['type']) {
  45. case 1:
  46. $arr[$key]['type'] = '验证码';
  47. break;
  48. case 2:
  49. $arr[$key]['type'] = '通知';
  50. break;
  51. case 3:
  52. $arr[$key]['type'] = '推广';
  53. break;
  54. default:
  55. $arr[$key]['type'] = '';
  56. break;
  57. }
  58. }
  59. $templateList['data']['data'] = $arr;
  60. return $this->success($templateList['data']);
  61. }
  62. }