SmsPay.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\adminapi\controller\v1\notification\sms;
  3. use app\models\system\SystemConfig;
  4. use crmeb\exceptions\AdminException;
  5. use think\facade\Route;
  6. use app\adminapi\controller\AuthController;
  7. use crmeb\services\{
  8. sms\Sms, FormBuilder, UtilService
  9. };
  10. /**
  11. * 短信购买
  12. * Class SmsPay
  13. * @package app\admin\controller\sms
  14. */
  15. class SmsPay extends AuthController
  16. {
  17. /**
  18. * @var Sms
  19. */
  20. protected $smsHandle;
  21. public function initialize()
  22. {
  23. parent::initialize(); // TODO: Change the autogenerated stub
  24. $this->smsHandle = new Sms('yunxin', [
  25. 'sms_account' => sys_config('sms_account'),
  26. 'sms_token' => sys_config('sms_token'),
  27. 'site_url' => sys_config('site_url')
  28. ]);
  29. if (!$this->smsHandle->isLogin()) {
  30. throw new AdminException('请先填写短息配置');
  31. }
  32. }
  33. /**
  34. * 获取账号信息
  35. */
  36. public function number()
  37. {
  38. $countInfo = $this->smsHandle->count();
  39. if ($countInfo['status'] == 400) return $this->fail($countInfo['msg']);
  40. $info['account'] = SystemConfig::getConfigValue('sms_account');
  41. $info['number'] = $countInfo['data']['number'];
  42. $info['send_total'] = $countInfo['data']['send_total'];
  43. return $this->success($info);
  44. }
  45. /**
  46. * 获取支付套餐
  47. */
  48. public function price()
  49. {
  50. list($page, $limit) = UtilService::getMore([
  51. ['page', 1],
  52. ['limit', 20],
  53. ], null, true);
  54. $mealInfo = $this->smsHandle->meal($page, $limit);
  55. if ($mealInfo['status'] == 400) return $this->fail($mealInfo['msg']);
  56. return $this->success($mealInfo['data']);
  57. }
  58. /**
  59. * 获取支付码
  60. */
  61. public function pay()
  62. {
  63. list($payType, $mealId, $price) = UtilService::postMore([
  64. ['payType', 'weixin'],
  65. ['mealId', 0],
  66. ['price', 0],
  67. ], null, true);
  68. $payInfo = $this->smsHandle->pay($payType, $mealId, $price, $this->adminId);
  69. if ($payInfo['status'] == 400) return $this->fail($payInfo['msg']);
  70. return $this->success($payInfo['data']);
  71. }
  72. }