nowTime = NOW_TIMESTAMP; $this->redis = \think\Cache::store('default')->handler(); } /** * 支付处理 新整理 */ public function index() { //海外游戏ip限制 if (in_array($this->input('gameid'), config('haiwai_game_ids'))) { $res = (new IpLimit())->validateIp(request()->ip(), $this->input['username']); if ($res != 1) { $this->jsonResult('', -100, '国内用户禁止充值'); } } $data['gameid'] = $this->input('gameid'); //游戏ID $data['member_id'] = $this->input('userid'); //用户ID $data['serverid'] = $this->input('serverid'); //服务器ID $data['servername'] = $this->input('servername'); //区服名称 $data['amount'] = cleanAmount($this->input('amount')); //充值金额 $data['roleid'] = $this->input('roleid'); //角色ID $data['attach'] = $this->input('attach'); //上一级的扩展参数,多数是订单编号[麻花网络自己聚合自己时,会加个aoyou###前缀] $data['ptb_amt'] = $this->input('ptb_amt', 0); //平台币使用金额 $data['imeil'] = trim($this->input('imeil')); //手机imeil码 $data['productname'] = $this->input('productname'); //消费的商品名称 $data['paytype'] = $this->input('paytype'); //支付类型 $data['rolename'] = $this->input('rolename', ''); //角色名 $data['rolelevel'] = $this->input('rolelevel', ''); //角色角色等级 $data['channel_id'] = $this->input('channel_id'); $data['sub_username'] = $this->input('sub_username'); $data['ip'] = request()->ip(); $data['appid'] = $this->input('appid'); // 用于处理不同平台的游戏支付方式封禁判断 $data['version'] = $this->input('version'); // 版本 $data['coin_amt'] = $this->input('coin_amt', 0); // 平台币使用金额 $data['coupon_member_id'] = $this->input('coupon_member_id', 0); // 代金券id $data['device'] = $this->input('device', ''); // 注册设备来源 $data['client_type'] = $this->input('client_type', 1); // 客户端类型(1=祈盟sdk, 2=巨量, 3=快手磁力包) //参数验证 $checkResult = $this->validate($this->input, 'Pay.add'); if (true !== $checkResult) { $this->jsonResult('', -100, $checkResult); } // 封禁安卓老版本的支付方式 if (version_compare($data['version'], 'v3.2.6') < 1) { if (substr($this->input('paytype'), 0, 5) == 'coin-') { if (in_array($this->input('paytype'), ['coin-zfb', 'coin-mix-zfb', 'coin-mix-zfb', 'coin-wxpay-h5', 'coin-wx-wap', 'coin-ybzf_wxmp_h5']) && in_array($this->input('gameid'), ['10', '249', '255', '256', '260', '262', '266'])) { $this->jsonResult('', -110, "请下载最新游戏包,或选择【支付宝(旧)】进行支付。"); } if (in_array($this->input('paytype'), ['coin-zfb']) && in_array($this->input('gameid'), ['20', '245', '248', '258', '259', '261', '263'])) { $this->jsonResult('', -110, "请下载最新游戏包,或选择【支付宝(旧)】进行支付。"); } } } // TODO:萌战无双游戏微信支付申请-01.02 if ($data['gameid'] == Config::get('gb_game')) { $this->jsonResult('', -110, '接入中...'); } $result = (new GamePayService())->gamePay($data, 1); if ($result['code'] == 1) { //收集设备信息 $platform = $this->input('platform'); $this->saveDevices($data['gameid'], $data['imeil'], $platform); //更新游戏区服信息 $this->saveGameServer($data['member_id'],$data['gameid'],$data['imeil'],'pay'); //全部平台币支付,并且支付成功时 if($result['data']['pay_status'] == 1) { model('common/Pay')->where('orderid', $result['data']['orderid'])->update(['pay_time' => time()]); // 通知CP,支付成功 (new PayCallback())->callBackToCp($result['data']['orderid']); (new PayLogic())->payWarning($data['member_id'], $data['channel_id'], $data['gameid'], $data['amount']); // 代金卷 if ($data['coupon_member_id'] > 0) { $notifyCoupon = (new YqlData())->notifyCoupon($data['coupon_member_id']); trace('代金卷处理.result=' . json_encode($notifyCoupon), 'Pay@index.$notifyCoupon'); } } $this->jsonResult($result['data'], 1, '订单生成成功', false); } else { $this->jsonResult('', $result['code'], $result['msg']); } // // //先响应客户端请求,返回后,下面代码继续执行 // if (function_exists("fastcgi_finish_request")) { // fastcgi_finish_request(); // } // //收集设备信息 // $platform = $this->input('platform'); // $this->saveDevices($data['gameid'], $data['imeil'], $platform); // //更新游戏区服信息 // $this->saveGameServer($data['member_id'],$data['gameid'],$data['imeil'],'pay'); // //全部平台币支付,并且支付成功时 // if($result['data']['pay_status']) { // // 通知CP,支付成功 // (new PayCallback())->callBackToCp($result['data']['orderid']); // (new PayLogic())->payWarning($data['member_id'], $data['channel_id'], $data['gameid'], $data['amount']); // if ($data['coupon_member_id'] > 0) { // $notifyCoupon = (new YqlData())->notifyCoupon($data['coupon_member_id']); // trace('result:' . json_encode($notifyCoupon), 'Pay@index.$notifyCoupon'); // } // } } /** * 支付处理 */ public function index_bak() { $gameid = $this->input('gameid'); //游戏ID $member_id = $this->input('userid'); //用户ID $serverid = $this->input('serverid'); //服务器ID $servername = $this->input('servername'); //区服名称 $amount = $this->input('amount'); //充值金额 $roleid = $this->input('roleid'); //角色ID $attach = $this->input('attach'); //上一级的扩展参数,多数是订单编号[麻花网络自己聚合自己时,会加个aoyou###前缀] $ptb_amt = $this->input('ptb_amt',0); //平台币使用金额 $imeil = trim($this->input('imeil')); //手机imeil码 $productname= $this->input('productname'); //消费的商品名称 $paytype = $this->input('paytype'); //支付类型 $rolename = $this->input('rolename',''); //角色名 $rolelevel = $this->input('rolelevel',''); //角色角色等级 $orderid = makeOrderid(); $pay_status = 0; //cy_pay表的支付状态 $cp_payflag = 0; //cy_paycpinfo表的支付状态 $memberModel = new Members; $frozenModel = new ChannelFrozen; $cpurlModel = new Cpurl; $gameModel = new Game; $payModel = new PayModel; $payCpinfoModel = new PayCpinfo; $memberChannelGameModel = new MemberChannelGame; $payLogic = new PayLogic(); $checkResult = $this->validate($this->input,'Pay.add'); if (true !== $checkResult) { $this->jsonResult('', 0, $checkResult); } if (empty($ptb_amt) && (substr($paytype,0,4)=='mix-' || $paytype=='ptb')) { $this->jsonResult('', 0, '请输入平台币使用数量'); } $memberInfo = $memberModel->field('username')->where(['id'=>$member_id])->find(); if(empty($memberInfo)){ $this->jsonResult('', 0, '用户不存在'); } //玩家在这款游戏的归属渠道 $channel_id = $memberChannelGameModel->where(['member_id'=>$member_id,'game_id'=>$gameid])->value('channel_id'); if (empty($channel_id)) { $this->jsonResult('', 0, '无关联的归属渠道信息'); } //判断渠道包是否合法 $channelInfo = model('Channel')->where(['status'=>1,'id'=>$this->input('channel_id')])->find(); if(!$channelInfo && intval($this->input('channel_id'))<>config('EMPTY_CHANNEL_ID')) { $this->jsonResult('',0,'游戏包渠道信息不存在'); } else if($channelInfo['level'] <> 3){ $this->jsonResult('',0,'非推广员渠道,不能进行推广,请联系客服'); } //当前游戏的渠道是否禁止消费(非归属渠道) if (isFrozenOption($this->input('channel_id'),$gameid,'consume')) { $this->jsonResult('', 0, '您所在渠道已经被禁止在此游戏消费'); } //充值回调地址 $cpurl = $cpurlModel->where(['appid'=>$this->appInfo['id']])->value('url'); if(empty($cpurl)){ $this->jsonResult('', 0, '没有回调地址,请通知我方配置'); } //游戏信息 $gameInfo = $gameModel->field('order_recheck')->where(['id' => $gameid])->find(); if(empty($gameInfo)){ $this->jsonResult('', 0, '游戏id参数错误'); } if($amount > 100000){ $this->jsonResult('', 0, '您的充值金额过大,请确认是否为合法充值'); } //有使用平台币时 if(!empty($ptb_amt)){ if($ptb_amt > $amount){ $this->jsonResult('', 0, '游戏平台币支付金额选择异常,平台币使用金额大于总金额'); } $userCoinInfo = model('MemberZscoin')->field('id,userid,username,game_id,amount,status')->where(['userid'=>$member_id,'game_id'=>$gameid])->find(); if(empty($userCoinInfo)){ $this->jsonResult('', 0, '您的游戏平台币余额不足'); } else if(!$userCoinInfo['status']){ $this->jsonResult('', 0, '您的游戏平台币账户已被冻结,不能使用'); } else if($userCoinInfo['amount'] < $ptb_amt){ $this->jsonResult('', 0, '您的游戏平台币余额不足'); } $arrPayAmount = $payLogic->calPayAmount($amount,$ptb_amt); } else{ $arrPayAmount = $payLogic->calPayAmount($amount); } //实际支付金额为0时 if (!($arrPayAmount['real_amount']>0)) { $paytype = 'ptb'; //全部用平台币支付 $pay_status = 1; //支付成功 $cp_payflag = 1; //付款时间 $payData['pay_time'] = $this->nowTime; } //有实际支付金额并且支付方式是平台币时 elseif($arrPayAmount['real_amount']>0 && $paytype=='ptb'){ $this->jsonResult('', 0, '平台币余额不足,请使用混合支付'); } elseif($arrPayAmount['real_amount']>0 && $arrPayAmount['real_ptb']>0 && substr($paytype,0,4)<>'mix-'){ $this->jsonResult('', 0, '请选择正确的支付方式'); } //指定时间内,禁止重复下单 if(!requestDuplicateCheck('pay_duplicate_'.$member_id.'_'.$gameid,$this->payRequestLimit)){ $this->jsonResult('', 0, '充值请求过多,请于'.$this->payRequestLimit.'s以后,再次进行充值操作'); } if($payModel->where(['attach'=>$attach,'gameid'=>$gameid])->find()){ $this->redis->del('pay_duplicate_'.$member_id.'_'.$gameid); $this->jsonResult('', 0, '游戏合作方的订单参数不能重复'); } //游戏防沉迷限制 $restrictInfo = model('GameRestrict')->where(['game_id'=>$gameid,'restrict_type'=>'preventhook'])->find(); if($restrictInfo){ $isPreventHook = intval($restrictInfo['restrict_status']); } else{ $settingModel = new Setting; $isPreventHook = intval($settingModel::getSetting('CHILD_LIMIT')); } if($isPreventHook == 2){ // 已实名认证用户做防沉迷判断 $membersTwoInfo = model('MembersTwo')->where(['userid' => $member_id])->find(); $gameInfo = model('Game')->where(['id' => $gameid])->find(); if($gameInfo['game_auth_type'] == 1 || $gameInfo['game_auth_type'] == 2){ //中宣部实名认证 $gameAccountInfo = model('Subaccount')->where(['game_id'=>$gameid,'member_id'=>$member_id])->find(); if($gameAccountInfo){ if($gameAccountInfo['auth_status']==3){ $membersTwoInfo['realname'] = trim($gameAccountInfo['real_name']); $membersTwoInfo['idcard'] = trim($gameAccountInfo['idcard_num']); } else if($gameAccountInfo['auth_status']==1){ $membersTwoInfo['realname'] = ''; $membersTwoInfo['idcard'] = ''; } else{ $membersTwoInfo['realname'] = ''; $membersTwoInfo['idcard'] = ''; } } else{ $membersTwoInfo['realname'] = ''; $membersTwoInfo['idcard'] = ''; } } if ($membersTwoInfo && !empty($membersTwoInfo['realname']) && !empty($membersTwoInfo['idcard']) && $membersTwoInfo['realname']<>-1 && $membersTwoInfo['idcard']<>-1) { $totalMonthRechargeAmt = model('Pay')->where(['userid' => $member_id,'status'=>1,'create_time'=>['egt',strtotime(date('Y-m-01'))]])->sum('amount'); // if (isMeetAgeByIDCard($membersTwoInfo['idcard'],0,8)){ // $this->jsonResult('', 0, '未满8岁周岁无法充值'); // } // else if(isMeetAgeByIDCard($membersTwoInfo['idcard'],8,16)){ // if($amount>50){ // $this->jsonResult('', 0, '未满16周岁,单次充值不可超过50元'); // } // if(($totalMonthRechargeAmt+$amount) > 200){ // $this->jsonResult('', 0, '未满16周岁,每月累充不可超过200元'); // } // } // else if(isMeetAgeByIDCard($membersTwoInfo['idcard'],16,18)){ // if($amount>100){ // $this->jsonResult('', 0, '未满18周岁,单次充值不可超过100元'); // } // if(($totalMonthRechargeAmt+$amount) > 400){ // $this->jsonResult('', 0, '未满18周岁,每月累充不可超过400元'); // } // } if (isMeetAgeByIDCard($membersTwoInfo['idcard'],0,12)){ $this->jsonResult('', 0, '未满12周岁的未成年用户,无法进行充值'); }else if(isMeetAgeByIDCard($membersTwoInfo['idcard'],12,16)){ if($amount>50){ $this->jsonResult('', 0, '12周岁以上未满16周岁的未成年用户,单次充值金额不得超过50元,每月累计充值上限为200元'); } if(($totalMonthRechargeAmt+$amount) > 200){ $this->jsonResult('', 0, '12周岁以上未满16周岁的未成年用户,单次充值金额不得超过50元,每月累计充值上限为200元'); } } else if(isMeetAgeByIDCard($membersTwoInfo['idcard'],16,18)){ if($amount>100){ $this->jsonResult('', 0, '16周岁以上未满18周岁的未成年用户,单次充值金额不得超过100元,每月累计充值上限为400元'); } if(($totalMonthRechargeAmt+$amount) > 400){ $this->jsonResult('', 0, '16周岁以上未满18周岁的未成年用户,单次充值金额不得超过100元,每月累计充值上限为400元'); } } } } $user_ip = request()->ip(); $payData['orderid'] = $orderid; // $payData['use_coin_sn'] = !empty($mc_id) ? $coinInfo['coin_sn'] : ''; //平台币劵订单号 $payData['amount'] = $amount; $payData['real_amount'] = $arrPayAmount['real_amount']; $payData['real_ptb'] = $arrPayAmount['real_ptb']; // $payData['real_ptb_amount'] = $arrPayAmount['real_ptb_amount']; $payData['userid'] = $member_id; $payData['username'] = $memberInfo['username']; $payData['roleid'] = $roleid; $payData['rolename'] = $rolename; $payData['rolelevel'] = $rolelevel; $payData['paytype'] = $paytype; $payData['productname'] = $productname; $payData['serverid'] = $serverid; $payData['servername'] = $servername; $payData['gameid'] = $gameid; $payData['status'] = $pay_status; $payData['ip'] = request()->ip(); $payData['imeil'] = $imeil; $payData['create_time'] = $this->nowTime; $payData['channel_id'] = $channel_id; $payData['recheck_status'] = $gameInfo['order_recheck']; $payData['attach'] = $attach; // 启动事务 Db::startTrans(); try{ $result = []; //返回值 $payModel->insert($payData); //如果是自己聚合自己时,支付回调地址固定 if(mb_substr($attach,0,8,'UTF-8')=='xkhyn###'){ $cpurl = Config::get('self_complex_callback_url'); $attach = str_replace("xkhyn###","",$attach); //聚合的订单编号,去掉[aoyou###]前缀 } //给Cp的用户名用子账号名 $paycp_username = (!empty($this->input('sub_username')) ? $this->input('sub_username') : $memberInfo['username']); $str = "orderid=".urlencode($orderid)."&username=".urlencode($paycp_username)."&gameid=".$gameid."&roleid=".urlencode($roleid)."&serverid=".urlencode($serverid)."&paytype=".urlencode($paytype)."&amount=".$amount."&paytime=".$this->nowTime."&attach=".urlencode($attach); $param = $str."&appkey=".urlencode($this->appInfo['appkey']); $md5params = md5($param); $params = $str . "&sign=".urlencode($md5params); $paycpData['orderid'] = $orderid; $paycpData['fcallbackurl'] = $cpurl; $paycpData['params'] = $params; $paycpData['create_time'] = $this->nowTime; $paycpData['payflag'] = $cp_payflag; //写入cy_paycpinfo表数据 $payCpinfoModel->insert($paycpData); //如果使用了平台币 if($arrPayAmount['real_ptb']>0){ $payLogic->saveCoinData($userCoinInfo,$payData); } //第三方支付用的商品简单描述 (去除&+等特殊字符) $payBody = preg_replace("/[\&\+]+/", '', $productname); //支付方式是支付宝或者支付宝混合支付时 if($paytype=='zfb' || $paytype=='mix-zfb'){ //支付宝支付参数 $alipayParam = $this->getAlipayAopParam($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['alipay_param'=>$alipayParam]; } //支付宝WAP H5支付 elseif($paytype=='zfb-h5'){ //支付宝支付参数 $alipayParam = $this->getAlipayWapAopParam($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['alipay_param'=>$alipayParam]; } elseif($paytype=='zfb-wap'){ //支付宝支付参数 $alipayParam = $this->getAlipayWapPostAopParam($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['alipay_param'=>$alipayParam]; } elseif($paytype=='wx-wap'){ //微信汇付宝支付参数 $wxParam = $this->getWxWapPostAopParam($orderid,$arrPayAmount['real_amount'],$payBody,$user_ip); $result = ['wxpayh5_param'=>$wxParam]; } elseif($paytype=='wxsmzf'){ //微信汇付宝扫码支付参数 $wxsmParam = $this->getWxWapsmPostAopParam($orderid,$arrPayAmount['real_amount'],$payBody,$user_ip); $result = ['wxpaysm_param'=>$wxsmParam]; } //支付方式是威富通-微信支付或者威富通-微信支付混合支付时 elseif($paytype=='swiftwxpay' || $paytype=='mix-swiftwxpay'){ //支付宝支付参数 $swiftpayParam = $this->swiftpayProcess($orderid,$arrPayAmount['real_amount'],$payBody); $swiftpayParam['orderid'] = $orderid; $result = ['swiftpay_param'=>$swiftpayParam]; } //支付方式是现在-微信支付或者现在-微信支付混合支付时 elseif($paytype=='ipaywxpay' || $paytype=='mix-ipaywxpay') { $ipay_param = $this->getIpaynowParam($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['ipay_param'=>$ipay_param]; } //支付方式是微信官方h5支付或者微信官方h5混合支付时 elseif($paytype=='wxpay-h5' || $paytype=='mix-wxpay-h5') { if($arrPayAmount['real_amount']>3000){ $this->redis->del('pay_duplicate_'.$member_id.'_'.$gameid); $this->jsonResult('', 0, '微信单笔支付限额3000元,您可选择其它支付'); } $wxpayh5_param = $this->getWxpayH5Param($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['wxpayh5_param'=>$wxpayh5_param]; } //支付方式是米花微信h5支付或者米花微信h5混合支付时 elseif($paytype=='wxpay-h5-mihua' || $paytype=='mix-wxpay-h5-mihua') { if($arrPayAmount['real_amount']>3000){ $this->redis->del('pay_duplicate_'.$member_id.'_'.$gameid); $this->jsonResult('', 0, '微信单笔支付限额3000元,您可选择其它支付'); } $wxpayh5_param = $this->getMihuaWxpayH5Param($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['wxpayh5_param'=>$wxpayh5_param]; } //支付方式是快接微信h5支付或者快接微信h5混合支付时 elseif($paytype=='wxpay-h5-kj' || $paytype=='mix-wxpay-h5-kj') { if($arrPayAmount['real_amount']>3000){ $this->redis->del('pay_duplicate_'.$member_id.'_'.$gameid); $this->jsonResult('', 0, '微信单笔支付限额3000元,您可选择其它支付'); } $wxpayh5_param = $this->getKjWxpayH5Param($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['wxpayh5_param'=>$wxpayh5_param]; } //支付方式是威富通中信银行-微信WAP支付处理时 elseif($paytype=='swiftccbwxpay' || $paytype=='mix-swiftccbwxpay') { $ccb_param = $this->swiftpayWeixinwapProcess($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['swiftccbwxpay_param'=>$ccb_param]; } //支付方式是米花支付宝h5支付或者米花支付宝h5混合支付时 elseif($paytype=='zfb-h5-mihua' || $paytype=='mix-zfb-h5-mihua') { $alipayh5_param = $this->getMihuaAlipayH5Param($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['alipayh5_param'=>$alipayh5_param]; } //支付方式是快接支付宝h5支付或者快接支付宝h5混合支付时 elseif($paytype=='zfb-h5-kj' || $paytype=='mix-zfb-h5-kj') { $alipayh5_param = $this->getKjZfbH5Param($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['alipayh5_param'=>$alipayh5_param]; } //支付方式是商盟微信h5支付或者商盟微信h5混合支付时 elseif($paytype=='wxpay-h5-sumpay' || $paytype=='mix-wxpay-h5-sumpay') { if($arrPayAmount['real_amount']>3000){ $this->redis->del('pay_duplicate_'.$member_id.'_'.$gameid); $this->jsonResult('', 0, '微信单笔支付限额3000元,您可选择其它支付');javascript:; } $wxpayh5_param = $this->getSumpayWxpayH5Param($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['wxpayh5_param'=>$wxpayh5_param]; //支付宝扫码支付 }elseif($paytype=='kdh5'){ //if($arrPayAmount['real_amount']>3000){ // $this->redis->del('pay_duplicate_'.$member_id.'_'.$gameid); // $this->jsonResult('', 0, '微信单笔支付限额3000元,您可选择其它支付'); //} $kdh5_param = $this->getkdh5weixinParam($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['kdh5_param'=>$kdh5_param]; //支付宝扫码支付 }elseif ($paytype == 'zfbsmzf'){ $qrcodePay = $this->chargeByZfbWap($orderid, $arrPayAmount['real_amount'], $payBody) ; //$qrcodePay = htmlspecialchars($qrcodePay); $result1['mweb_url'] = $qrcodePay; $result['zfbsmzf_param'] = $result1; $result['orderid'] = $orderid; $result['referer'] = "com.yiyou.zfb"; } //第三方现金支付 支付宝 elseif ($paytype == 'xzzfbzf'){ $urlPays = $this->chargeByxzzfbzf($orderid, $arrPayAmount['real_amount'], $payBody) ; // $res_info['mweb_url'] = $urlPays; $result['xzzfbzf_param'] = $urlPays; // $result['orderid'] = $orderid; // $result['referer'] = "com.yiyou.zfb"; }elseif($paytype=='old-zfb-wap'){ //支付宝支付参数 $alipayParam = $this->getAlipayWapPostAopParam($orderid,$arrPayAmount['real_amount'],$payBody); $result = ['alipay_param'=>$alipayParam]; } //全部平台币支付,并且支付成功时 if($pay_status){ //更新member表的total_pay_amount $memberModel->where(['id'=>$member_id])->update(['total_pay_amount'=>Db::raw('total_pay_amount+'.$amount)]); } $this->redis->del('pay_duplicate_'.$member_id.'_'.$gameid); // 提交事务 Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); $this->jsonResult('', 0, '订单生成失败'.$e->getMessage()); } $result['pay_status'] = $pay_status; //支付状态 $result['orderid'] = $orderid; $this->jsonResult($result, 1, '订单生成成功',false); //先响应客户端请求,返回后,下面代码继续执行 fastcgi_finish_request(); //收集设备信息 $platform = $this->input('platform'); $this->saveDevices($gameid,$imeil,$platform); //更新游戏区服信息 $this->saveGameServer($member_id,$gameid,$imeil,'pay'); //全部平台币支付,并且支付成功时 if($pay_status){ // 通知CP,支付成功 (new PayCallback())->callBackToCp($orderid); (new PayLogic())->payWarning($member_id, $channel_id, $gameid, $amount); } exit; } /** * 第三方现金支付 支付宝 * @return string */ private function chargeByxzzfbzf($orderid,$real_amount,$productname,$productdesc='') { $productdesc = "订单支付"; $productname = preg_replace("/[\&\+]+/", '', $productname); // 主题(过滤特殊字符) $subject = preg_replace("/[\&\+]+/", '', $productdesc); // 商品描述信息(过滤特殊字符) $consumerCreateIp = $this->getUserIp(); //需上传用户真实ip $key = Config::get('h5_alipay_config')['key']; $req=array(); $req["appId"] = Config::get('h5_alipay_config')['zfbAppId']; $req["deviceType"] = '0601'; $req["frontNotifyUrl"] = Config::get('h5_alipay_config')['return_url'];//'http://sdkapi.46yx.com/v1.demo/zfbalipays.html';//前台通知,三方支付宝0模式有效,官方支付宝0、1模式有效,微信0模式有效 $req["funcode"] = 'WP001'; $req["mhtCharset"] = 'UTF-8'; $req["mhtCurrencyType"] = '156'; $req["mhtOrderAmt"] = $real_amount*100; $req["mhtOrderDetail"] = $subject; $req["mhtOrderName"] = $productname; $req["mhtOrderNo"] = $orderid; $req["mhtOrderStartTime"] = date("YmdHis"); $req["mhtOrderTimeOut"] = '3600'; $req["mhtOrderType"] = '01'; $req["mhtReserved"] = "test"; $req["mhtSignType"] = 'MD5'; $req["notifyUrl"] = Config::get('h5_alipay_config')['notify_url']; $req["outputType"] = 1;// 0 默认值 $req["payChannelType"] = 12; //12 支付宝 //13 微信 //20 银联 //25 手Q $req["version"] = "1.0.0"; $req["consumerCreateIp"] = $consumerCreateIp; //微信必填// outputType=2时 无须上送该值 $req_str = $this->getToStr($req, $key); $service = 'https://pay.ipaynow.cn'; $res = $this->xzzfbzfpost($service, $req_str); $code = (bool)stripos($res, '&tn='); if($code) { $arr = explode('&', $res); $gettn = ''; foreach($arr as $v) { $tn = explode('=', $v); if($tn[0] == 'tn'){ $gettn = $tn[1]; } } $tn=urldecode($gettn); $pay_return['mweb_url'] = $tn; $pay_return['referer'] = 'com.yiyou.zfb'; return $pay_return; // return $tn; } else { $this->jsonResult('', 0, '订单生成失败',false); } } //获取真实IP,可以根据实际情况自行获取 function getUserIp() { try { $info = getCurl('https://myip.ipip.net'); if (!$info) { $info = file_get_contents('http://myip.ipip.net'); } $ipstr = explode(':', $info); $ip = explode(' ', $ipstr[1]); return $ip[0]; } catch (Exception $e) { return request()->ip(); } } //获取参数 function getDate($arr) { $result = array(); $funcode = $arr['funcode']; foreach($arr as $key => $value) { if (($funcode=='WP001')&&!($key=='mhtSignature'||$key=='signature')){ $result[$key]=$value; continue; } if(($funcode== 'N001'||$funcode=='N002')&&!($key== 'signature')){ $result[$key]=$value; continue; } if (($funcode=='MQ002')&&!($key=='mhtSignature'||$key=='signature')) { $result[$key]=$value; continue; } } return $result; } //获取签名 function createSignaTure($arr, $key) { $date = $this -> getDate($arr); ksort($date); $str = ''; foreach($date as $k => $v) { if($v != '') { $str .= $k.'='.$v.'&'; } } $str .= strtolower(md5($key)); return(strtolower(md5($str))); } //获取请求参数串 function getToStr($arr, $key) { $date = $this -> getDate($arr); $info = $this -> createSignaTure($arr, $key); $str = ''; foreach($date as $k => $v) { if($v != '') { $str .= $k.'='.urlencode($v).'&'; } } $str .= 'mhtSignature'.'='.$info; log_message($str."\r\n",'log',LOG_PATH . '../paylog/'); //file_put_contents('../baowen.log', $str."\r\n"); return $str; } /** * 支付宝扫码支付 * @param $orderid * @param $real_amount * @param $productname * @param $productdesc */ private function chargeByZfbWap($orderid, $real_amount, $productname, $productdesc = '') { vendor('alipayAop.AopSdk'); $aop = new \AopClient(); $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; //网关地址要使用沙箱网关alipaydev $aop->appId = "2021002156644399"; $aop->rsaPrivateKey = file_get_contents(Config::get('alipayAop')['private_key']); $aop->alipayrsaPublicKey = file_get_contents(Config::get('alipayAop')['alipay_public_key']); $aop->format = "json"; $aop->apiVersion = '1.0'; $aop->postCharset = 'UTF-8'; $aop->signType = "RSA2"; //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay $request = new \AlipayTradePagePayRequest(); $productname = preg_replace("/[\&\+]+/", '', $productname); // 主题(过滤特殊字符) $subject = preg_replace("/[\&\+]+/", '', $productdesc); // 商品描述信息(过滤特殊字符) //SDK已经封装掉了公共参数,这里只需要传入业务参数 $info = json_encode(['body' => $subject, 'subject' => $productname, 'out_trade_no' => $orderid, 'timeout_express' => '30m', 'total_amount' => $real_amount, 'product_code' => 'FAST_INSTANT_TRADE_PAY'], JSON_UNESCAPED_UNICODE); $request->setBizContent($info); // $request->setReturnUrl("http://" . $_SERVER['HTTP_HOST'] . "/v1.user_center/returnUrl.html"); // $request->setNotifyUrl("http://" . $_SERVER['HTTP_HOST'] . "/v1.platform_pay/notify.html"); $request->setNotifyUrl(Config::get('alipayAop')['notify_url']); $result = $aop->pageExecute($request); return $result; } /** * 汇付宝 微信H5支付 * @param $orderid * @param $real_amount * @param $productname * @param string $productdesc * @return mixed|string */ private function getWxWapPostAopParam($orderid,$real_amount,$productname,$productdesc='',$user_ip='127.0.0.1') { //获取用户IP $user_ip = $user_ip; $version = "1"; $agent_id = Config::get('wxwappay-h5')['mch_id'];//商户编号,(汇付宝商户内码:七位整数数字) $sign_key = Config::get('wxwappay-h5')['key']; $notify_url = Config::get('wxwappay-h5')['notify_url'];//支付后返回的商户处理页面,URL参数是以http://或https://开头的完整URL地址(后台处理),提交的url地址必须外网能访问到,否则无法通知商户。值可以为空,但不可以为null。 $scene = "h5";//支付方式,h5表示h5,qr表示扫码(如支付类型为扫码,payment_mode传UnifiedOrder返回二维码url),jsapi表示公众号(微信内拉起),app表示app拉起支付(值均为小写) $pay_type = "30";//支付类型30 $agent_bill_id = $orderid;//商户系统内部的订单号(要保证唯一) $agent_bill_time = date('YmdHis', time());//提交单据的时间yyyyMMddHHmmss,该参数共计14位,当时不满14位时,在后面加0补足14位 $pay_amt = $real_amount;//订单总金额 不可为空。小数点后保留两位 $return_url = Config::get('wxwappay-h5')['return_url']."?URLscheme=yiyouweixin";//支付后返回的商户显示页面,URL参数是以http://或https://开头的完整URL地址(前台显示),原则上该参数与notify_url提交的参数不一致。值可以为空,但不可以为null。 $user_ip = str_replace(".","_",$user_ip);//用户所在客户端的真实ip其中的“.”替换为“_” 。因为近期我方发现用户在提交数据时,user_ip在网络层被篡改,导致签名错误,所以我们规定使用这种格式。 $productname=iconv("UTF-8", "gbk", $productname); $goods_name = $productname;//商品名称,不能为空(不参加签名) $remark = "";//商户自定义,原样返回,可以为空。 $goods_note = ""; $payment_mode = "cashier";//收银台=cashier,接口=UnifiedOrder(目前支持扫码,app) $n = "南京麻花网络"; $fileName=iconv("UTF-8", "gbk", $n); $strs='{"s":"WAP","n":"'.$fileName.'","id":"http://46yx.com"}'; $str = base64_encode($strs); $meta_option =urlencode($str);//加密后的结果 $bank_card_type = "-1";//银行类型:未知=-1,储蓄卡=0,信用卡=1。 $timestamp = "";//时间戳,传了订单有效时间上下1min,从1970年1月1日0时到现在的毫秒数,传了参与签名,签名位置在key前面。 $sign_type = "MD5";//签名类型,MD5\RSA\RSA2 $data['version']=$version; $data['scene']=$scene; $data['payment_mode']=$payment_mode; $data['agent_id']=$agent_id; $data['agent_bill_id']=$agent_bill_id; $data['agent_bill_time']=$agent_bill_time; $data['pay_type']=$pay_type; $data['pay_amt']=$pay_amt; $data['notify_url']=$notify_url; $data['return_url']=$return_url; $data['user_ip']=$user_ip; $data['goods_name']=$goods_name; $data['goods_note']=$goods_note; $data['remark']=$remark; $data['meta_option']=$meta_option; $data['bank_card_type']=$bank_card_type; $sign_str = ''; $sign_str = $sign_str.'version='.$version; $sign_str = $sign_str.'&agent_id='.$agent_id; $sign_str = $sign_str.'&agent_bill_id='.$agent_bill_id; $sign_str = $sign_str.'&agent_bill_time='.$agent_bill_time; $sign_str = $sign_str.'&pay_type='.$pay_type; $sign_str = $sign_str.'&pay_amt='.$pay_amt; $sign_str = $sign_str.'¬ify_url='.$notify_url; $sign_str = $sign_str.'&return_url='.$return_url; $sign_str = $sign_str.'&user_ip='.$user_ip; $sign_str = $sign_str.'&bank_card_type='.$bank_card_type; $sign_str = $sign_str.'&remark='.urlencode($remark); $sign_str = $sign_str.'&key='.$sign_key; $sign = md5($sign_str); ////MD5\RSA\RSA2签名结果 $data['sign']=$sign; $urls = Config::get('wxwappay-h5')['pay_url']; $response = $this->postXmlCurl($data,$urls); $redirectUrl = ""; if(!empty($response)) { if($response['ret_code'] == '0000') { $redirectUrl = $response['redirectUrl']; $ret_code = $response['ret_code']; $ret_msg = $response['ret_msg']; $hf_sign = md5('redirectUrl='.$redirectUrl.'&ret_code='.$ret_code.'&ret_msg='.$ret_msg.'&key='.$sign_key); if($hf_sign != $response['sign']) { $this->jsonResult('', 0, '订单生成失败',false); } }else{ $this->jsonResult('', 0, '订单生成失败',false); } }else{ $this->jsonResult('', 0, '订单生成失败',false); } $pay_return['mweb_url'] = $redirectUrl; $pay_return['referer'] = Config::get('wxpay-h5')['referer']; return $pay_return; } /** * 汇付宝 微信扫码支付 * @param $orderid * @param $real_amount * @param $productname * @param string $productdesc * @return mixed|string */ private function getWxWapsmPostAopParam($orderid,$real_amount,$productname,$productdesc='',$user_ip='127.0.0.1') { //获取用户IP $user_ip = $user_ip; $version = "1"; $agent_id = Config::get('wxwappay-h5')['mch_id'];//商户编号,(汇付宝商户内码:七位整数数字) $sign_key = Config::get('wxwappay-h5')['key']; $notify_url = Config::get('wxwappay-h5')['notify_url'];//支付后返回的商户处理页面,URL参数是以http://或https://开头的完整URL地址(后台处理),提交的url地址必须外网能访问到,否则无法通知商户。值可以为空,但不可以为null。 $scene = "qr";//支付方式,h5表示h5,qr表示扫码(如支付类型为扫码,payment_mode传UnifiedOrder返回二维码url),jsapi表示公众号(微信内拉起),app表示app拉起支付(值均为小写) $pay_type = "30";//支付类型30 $agent_bill_id = $orderid;//商户系统内部的订单号(要保证唯一) $agent_bill_time = date('YmdHis', time());//提交单据的时间yyyyMMddHHmmss,该参数共计14位,当时不满14位时,在后面加0补足14位 $pay_amt = $real_amount;//订单总金额 不可为空。小数点后保留两位 $return_url = Config::get('wxwappay-h5')['return_url']."?URLscheme=yiyouweixin";//支付后返回的商户显示页面,URL参数是以http://或https://开头的完整URL地址(前台显示),原则上该参数与notify_url提交的参数不一致。值可以为空,但不可以为null。 $user_ip = str_replace(".","_",$user_ip);//用户所在客户端的真实ip其中的“.”替换为“_” 。因为近期我方发现用户在提交数据时,user_ip在网络层被篡改,导致签名错误,所以我们规定使用这种格式。 $goods_name = $productname;//商品名称,不能为空(不参加签名) $goods_name=iconv("UTF-8", "gbk", $goods_name); $remark = "";//商户自定义,原样返回,可以为空。 $goods_note = ""; $payment_mode = "cashier";//收银台=cashier,接口=UnifiedOrder(目前支持扫码,app) $n = "南京麻花网络"; $fileName=iconv("UTF-8", "gbk", $n); $strs='{"s":"WAP","n":"'.$fileName.'","id":"http://46yx.com"}'; $str = base64_encode($strs); $meta_option =urlencode($str);//加密后的结果 $bank_card_type = "-1";//银行类型:未知=-1,储蓄卡=0,信用卡=1。 $timestamp = "";//时间戳,传了订单有效时间上下1min,从1970年1月1日0时到现在的毫秒数,传了参与签名,签名位置在key前面。 $sign_type = "MD5";//签名类型,MD5\RSA\RSA2 $data['version']=$version; $data['scene']=$scene; $data['payment_mode']=$payment_mode; $data['agent_id']=$agent_id; $data['agent_bill_id']=$agent_bill_id; $data['agent_bill_time']=$agent_bill_time; $data['pay_type']=$pay_type; $data['pay_amt']=$pay_amt; $data['notify_url']=$notify_url; $data['return_url']=$return_url; $data['user_ip']=$user_ip; $data['goods_name']=$goods_name; $data['goods_note']=$goods_note; $data['remark']=$remark; $data['meta_option']=$meta_option; $data['bank_card_type']=$bank_card_type; $sign_str = ''; $sign_str = $sign_str.'version='.$version; $sign_str = $sign_str.'&agent_id='.$agent_id; $sign_str = $sign_str.'&agent_bill_id='.$agent_bill_id; $sign_str = $sign_str.'&agent_bill_time='.$agent_bill_time; $sign_str = $sign_str.'&pay_type='.$pay_type; $sign_str = $sign_str.'&pay_amt='.$pay_amt; $sign_str = $sign_str.'¬ify_url='.$notify_url; $sign_str = $sign_str.'&return_url='.$return_url; $sign_str = $sign_str.'&user_ip='.$user_ip; $sign_str = $sign_str.'&bank_card_type='.$bank_card_type; $sign_str = $sign_str.'&remark='.urlencode($remark); $sign_str = $sign_str.'&key='.$sign_key; $sign = md5($sign_str); ////MD5\RSA\RSA2签名结果 $data['sign']=$sign; $urls = Config::get('wxwappay-h5')['pay_url']; $response = $this->postXmlCurl($data,$urls); $redirectUrl = ""; if(!empty($response)) { if($response['ret_code'] == '0000') { $redirectUrl = $response['redirectUrl']; $ret_code = $response['ret_code']; $ret_msg = $response['ret_msg']; $hf_sign = md5('redirectUrl='.$redirectUrl.'&ret_code='.$ret_code.'&ret_msg='.$ret_msg.'&key='.$sign_key); if($hf_sign != $response['sign']) { $this->jsonResult('', 0, '订单生成失败',false); } }else{ $this->jsonResult('', 0, '订单生成失败',false); } }else{ $this->jsonResult('', 0, '订单生成失败',false); } $pay_return['mweb_url'] = $redirectUrl; $pay_return['referer'] = Config::get('wxpay-h5')['referer']; return $pay_return; } /** * 获取支付宝支付参数 * * @param string $orderid 订单号 * @param float $real_amount 支付金额 * @param string $productname 商品名称 * @param string $productdesc 描述 * * @return string 支付参数字符串 */ private function getAlipayParam($orderid,$real_amount,$productname,$productdesc='') { // 支付宝要求参数格式:key1="value1"&key2="value2",不要修改 $ali['partner'] = Config::get('alipay')['partner']; // 合作身份者ID $ali['out_trade_no'] = $orderid; // 订单号 $ali['subject'] = preg_replace("/[\&\+]+/", '', $productname); // 主题(过滤特殊字符) $ali['body'] = preg_replace("/[\&\+]+/", '', $productdesc); // 商品描述信息(过滤特殊字符) $ali['total_fee'] = $real_amount; // 支付金额 $ali['notify_url'] = Config::get('alipay')['notify_url']; // 回调地址 $ali['service'] = "mobile.securitypay.pay"; $ali['_input_charset'] = Config::get('alipay')['input_charset']; $ali['payment_type'] = Config::get('alipay')['payment_type']; $ali['seller_id'] = Config::get('alipay')['seller_id']; $ali['it_b_pay'] = '1m'; // 支付超时时间 vendor('alipay.lib.AlipaySubmit'); $alipay = new \AlipaySubmit(Config::get('alipay')); //生成支付宝支付参数字符串 $str = $alipay->buildRequestParaToString($ali); return $str; } /** * 获取支付宝支付参数 * * @param string $orderid 订单号 * @param float $real_amount 支付金额 * @param string $productname 商品名称 * @param string $productdesc 描述 * * @return string 支付参数字符串 */ private function getAlipayAopParam($orderid,$real_amount,$productname,$productdesc='') { //Alipay Aop Sdk支付发起 vendor('alipayAop.AopSdk'); $aop = new \AopClient(); $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; $aop->appId = Config::get('alipayAop')['appId']; $aop->rsaPrivateKey = file_get_contents(Config::get('alipayAop')['private_key']); $aop->alipayrsaPublicKey = file_get_contents(Config::get('alipayAop')['alipay_public_key']); $aop->apiVersion = '1.0'; $aop->signType = Config::get('alipayAop')['sign_type']; $aop->postCharset = 'utf-8'; $aop->format = 'json'; $request = new \AlipayTradeAppPayRequest(); $bizcontent = array(); $bizcontent['subject'] = preg_replace("/[\&\+]+/", '', $productname); // 主题(过滤特殊字符) $bizcontent['body'] = preg_replace("/[\&\+]+/", '', $productdesc); // 商品描述信息(过滤特殊字符) $bizcontent['out_trade_no'] = $orderid; // 订单号 $bizcontent['timeout_express'] = '30m'; // 超时时间 $bizcontent['total_amount'] = $real_amount; // 支付金额 $bizcontent['product_code'] = 'QUICK_MSECURITY_PAY'; // 支付方式 $request->setBizContent(json_encode($bizcontent)); $request->setNotifyUrl(Config::get('alipayAop')['notify_url']); $result = $aop->sdkExecute($request); // echo htmlspecialchars($result); return $result; } private function getAlipayWapPostAopParam($orderid,$real_amount,$productname,$productdesc='') { //Alipay Aop Sdk支付发起 vendor('alipayAop.AopSdk'); $aop = new \AopClient(); $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; $aop->appId = Config::get('alipayAop')['appId']; $aop->rsaPrivateKey = file_get_contents(Config::get('alipayAop')['private_key']); $aop->alipayrsaPublicKey = file_get_contents(Config::get('alipayAop')['alipay_public_key']); $aop->apiVersion = '1.0'; $aop->signType = Config::get('alipayAop')['sign_type']; $aop->postCharset = 'utf-8'; $aop->format = 'json'; $request = new \AlipayTradeWapPayRequest(); $bizcontent = array(); $bizcontent['subject'] = preg_replace("/[\&\+]+/", '', $productname); // 主题(过滤特殊字符) $bizcontent['body'] = preg_replace("/[\&\+]+/", '', $productdesc); // 商品描述信息(过滤特殊字符) $bizcontent['out_trade_no'] = $orderid; // 订单号 $bizcontent['timeout_express'] = '30m'; // 超时时间 $bizcontent['total_amount'] = $real_amount; // 支付金额 $bizcontent['product_code'] = 'QUICK_MSECURITY_PAY'; // 支付方式 $request->setBizContent(json_encode($bizcontent)); $request->setNotifyUrl(Config::get('alipayAop')['notify_url']); $result = $aop->pageExecute($request); // echo htmlspecialchars($result); $pay_return['mweb_url'] = $result; $pay_return['referer'] = "com.yiyou.zfb"; return $pay_return; } private function getAlipayWapAopParam($orderid,$real_amount,$productname,$productdesc='') { //Alipay Aop Sdk支付发起 vendor('alipayAop.AopSdk'); $aop = new \AopClient(); $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; $aop->appId = Config::get('alipayAop')['appId']; $aop->rsaPrivateKey = file_get_contents(Config::get('alipayAop')['private_key']); $aop->alipayrsaPublicKey = file_get_contents(Config::get('alipayAop')['alipay_public_key']); $aop->apiVersion = '1.0'; $aop->signType = Config::get('alipayAop')['sign_type']; $aop->postCharset = 'utf-8'; $aop->format = 'json'; $request = new \AlipayTradeWapPayRequest(); $bizcontent = array(); $bizcontent['subject'] = preg_replace("/[\&\+]+/", '', $productname); // 主题(过滤特殊字符) $bizcontent['body'] = preg_replace("/[\&\+]+/", '', $productdesc); // 商品描述信息(过滤特殊字符) $bizcontent['out_trade_no'] = $orderid; // 订单号 $bizcontent['timeout_express'] = '30m'; // 超时时间 $bizcontent['total_amount'] = $real_amount; // 支付金额 $bizcontent['product_code'] = 'QUICK_MSECURITY_PAY'; // 支付方式 $request->setBizContent(json_encode($bizcontent)); $request->setNotifyUrl(Config::get('alipayAop')['notify_url']); $result = $aop->pageExecute($request,"GET"); // echo htmlspecialchars($result); return $result; } /** * 威富通-微信支付处理 * * @param string $orderid 订单号 * @param float $real_amount 支付金额(单位元) * @param string $productname 商品名称 * * @return array 微信支付参数 * */ private function swiftpayProcess($orderid,$real_amount,$productname) { vendor('swiftpay.ClientResponseHandler','.class.php'); vendor('swiftpay.RequestHandler','.class.php'); vendor('swiftpay.PayHttpClient','.class.php'); vendor('swiftpay.Utils','.class.php'); $resHandler = new \ClientResponseHandler(); //后台应答类 $requestHandler = new \RequestHandler(); //请求类 $pay = new \PayHttpClient(); $requestHandler->setKey(Config::get('swiftpay')['key']); $requestHandler->setSignType('MD5'); $requestHandler->setParameter('service','pay.weixin.raw.app'); //接口类型 $requestHandler->setParameter('version','2.0'); $requestHandler->setParameter('mch_id',Config::get('swiftpay')['mch_id']); //商户号,由平台分配 $requestHandler->setParameter('appid',Config::get('swiftpay')['appid']); $requestHandler->setParameter('out_trade_no',$orderid); $requestHandler->setParameter('body',$productname); $requestHandler->setParameter('total_fee',$real_amount*100); //以分为单位 $requestHandler->setParameter('mch_create_ip',request()->ip()); $requestHandler->setParameter('notify_url',Config::get('swiftpay')['notify_url']); $requestHandler->setParameter('nonce_str',mt_rand(time(),time()+rand())); //随机字符串,必填项,不长于 32 位 $requestHandler->setParameter('sub_appid',Config::get('swiftpay')['appid']); //微信开放平台审核通过的移动应用AppID $requestHandler->createSign();//创建签名 $data = \Utils::toXml($requestHandler->getAllParameters()); $pay->setReqContent($requestHandler->getGateURL(),$data); //执行http调用 if($pay->call()){ $resHandler->setContent($pay->getResContent()); //设置应答类内容 $resHandler->setKey($requestHandler->getKey()); $resHandler->setParameter('sign_type', 'MD5'); if($resHandler->isTenpaySign()){ //当返回状态与业务结果都为0时才返回,其它结果请查看接口文档 if($resHandler->getParameter('status') == 0 && $resHandler->getParameter('result_code') == 0){ return json_decode($resHandler->getParameter('pay_info'),true); }else{ throw new \Exception(' Error Info:'.$resHandler->getParameter('message')); } } throw new \Exception(' Error Info:'.$resHandler->getParameter('message')); }else{ throw new \Exception(' Error Info:'.$pay->getErrInfo()); } } /** * 威富通中信银行-微信WAP支付处理 * * @param string $orderid 订单号 * @param float $real_amount 支付金额(单位元) * @param string $productname 商品名称 * * @return array 微信支付参数 * */ private function swiftpayWeixinwapProcess($orderid,$real_amount,$productname) { vendor('swiftpay.ClientResponseHandler','.class.php'); vendor('swiftpay.RequestHandler','.class.php'); vendor('swiftpay.PayHttpClient','.class.php'); vendor('swiftpay.Utils','.class.php'); $resHandler = new \ClientResponseHandler(); //后台应答类 $requestHandler = new \RequestHandler(); //请求类 $pay = new \PayHttpClient(); $requestHandler->setRSAKey(Config::get('swiftccbwxpay')['private_key']); $requestHandler->setSignType('RSA_1_256'); $requestHandler->setParameter('service','pay.weixin.wappay'); //接口类型 $requestHandler->setParameter('version','2.0'); $requestHandler->setParameter('sign_type','RSA_1_256'); $requestHandler->setParameter('mch_id',Config::get('swiftccbwxpay')['mch_id']); //商户号,由平台分配 $requestHandler->setParameter('out_trade_no',$orderid); $requestHandler->setParameter('body',$productname); $requestHandler->setParameter('total_fee',$real_amount*100); //以分为单位 $requestHandler->setParameter('mch_create_ip',request()->ip()); $requestHandler->setParameter('notify_url',Config::get('swiftccbwxpay')['notify_url']); $requestHandler->setParameter('device_info','AND_WAP'); $requestHandler->setParameter('mch_app_name','麻花网络'); //应用名 $requestHandler->setParameter('mch_app_id',Config::get('swiftccbwxpay')['mch_app_id']); //应用标识 $requestHandler->setParameter('nonce_str',mt_rand(time(),time()+rand())); //随机字符串,必填项,不长于 32 位 $requestHandler->createSign();//创建签名 $data = \Utils::toXml($requestHandler->getAllParameters()); $pay->setReqContent($requestHandler->getGateURL(),$data); //执行http调用 if($pay->call()){ $resHandler->setRSAKey(Config::get('swiftccbwxpay')['public_key']); $resHandler->setContent($pay->getResContent()); //设置应答类内容 $resHandler->setKey($requestHandler->getKey()); if($resHandler->isTenpaySign()){ //当返回状态与业务结果都为0时才返回,其它结果请查看接口文档 if($resHandler->getParameter('status') == 0 && $resHandler->getParameter('result_code') == 0){ return $resHandler->getParameter('pay_info'); }else{ throw new \Exception(' Error Code:'.$resHandler->getParameter('err_code').' Error Message:'.$resHandler->getParameter('err_msg')); } } throw new \Exception(' Error Info:'.$resHandler->getParameter('message')); }else{ throw new \Exception(' Error Info:'.$pay->getErrInfo()); } } /** * 获取现在支付参数 * * @param string $orderid 订单号 * @param float $real_amount 支付金额 * @param string $productname 商品名称 * * @return array 支付参数数组 */ private function getIpaynowParam($orderid,$real_amount,$productname) { $ipay['mhtOrderNo'] = $orderid; // 商户订单号 $ipay['appId'] = Config::get('ipaynow')['appid']; // 商户应用唯一标识 $ipay['mhtOrderAmt'] = $real_amount*100; // 支付金额,以分为单位 $ipay['notifyUrl'] = Config::get('ipaynow')['notify_url']; // 回调地址 $ipay['funcode'] = 'WP001'; $ipay['version'] = '1.0.0'; $ipay["payChannelType"] = "13"; $ipay["mhtOrderName"] = $productname; $ipay["mhtOrderType"] = "01"; $ipay["mhtCurrencyType"]= '156'; $ipay["mhtOrderStartTime"]= date('YmdHis'); $ipay['mhtCharset'] = "UTF-8"; $ipay['deviceType'] = "01"; $ipay['mhtOrderDetail'] = $productname; $ipay['mhtSignType'] ='MD5'; ksort($ipay); //按key升序排列 reset($ipay); //拼接待签名字符串 $arg = ""; while (list ($key, $val) = each ($ipay)) { $arg.=$key."=".$val."&"; } //如果存在转义字符,那么去掉转义 if(get_magic_quotes_gpc()){$arg = stripslashes($arg);} //生成签名 $mhtSignature = md5($arg.md5(Config::get('ipaynow')['key'])); return $arg.'mhtSignature='.$mhtSignature; } /** * 微信官方h5支付 * * @param string $orderid 订单号 * @param float $real_amount 支付金额 * @param string $body 商品名称 * * @return array 支付参数数组 */ private function getWxpayH5Param($orderid,$real_amount,$body) { $pay_return = false; $wxPay = new WeixinPay; $params['appid'] = Config::get('wxpay-h5')['appid']; $params['mch_id'] = Config::get('wxpay-h5')['mch_id']; $params['nonce_str'] = random(10); $params['body'] = $body; $params['out_trade_no'] = $orderid; $params['total_fee'] = $real_amount*100; // 支付金额,以分为单位 $params['spbill_create_ip'] = $this->request->ip(); $params['notify_url'] = Config::get('wxpay-h5')['notify_url']; $params['trade_type'] = 'MWEB'; $params['scene_info'] = '{"h5_info":{"type":"Wap","wap_url":"http://m.weilongwl.com","wap_name":"麻花网络游戏"}}'; //获取签名数据 $params['sign'] = $wxPay->MakeSign($params,Config::get('wxpay-h5')['key']); $xml = dataToXml($params); $response = $wxPay->postXmlCurl($xml); if (!$response) { return false; } $result = $wxPay->xmlToArray($response); if( array_key_exists("return_code", $result) && $result["return_code"] == "SUCCESS" && array_key_exists("result_code", $result) && $result["result_code"] == "SUCCESS") { $pay_return['prepay_id'] = $result['prepay_id']; $pay_return['trade_type'] = $result['trade_type']; $pay_return['mweb_url'] = $result['mweb_url']; $pay_return['referer'] = Config::get('wxpay-h5')['referer']; } else{ throw new \Exception(' 错误代码:'.$result["err_code"].' 错误代码描述:'.$result["err_code_des"]); } return $pay_return; } /** * 米花微信h5支付 * * @param string $orderid 订单号 * @param float $real_amount 支付金额 * @param string $body 商品名称 * * @return array 支付参数数组 */ private function getMihuaWxpayH5Param($orderid,$real_amount,$body) { $pay_return = false; vendor('mihuaSdk.Mihua','.class.php'); $mihua = new \Mihua(); $return_url = Config::get('wxpay-h5-mihua')['return_url']."?orderid=".$orderid; $notify_url = Config::get('wxpay-h5-mihua')['notify_url']; $response = $mihua->pay($body, $orderid, $real_amount,$return_url,$notify_url); if (!$response) { return false; } $result = json_decode($response,true); if( array_key_exists("code", $result) && $result["code"] == "000000") { $pay_return['mweb_url'] = $result['data']['payUrl']; $pay_return['referer'] = Config::get('wxpay-h5-mihua')['referer']; } else{ throw new \Exception(' 错误代码:'.$result["code"].' 错误代码描述:'.$result["msg"]); } return $pay_return; } /** * 米花支付宝h5支付 * * @param string $orderid 订单号 * @param float $real_amount 支付金额 * @param string $body 商品名称 * * @return array 支付参数数组 */ private function getMihuaAlipayH5Param($orderid,$real_amount,$body) { $pay_return = false; vendor('mihuaSdk.Mihuazfb','.class.php'); $mihua = new \Mihuazfb(); $return_url = Config::get('zfb-h5-mihua')['return_url']."?orderid=".$orderid; $notify_url = Config::get('zfb-h5-mihua')['notify_url']; $response = $mihua->alipay($body, $orderid, $real_amount,$return_url,$notify_url); if (!$response) { return false; } $result = json_decode($response,true); if( array_key_exists("code", $result) && $result["code"] == "000000") { $pay_return['mweb_url'] = $result['data']['payUrl']; $pay_return['referer'] = Config::get('zfb-h5-mihua')['referer']; } else{ throw new \Exception(' 错误代码:'.$result["code"].' 错误代码描述:'.$result["msg"]); } return $pay_return; } /** * 快接微信h5支付 * * @param string $orderid 订单号 * @param float $real_amount 支付金额 * @param string $body 商品名称 * * @return array 支付参数数组 */ private function getKjWxpayH5Param($orderid,$real_amount,$body) { $pay_return = false; vendor('kjpaySdk.Kjpay','.class.php'); $kjpay = new \Kjpay(); $return_url = Config::get('wxpay-h5-kj')['return_url']."?orderid=".$orderid; $notify_url = Config::get('wxpay-h5-kj')['notify_url']; $response = $kjpay->pay($body, $orderid, $real_amount,$return_url,$notify_url); if (!$response) { return false; } $result = $response; if( array_key_exists("status", $result) && $result["status"] == "1") { $pay_return['mweb_url'] = $result['data']['pay_url']; $pay_return['referer'] = Config::get('wxpay-h5-kj')['referer']; } else{ throw new \Exception(' 错误代码:'.$result["code"].' 错误代码描述:'.$result["msg"]); } return $pay_return; } /** * 快接支付宝h5支付 * * @param string $orderid 订单号 * @param float $real_amount 支付金额 * @param string $body 商品名称 * * @return array 支付参数数组 */ private function getKjZfbH5Param($orderid,$real_amount,$body) { $pay_return = false; vendor('kjpaySdk.Kjzfb','.class.php'); $kjpay = new \Kjzfb(); $return_url = Config::get('zfb-h5-kj')['return_url']."?orderid=".$orderid; $notify_url = Config::get('zfb-h5-kj')['notify_url']; $response = $kjpay->pay($body, $orderid, $real_amount,$return_url,$notify_url); if (!$response) { return false; } $result = $response; if( array_key_exists("status", $result) && $result["status"] == "1") { $pay_return['mweb_url'] = $result['data']['pay_url']; $pay_return['referer'] = Config::get('zfb-h5-kj')['referer']; } else{ throw new \Exception(' 错误代码:'.$result["code"].' 错误代码描述:'.$result["msg"]); } return $pay_return; } /** * 商盟微信h5支付 * * @param string $orderid 订单号 * @param float $real_amount 支付金额 * @param string $body 商品名称 * * @return array 支付参数数组 */ private function getSumpayWxpayH5Param($orderid,$real_amount,$body) { $pay_return = false; vendor('sumpaySdk.Sumpay','.class.php'); $sumpay = new \Sumpay(); $return_url = Config::get('wxpay-h5-sumpay')['return_url']."?orderid=".$orderid; $notify_url = Config::get('wxpay-h5-sumpay')['notify_url']; $response = $sumpay->pay($body, $orderid, $real_amount,$return_url,$notify_url); if (!$response) { return false; } $result = $response; // var_dump($result); if( array_key_exists("code", $result) && $result["code"] == "10000") { if(substr($result['data']['redirectUrl'],0,4)<>'http'){ // $pay_return['mweb_url'] = $result['data']['redirectUrl']; $pay_return['mweb_url'] = "https://".$result['data']['redirectUrl']; } else{ $pay_return['mweb_url'] = $result['data']['redirectUrl']; } $pay_return['referer'] = Config::get('wxpay-h5-sumpay')['referer']; } else{ throw new \Exception(' 错误代码:'.$result["code"].' 错误代码描述:'.$result["message"]); } return $pay_return; } /** * 酷点微信h5支付 * * @param string $orderid 订单号 * @param float $real_amount 支付金额 * @param string $body 商品名称 * * @return array 支付参数数组 */ private function getkdh5weixinParam($orderid,$real_amount,$body) { $pay_return = false; vendor('kdpaySdk.des'); $kdh5pay = new \kdpay(); $return_url = Config::get('kdh5')['return_url']."?orderid=".$orderid; $notify_url = Config::get('kdh5')['notify_url']; log_message('打印2:'.$return_url,'log',LOG_PATH . 'apilog/'); $response = $kdh5pay->oil_fee_jsapi_get($body, $orderid, $real_amount,$return_url,$notify_url); if (!$response) { return false; } $result = $response; $pay_return['mweb_url'] = $result; $pay_return['referer'] = Config::get('kdh5')['referer']; return $pay_return; } /** * 订单查询 */ public function queryPay(){ $orderid = $this->input('orderid'); //订单ID if(empty($orderid)){ $this->jsonResult('', 0,'订单ID不能为空'); } $pay_type = 1; // 支付类型: 1=支付, 2=充值 if(strrpos($orderid, 'COIN') === 0){ $pay_type = 2; } if($pay_type == 1){ // 支付 - $payModel = new PayModel; $payInfo = $payModel->field('status')->where(['orderid'=>$orderid])->find(); }else{ // 充值 $memberCoinPayModel = new MemberCoinPay(); //消费订单信息 $payInfo = $memberCoinPayModel->field('status')->where(['orderid' => $orderid])->find(); } if($payInfo){ $this->jsonResult($payInfo, 1,'订单查询成功'); }else{ $this->jsonResult('', 0,'订单信息不存在'); } } /** * 微信查询订单接口 */ public function weixinOrderQuery() { $orderid = $this->input('orderid'); //订单ID if(empty($orderid)){ $this->jsonResult('', 0,'订单ID不能为空'); } $wxPay = new WeixinPay; $params['appid'] = Config::get('wxpay-h5')['appid']; $params['mch_id'] = Config::get('wxpay-h5')['mch_id']; $params['out_trade_no'] = $orderid; $params['nonce_str'] = random(10); //获取签名数据 $params['sign'] = $wxPay->MakeSign($params,Config::get('wxpay-h5')['key']); $xml = dataToXml($params); $response = $wxPay->queryPostXmlCurl($xml); if (!$response) { $this->jsonResult(['status'=>'FAIL'], 1,'发起微信订单查询失败'); } $result = $wxPay->xmlToArray($response); if( array_key_exists("return_code", $result) && $result["return_code"] == "SUCCESS" && array_key_exists("result_code", $result) && $result["result_code"] == "SUCCESS") { $this->jsonResult(['status'=>$result['trade_state']], 1,' 微信订单查询成功'); } elseif(array_key_exists("return_code", $result) && $result["return_code"] == "SUCCESS"){ if(isset($result["err_code"]) && isset($result["err_code_des"])) $this->jsonResult(['status'=>'FAIL'], 1,' 微信订单查询失败,错误代码:'.$result["err_code"].' 错误代码描述:'.$result["err_code_des"]); else $this->jsonResult(['status'=>'FAIL'], 1,' 微信订单查询失败'); } elseif(array_key_exists("return_code", $result)){ $this->jsonResult(['status'=>'FAIL'], 1,' 微信订单查询失败,'.$result["return_msg"]); } else{ $this->jsonResult(['status'=>'FAIL'], 1,'微信订单查询失败'); } } /** * 威富通中信银行-微信WAP订单查询 * */ public function swiftpayWeixinwapOrderQuery(){ $orderid = $this->input('orderid'); //订单ID if(empty($orderid)){ $this->jsonResult('', 0,'订单ID不能为空'); } vendor('swiftpay.ClientResponseHandler','.class.php'); vendor('swiftpay.RequestHandler','.class.php'); vendor('swiftpay.PayHttpClient','.class.php'); vendor('swiftpay.Utils','.class.php'); $resHandler = new \ClientResponseHandler(); //后台应答类 $requestHandler = new \RequestHandler(); //请求类 $pay = new \PayHttpClient(); $requestHandler->setRSAKey(Config::get('swiftccbwxpay')['private_key']); $requestHandler->setSignType('RSA_1_256'); $requestHandler->setParameter('version','2.0'); $requestHandler->setParameter('service','unified.trade.query');//接口类型 $requestHandler->setParameter('mch_id',Config::get('swiftccbwxpay')['mch_id']); //必填项,商户号,由威富通分配 $requestHandler->setParameter('out_trade_no',$orderid); $requestHandler->setParameter('sign_type','RSA_1_256'); $requestHandler->setParameter('nonce_str',mt_rand(time(),time()+rand())); //随机字符串,必填项,不长于 32 位 $requestHandler->createSign(); //创建签名 $data = \Utils::toXml($requestHandler->getAllParameters()); $pay->setReqContent($requestHandler->getGateURL(),$data); if($pay->call()){ $resHandler->setRSAKey(Config::get('swiftccbwxpay')['public_key']); $resHandler->setContent($pay->getResContent()); $resHandler->setKey($requestHandler->getKey()); if($resHandler->isTenpaySign()){ $result = $resHandler->getAllParameters(); \Utils::dataRecodes('查询订单',$result); $status = isset($result['trade_state']) ? $result['trade_state'] : 'FAIL'; $this->jsonResult(['status'=>$status],1,'查询订单成功'); } $this->jsonResult('',0,' Error Code:'.$resHandler->getParameter('status').' Error Message:'.$resHandler->getParameter('message')); }else{ $this->jsonResult('',0,'Response Code:'.$pay->getResponseCode().' Error Info:'.$pay->getErrInfo()); } } /** * */ public function getAlipayWapParam($orderid,$real_amount,$productname,$productdesc='') { $alipay_config = Config::get('alipay_wap_config'); //商户订单号,商户网站订单系统中唯一订单号,必填 $out_trade_no = $orderid; //订单名称,必填 $subject = $productname; //付款金额,必填 $total_fee = $real_amount; //收银台页面上,商品展示的超链接,必填 $show_url = "46yx.com"; //商品描述,可空 $body = $productdesc; /************************************************************/ //构造要请求的参数数组,无需改动 $parameter = array( "service" => $alipay_config['service'], "partner" => $alipay_config['partner'], "seller_id" => $alipay_config['seller_id'], "payment_type" => $alipay_config['payment_type'], "notify_url" => $alipay_config['notify_url'], "return_url" => $alipay_config['return_url'], "_input_charset" => trim(strtolower($alipay_config['input_charset'])), "out_trade_no" => $out_trade_no, "subject" => $subject, "total_fee" => $total_fee, "show_url" => $show_url, //"app_pay" => "Y",//启用此参数能唤起钱包APP支付宝 "body" => $body, ); //建立请求 // $alipaySubmit = new \Alipay_wap\AlipaySubmit($alipay_config); // //生成支付宝支付参数字符串 // $str = $alipaySubmit->buildRequestParaToString($parameter); return $parameter; } public function alipay_wap_notify() { $alipay_config = Config::get('alipay_wap_config'); //计算得出通知验证结果 $alipayNotify = new \Alipay_wap\AlipayNotify($alipay_config); if ($result = $alipayNotify->verifyNotify()) { // 处理支付成功后的逻辑业务 if (input('post.trade_status') == 'TRADE_SUCCESS') { //写入日志 log_message($result, 'log', LOG_PATH . '../paylog/'); $out_trade_no = input('out_trade_no'); //订单号 if (!empty($out_trade_no)) { //更新订单状态处理 $this->updateOrder($out_trade_no, input('total_fee')); } echo 'success'; exit; //请不要修改或删除 } echo 'fail'; exit; //验证失败 } echo 'fail'; exit; } public function alipay_wap_return() { $alipay_config = Config::get('alipay_wap_config'); //计算得出通知验证结果 $alipayNotify = new \Alipay_wap\AlipayNotify($alipay_config); if ($result = $alipayNotify->verifyNotify()) { // 处理支付成功后的逻辑业务 if (input('post.trade_status') == 'TRADE_SUCCESS') { //写入日志 log_message($result, 'log', LOG_PATH . '../paylog/'); $out_trade_no = input('out_trade_no'); //订单号 if (!empty($out_trade_no)) { //更新订单状态处理 $this->updateOrder($out_trade_no, input('total_fee')); } echo 'success'; exit; //请不要修改或删除 } echo 'fail'; exit; //验证失败 } echo 'fail'; exit; } /** * 将xml转为array * @param string $xml * * @return array */ public function xmlToArray($xml) { if (!$xml) { return false; } $data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); return $data; } /** * 作用:以post方式提交xml到对应的接口url * * @param $xml string xml的报文内容 * @param $second int 请求的超时时间 * */ public function postXmlCurl($post_data,$url='',$second=30){ if($url==''){ $url = $this->url; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // post数据 curl_setopt($ch, CURLOPT_POST, 1); // post的变量 curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data); //执行请求 $output = curl_exec($ch); //打印获得的数据 $xml = $this->xmlToArray($output); return $xml; curl_close($ch); } public function xzzfbzfpost($url, $data) { $curl = curl_init(); // 启动一个CURL会话 curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 //curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 curl_setopt($curl, CURLOPT_TIMEOUT, 40); // 设置超时限制防止死循环 curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 $tmpInfo = curl_exec($curl); // 执行操作 log_message($tmpInfo, 'log', LOG_PATH . '../paylog/'); // if (curl_errno($curl)) { // echo 'Errno'.curl_error($curl); // echo curl_errno($curl);//捕抓异常 // } curl_close($curl); // 关闭CURL会话 return $tmpInfo; // 返回数据 } }