user = $this->getUserDetail(); // 用户信息 } /** * 充值支付 * $type 30=微信 40=支付宝 */ public function pay($money,$type=30,$recharge_plan_id = 0) { $order_no = order_no(); $order = [ 'mode' => 10, //充值 'type' => $type,//支付类型 'order_no' => $order_no, 'money' => $money, 'recharge_plan_id' => $recharge_plan_id, 'remark' => '用户充值', 'user_id' => $this->user['user_id'], 'shop_id' => $this->shop_id, 'applet_id' => $this->applet_id ]; Cache::set($order_no, $order,7200); //H5支付 if($this->mp == 'h5'){ //微信小程序支付 if($type == 30){ $wx = new WxPay(SettingModel::getItem('wxpay',$this->applet_id)); if(!$result = $wx->h5($order_no,$money,'api/food.notify/recharge/appletid/'.$this->applet_id,'用户充值')){ return $this->renderError($wx->getError()); } } //支付宝小程序支付 if($type == 40){ $alipay = new AlipayPay($this->applet_id); if(!$result = $alipay->tradeWapPay($order_no,$money,'api/food.notify/alipayRecharge/appletid/'.$this->applet_id,'h5/food/#/pages/user/vip/wallet','用户充值')){ $this->error = $alipay->getError(); return false; } } }else{ //微信小程序支付 if($type == 30){ $wx = new WxPay(SettingModel::getItem('wxpay',$this->applet_id)); if(!$result = $wx->jsapi($order_no,$money,$this->user['open_id'],'api/food.notify/recharge/appletid/'.$this->applet_id,'用户充值')){ return $this->renderError($wx->getError()); } } //支付宝小程序支付 if($type == 40){ $alipay = new AlipayPay($this->applet_id); if(!$result = $alipay->tradeCreate($order_no,$money,$this->user['open_id'],'api/food.notify/alipayRecharge/appletid/'.$this->applet_id,'用户充值')){ return $this->renderError($alipay->getError()); } } } return $this->renderSuccess($result); } }