IndexController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\BaseController;
  4. use App\Services\GongdengOrderService;
  5. use App\Services\RechargeService;
  6. use App\Services\RedisService;
  7. use App\Services\WechatService;
  8. /**
  9. * 主控制器类
  10. * @author wesmiler
  11. * @since 2020/11/10
  12. * Class IndexController
  13. * @package App\Http\Controllers
  14. */
  15. class IndexController extends BaseController
  16. {
  17. /**
  18. * 构造函数
  19. * @author wesmiler
  20. * @since 2020/11/11
  21. * IndexController constructor.
  22. */
  23. public function __construct()
  24. {
  25. parent::__construct();
  26. $this->gdService = new GongdengOrderService();
  27. $this->rechargeService = new RechargeService();
  28. }
  29. /**
  30. * 获取jssdk参数
  31. * @return array
  32. */
  33. public function jssdk(){
  34. $url = request()->get('url', '');
  35. $jssdkParams = WechatService::getJssdkParams($url);
  36. RedisService::set('caches:shares:'.date('YmdHis'), ['url'=> $url,'params'=> $jssdkParams], 600);
  37. return message(1005,true, $jssdkParams);
  38. }
  39. /**
  40. * 获取验证订单信息
  41. * @return array
  42. */
  43. public function orderInfo(){
  44. $orderSn = request()->get('order_sn');
  45. if(empty($orderSn)){
  46. return message('订单号参数错误', false);
  47. }
  48. $info = [];
  49. $prefix = substr($orderSn, 0,1);
  50. switch ($prefix){
  51. case 'G': // 供灯
  52. $info = $this->gdService->orderInfo($orderSn);
  53. break;
  54. case 'R': // 充值
  55. $info = $this->rechargeService->orderInfo($orderSn);
  56. break;
  57. }
  58. if($info){
  59. return message('获取订单信息', true, $info);
  60. }else{
  61. return message('获取订单信息失败', false);
  62. }
  63. }
  64. }