SmsPay.php 2.7 KB

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