SmsPay.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\notification\sms;
  12. use crmeb\exceptions\AdminException;
  13. use app\controller\admin\AuthController;
  14. use crmeb\services\{sms\Sms, SystemConfigService};
  15. /**
  16. * 短信购买
  17. * Class SmsPay
  18. * @package app\controller\admin\v1\notification\sms
  19. */
  20. class SmsPay extends AuthController
  21. {
  22. /**
  23. * @var Sms
  24. */
  25. protected $smsHandle;
  26. public function initialize()
  27. {
  28. parent::initialize();
  29. $data = SystemConfigService::more(['sms_account', 'sms_token', 'site_url']);
  30. $this->smsHandle = new Sms('yunxin', $data);
  31. if (!$this->smsHandle->isLogin()) {
  32. throw new AdminException('请先填写短息配置');
  33. }
  34. }
  35. /**
  36. * 获取账号信息
  37. */
  38. public function number()
  39. {
  40. $countInfo = $this->smsHandle->count();
  41. if ($countInfo['status'] == 400) return $this->fail($countInfo['msg']);
  42. $info['account'] = sys_config('sms_account');
  43. $info['number'] = $countInfo['data']['number'];
  44. $info['send_total'] = $countInfo['data']['send_total'];
  45. return $this->success($info);
  46. }
  47. /**
  48. * 获取支付套餐
  49. */
  50. public function price()
  51. {
  52. [$page, $limit] = $this->request->getMore([
  53. ['page', 1],
  54. ['limit', 20],
  55. ], true);
  56. $mealInfo = $this->smsHandle->meal($page, $limit);
  57. if ($mealInfo['status'] == 400) return $this->fail($mealInfo['msg']);
  58. return $this->success($mealInfo['data']);
  59. }
  60. /**
  61. * 获取支付码
  62. */
  63. public function pay()
  64. {
  65. [$payType, $mealId, $price] = $this->request->postMore([
  66. ['payType', 'weixin'],
  67. ['mealId', 0],
  68. ['price', 0],
  69. ], true);
  70. $payInfo = $this->smsHandle->pay($payType, $mealId, $price, $this->adminId);
  71. if ($payInfo['status'] == 400) return $this->fail($payInfo['msg']);
  72. return $this->success($payInfo['data']);
  73. }
  74. }