Recharge.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use app\common\library\AliPay2;
  7. use app\common\library\HuijuH5Pay;
  8. use think\cache\driver\Redis;
  9. use think\Db;
  10. /**
  11. * @title 充值余额
  12. * @controller UserCenter
  13. * @group base
  14. */
  15. class Recharge extends Base
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. parent::check_login();
  21. }
  22. /**
  23. * @title 余额充值
  24. * @desc 余额充值
  25. * @author Gavin
  26. * @url /api/Recharge/recharge
  27. * @method POST
  28. * @tag 余额充值
  29. * @header name:Authorization require:1 desc:Token
  30. * @param name:price type:string : default: desc:充值金额
  31. * @param name:pay_type type:string require:1 default:wx desc:wx:微信zfb:支付宝
  32. */
  33. public function recharge()
  34. {
  35. //redis原子锁
  36. if (redisSetNx('recharge'.$this->uid,2)){
  37. $v = getConfigValue('recharge_switch');
  38. if (!$v) $this->error('维护中,暂时关闭');
  39. $price = input('price');
  40. $pay_type = input('pay_type');
  41. if (!$price || !$pay_type) $this->error('参数错误');
  42. if (!isAmount($price)) $this->error('金额错误');
  43. $order_no = get_order_sn();
  44. $data = [
  45. 'order_no'=>$order_no,
  46. 'm_id'=>$this->uid,
  47. 'price'=>$price,
  48. 'pay_price'=>$price,
  49. 'pay_type'=>$pay_type
  50. ];
  51. if (Db::name('store_member_recharge')->insert($data)){
  52. $com = true;
  53. switch ($pay_type){
  54. case 'ylh5':
  55. $callback_url = 'http://'.$_SERVER['SERVER_NAME'].'/pages/mine/qianbao';
  56. $huiju = new HuijuH5Pay();
  57. $notify_url = 'http://'.$_SERVER['SERVER_NAME'].'/index.php/api/Pay/ylrechargeNotify';//回调地址
  58. $result = $huiju->ylh5Pay($order_no,$callback_url,$notify_url,'余额充值',$price,$this->uid,2);
  59. if ($result['ra_Code']=='100'){
  60. $retrun_data['order_no'] = $order_no;
  61. $retrun_data['pay'] = $result['rc_Result'];
  62. }else{
  63. $com = false;
  64. }
  65. break;
  66. case 'zfbh5':
  67. $callback_url = 'http://'.$_SERVER['SERVER_NAME'].'/pages/mine/qianbao';
  68. $huiju = new HuijuH5Pay();
  69. $notify_url = 'http://'.$_SERVER['SERVER_NAME'].'/index.php/api/Pay/ylrechargeNotify';//回调地址
  70. $result = $huiju->ylh5Pay($order_no,$callback_url,$notify_url,'余额充值',$price,$this->uid,1);
  71. if ($result['ra_Code']=='100'){
  72. $retrun_data['order_no'] = $order_no;
  73. $retrun_data['pay'] = $result['rc_Result'];
  74. }else{
  75. $com = false;
  76. }
  77. break;
  78. default:
  79. $com = false;
  80. break;
  81. }
  82. if ($com){
  83. $this->success('成功',$retrun_data);
  84. }else{
  85. $this->error('调起支付失败,请稍后重试');
  86. }
  87. }else{
  88. $this->error('失败,请稍后重试');
  89. }
  90. }else{
  91. $this->error('请求过快');
  92. }
  93. }
  94. }