SmsPay.php 2.1 KB

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