123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace app\api\controller;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use app\common\library\AliPay2;
- use app\common\library\HuijuH5Pay;
- use think\cache\driver\Redis;
- use think\Db;
- /**
- * @title 充值余额
- * @controller UserCenter
- * @group base
- */
- class Recharge extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::check_login();
- }
- /**
- * @title 余额充值
- * @desc 余额充值
- * @author Gavin
- * @url /api/Recharge/recharge
- * @method POST
- * @tag 余额充值
- * @header name:Authorization require:1 desc:Token
- * @param name:price type:string : default: desc:充值金额
- * @param name:pay_type type:string require:1 default:wx desc:wx:微信zfb:支付宝
- */
- public function recharge()
- {
- //redis原子锁
- if (redisSetNx('recharge'.$this->uid,2)){
- $v = getConfigValue('recharge_switch');
- if (!$v) $this->error('维护中,暂时关闭');
- $price = input('price');
- $pay_type = input('pay_type');
- if (!$price || !$pay_type) $this->error('参数错误');
- if (!isAmount($price)) $this->error('金额错误');
- $order_no = get_order_sn();
- $data = [
- 'order_no'=>$order_no,
- 'm_id'=>$this->uid,
- 'price'=>$price,
- 'pay_price'=>$price,
- 'pay_type'=>$pay_type
- ];
- if (Db::name('store_member_recharge')->insert($data)){
- $com = true;
- switch ($pay_type){
- case 'ylh5':
- $callback_url = 'http://'.$_SERVER['SERVER_NAME'].'/pages/mine/qianbao';
- $huiju = new HuijuH5Pay();
- $notify_url = 'http://'.$_SERVER['SERVER_NAME'].'/index.php/api/Pay/ylrechargeNotify';//回调地址
- $result = $huiju->ylh5Pay($order_no,$callback_url,$notify_url,'余额充值',$price,$this->uid,2);
- if ($result['ra_Code']=='100'){
- $retrun_data['order_no'] = $order_no;
- $retrun_data['pay'] = $result['rc_Result'];
- }else{
- $com = false;
- }
- break;
- case 'zfbh5':
- $callback_url = 'http://'.$_SERVER['SERVER_NAME'].'/pages/mine/qianbao';
- $huiju = new HuijuH5Pay();
- $notify_url = 'http://'.$_SERVER['SERVER_NAME'].'/index.php/api/Pay/ylrechargeNotify';//回调地址
- $result = $huiju->ylh5Pay($order_no,$callback_url,$notify_url,'余额充值',$price,$this->uid,1);
- if ($result['ra_Code']=='100'){
- $retrun_data['order_no'] = $order_no;
- $retrun_data['pay'] = $result['rc_Result'];
- }else{
- $com = false;
- }
- break;
- default:
- $com = false;
- break;
- }
- if ($com){
- $this->success('成功',$retrun_data);
- }else{
- $this->error('调起支付失败,请稍后重试');
- }
- }else{
- $this->error('失败,请稍后重试');
- }
- }else{
- $this->error('请求过快');
- }
- }
- }
|