get_discount($param['game_id'], $user['promote_id'], $param['user_id']); $discount = $discount['discount']; // if(!is_check_apply_promote($param['game_id'],$user['promote_id'])){ // $user['promote_id']=0; // $user['promote_account']="自然注册"; // } $vo = new \Think\Pay\PayVo(); $vo->setBody("充值记录描述") ->setFee($param['price'])//支付金额 ->setTitle($param['title']) ->setBody($param['body']) ->setOrderNo($out_trade_no) ->setRatio(get_game_selle_ratio($param["game_id"])) ->setService($param['server']) ->setSignType($param['signtype']) ->setPayMethod('mobile') ->setTable($table) ->setPayWay($param['payway']) ->setGameId($param['game_id']) ->setGameName(get_game_name($param['game_id'])) ->setGameAppid($param['game_appid']) ->setServerId(0) ->setGameplayerName($param['game_player_name']) ->setServerName($param['server_name']) ->setUserId($param['user_id']) ->setAccount($user['account']) ->setUserNickName($user['nickname']) ->setPromoteId($user['promote_id']) ->setPromoteName($user['promote_account']) ->setExtend($param['extend']) ->setSdkVersion($param['sdk_version']) ->setSmallId($param['small_user_id']) ->setSmallAccount(get_user_account_by_id($param['small_user_id'])) ->setDiscount($discount); return $pay->buildRequestForm($vo); } /** *支付宝移动支付 */ public function alipay_pay() { #获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组 $request = json_decode(base64_decode(file_get_contents("php://input")), true); file_put_contents(dirname(__FILE__) . '/alipay_payapp.txt',json_encode($request)); C(api('Config/lists')); if ($request['price']*1 < 0) { $this->set_message(1011, "fail", "充值金额有误"); } $game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find(); if($game['pay_status'] == 0){ $this->set_message(0,"fail","该游戏暂时无法充值,请联系客服!"); } /* $request['price'] = 0.01; */ $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find(); if($extend_data){ $this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付"); } if (empty(C("alipay.partner")) || empty(C("alipay.email")) || empty(C("alipay.key")) || empty(C("alipay.appid"))) { $this->set_message(1079, "faill", "未设置支付参数"); } $game_set_data = get_game_set_info($request['game_id']); $request['apitype'] = "alipay"; $request['config'] = "alipay"; $request['signtype'] = "MD5"; $request['server'] = "mobile.securitypay.pay"; $request['payway'] = 1; $data = $this->pay($request); $md5_sign = $this->encrypt_md5(base64_encode($data['arg']), $game_set_data["access_key"]); $data = array('status' => 200, "orderInfo" => base64_encode($data['arg']), "out_trade_no" => $data['out_trade_no'], "order_sign" => $data['sign'], "md5_sign" => $md5_sign); echo base64_encode(json_encode($data)); } /** *微信 */ public function outher_pay() { #获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组 $request = json_decode(base64_decode(file_get_contents("php://input")), true); C(api('Config/lists')); if ($request['price']*1 < 0) { $this->set_message(1011, "fail", "充值金额有误"); } $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find(); if($extend_data){ $this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付"); } $game_set_data = get_game_set_info($request['game_id']); if (get_wx_type() == 0) {//官方 $table = $request['code'] == 1 ? "spend" : "deposit"; $prefix = $request['code'] == 1 ? "SP_" : "PF_"; $request['pay_order_number'] = $prefix . date('Ymd') . date('His') . sp_random_string(4); $request['pay_way'] = 3; $request['pay_status'] = 0; $request['spend_ip'] = get_client_ip(); $weixn = new Weixin(); //折扣 $user = get_user_entity($request['user_id']); $discount = $this->get_discount($request['game_id'], $user['promote_id'], $request['user_id']); $discount = $discount['discount']; if($prefix=='PF_'){ $pay_amount = $request['price']; }else{ $pay_amount = $discount * $request['price'] / 10; } $is_pay = json_decode($weixn->weixin_pay($request['title'], $request['pay_order_number'], $pay_amount, 'APP', 2,$request['game_id']), true); if ($is_pay['status'] === 1) { if (!$request['is_uc'] || C('UC_SET') == 0 || find_uc_account($user['account'])) { if ($request['code'] == 1) { $this->add_spend($request); } else { $this->add_deposit($request); } } $json_data['appid'] = $is_pay['appid']; $json_data['partnerid'] = $is_pay['mch_id']; $json_data['prepayid'] = $is_pay['prepay_id']; $json_data['noncestr'] = $is_pay['noncestr']; $json_data['timestamp'] = $is_pay['time']; $json_data['package'] = "Sign=WXPay"; $json_data['sign'] = $is_pay['sign']; $json_data['game_pay_appid'] = $game_set_data['game_pay_appid']; $json_data['status'] = 200; $json_data['return_msg'] = "下单成功"; $json_data['wxtype'] = "wx"; echo base64_encode(json_encode($json_data)); } } else { if (empty(C("weixin_gf.partner")) || empty(C("weixin_gf.key"))) { $this->set_message(1079, "faill", "未设置威富通账号"); } $request['apitype'] = "swiftpass"; $request['config'] = array("partner" => trim(C("weixin_gf.partner")), "email" => "", "key" => trim(C("weixin_gf.key"))); $request['signtype'] = "MD5"; $request['server'] = "unified.trade.pay"; $request['payway'] = 4; $result_data = $this->pay($request); $data['status'] = 200; $data['return_code'] = "success"; $data['return_msg'] = "下单成功"; $data['token_id'] = $result_data['token_id']; $data['out_trade_no'] = $result_data['out_trade_no']; $data['game_pay_appid'] = $game_set_data['game_pay_appid']==""?C("weixin_gf.partner"):$game_set_data['game_pay_appid']; $data['wxtype'] = "wft"; echo base64_encode(json_encode($data)); } } //聚宝云支付 public function jubaobar_pay() { #获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组 $request = json_decode(base64_decode(file_get_contents("php://input")), true); C(api('Config/lists')); if ($request['price']*1 < 0) { $this->set_message(1011, "fail", "充值金额有误"); } $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find(); if($extend_data){ $this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付"); } $prefix = $request['code'] == 1 ? "SP_" : "PF_"; $out_trade_no = $prefix . date('Ymd') . date('His') . sp_random_string(4); $request['pay_order_number'] = $out_trade_no; $request['pay_status'] = 0; $request['pay_way'] = 5; $request['spend_ip'] = get_client_ip(); $user = get_user_entity($request['user_id']); if (!$request['is_uc'] || C('UC_SET') == 0 || find_uc_account($user['account'])) { if ($request['code'] == 1) { #TODO添加消费记录 $this->add_spend($request); } else { #TODO添加平台币充值记录 $this->add_deposit($request); } } $data['status'] = 200; $data['return_code'] = "success"; $data['return_msg'] = "下单成功"; $data['out_trade_no'] = $out_trade_no; $data['appid'] = $request['sdk_version'] == 2 ? C("jubaobar.iosemail") : C("jubaobar.email");//1安卓 2苹果 echo base64_encode(json_encode($data)); } //竣付通支付 public function jft_pay() { #获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组 $request = json_decode(base64_decode(file_get_contents("php://input")), true); C(api('Config/lists')); if ($request['price']*1 < 0) { $this->set_message(1011, "fail", "充值金额有误"); } $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find(); if($extend_data){ $this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付"); } $prefix = $request['code'] == 1 ? "SP_" : "PF_"; $out_trade_no = $prefix . date('Ymd') . date('His') . sp_random_string(4); $request['pay_order_number'] = $out_trade_no; $request['pay_status'] = 0; $request['pay_way'] = 6; $request['spend_ip'] = get_client_ip(); $user = get_user_entity($request['user_id']); if (!$request['is_uc'] || C('UC_SET') == 0 || find_uc_account($user['account'])) { if ($request['code'] == 1) { #TODO添加消费记录 $this->add_spend($request); } else { #TODO添加平台币充值记录 $this->add_deposit($request); } } $discount = $this->get_discount($request['game_id'], $user['promote_id'], $request['user_id']); $discount = $discount['discount']; $pay_amount = $discount * $request['price'] / 10; $data['status'] = 200; $data['return_code'] = "success"; $data['return_msg'] = "下单成功"; $data['ordertime'] = date("Ymdhms", time()); $data['out_trade_no'] = $out_trade_no; $data['partner'] = C('jft.partner'); $data['appid'] = C('jft.appid'); $data['com_key'] = C('jft.key'); $data['key'] = C('jft.appkey'); $data['vector'] = C('jft.vector'); $data['returnurl'] = "http://www.vlcms.com"; $data['notifyurl'] = "http://" . $_SERVER['HTTP_HOST'] . "/callback.php/Notify/jft_callback"; $data['ordertime'] = date("Ymdhms", time()); echo base64_encode(json_encode($data)); } //汇付宝支付 public function heepay_pay() { #获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组 $request = json_decode(base64_decode(file_get_contents("php://input")), true); C(api('Config/lists')); if (C('UC_SET') == 1) { if (!is_array(find_uc_account($request['account']))) { $this->set_message(1080, "fail", "Uc用户暂不支持"); } } if ($request['price']*1 < 0) { $this->set_message(1011, "fail", "充值金额有误"); } $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find(); if($extend_data){ $this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付"); } $prefix = $request['code'] == 1 ? "SP_" : "PF_"; $out_trade_no = $prefix . date('Ymd') . date('His') . sp_random_string(4); $request['pay_order_number'] = $out_trade_no; $request['pay_status'] = 0; $request['pay_way'] = 6; $request['spend_ip'] = get_client_ip(); if ($request['code'] == 1) { #TODO添加消费记录 $this->add_spend($request); } else { #TODO添加平台币充值记录 $this->add_deposit($request); } $pay['agent_id'] = "1664502";//商户号 $pay['order_no'] = $out_trade_no; $pay['time'] = date('YmdHis', time()); $pay['pay_type'] = $request['pay_type']; $pay['amount'] = $request['price']; $pay['user_ip'] = get_client_ip(); $pay['sign_key'] = "87FB9444028A4B14937A1905";//密钥 $pay['payerName'] = "元宝"; $pay['number'] = 1; $pay['goods_note'] = "支付"; $heepay = new Heepay(); $token_id = $heepay->heepay_pay($pay); $data['agent_id'] = "1664502";//商户号 $data['status'] = 200; $data['return_code'] = "success"; $data['return_msg'] = "下单成功"; $data['token_id'] = $token_id; $data['out_trade_no'] = $out_trade_no; echo base64_encode(json_encode($data)); } /* * 平台币抵扣 * 优先抵扣绑币 平台币 调这个接口说明 不走第三方支付通道 */ public function platform_coin_deduction() { #获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组 $request = json_decode(base64_decode(file_get_contents("php://input")), true); #记录信息 if ($request['price'] *1<=0) { $this->set_message(1011, "fail", "充值金额有误"); } $request['price'] = abs($request['price']); $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find(); if($extend_data){ $this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付"); } $user_info = get_user_entity($request['user_id']); if($user_info['lock_status'] == 0 || $user_info['check_status'] == 0){ $this->set_message(0,"fail","账号被禁用,无法充值,请联..系客服!"); } $game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find(); if($game['pay_status'] == 0){ $this->set_message(0,"fail","该游戏暂时无法充值,请联系客服!"); } $out_trade_no = "PF_" . date('Ymd') . date('His') . sp_random_string(4); $request['order_number'] = $out_trade_no; $request['pay_order_number'] = $out_trade_no; $request['out_trade_no'] = $out_trade_no; $request['title'] = $request['title']; $request['pay_status'] = 1; $request['pay_way'] = 0; $request['spend_ip'] = get_client_ip(); $user_entity = get_user_entity($request['user_id']); $discount_arr = $this->get_discount($request['game_id'], $user_entity['promote_id'], $request['user_id']); $discount = $discount_arr['discount']; $user = M("user", "tab_"); //添加黑名单 $check_deposit_money = $this->check_deposit_money($user_entity); $check_bind_money = $this->check_bind_money($user_entity); if($check_deposit_money === false || $check_bind_money === false || (C('BRUSH_MONEY') && (abs($check_deposit_money)>=C('BRUSH_MONEY') || abs($check_bind_money)>=C('BRUSH_MONEY'))) || (!C('BRUSH_MONEY') && (abs($check_deposit_money) != 0 || abs($check_bind_money) != 0))){ if(C('BRUSH_SMS_STATUS') && C('BRUSH_PHONE')&& C('BRUSH_SMS_ID')){ $result = $this-> send_block(C('BRUSH_PHONE'),$user_entity['account']); } $block_data['check_status'] = 0; $block_data['block_time'] = time(); $user->where(['id'=>$user_entity['id']])->save($block_data); echo base64_encode(json_encode(array("status" => 1076,"return_code" => "fail", "return_msg" => C('BRUSH_MONEY')."您的账号暂时无法充值,请联系客服处理.".$check_deposit_money))); exit(); } $result = false; // 先扣绑币 $request['pay_way'] = -1; $user_play = M("UserPlay", "tab_"); $user_play_map['user_id'] = $request['user_id']; $user_play_map['game_id'] = $request['game_id']; $user_play_data = $user_play->where($user_play_map)->find(); if ($user_play_data['bind_balance'] < $request['price']) { $price = $request['price']; if ($user_play_data['bind_balance'] > 0) { $user_play->where($user_play_map)->save(array('bind_balance' => 0)); // 扣绑定币 $request['price'] = $user_play_data['bind_balance']; $result = $this->add_spend($request); $this->set_ratio($request['pay_order_number'], 2); // 游戏返利 } $request['pay_way'] = 0; // 扣平台币 $real_price = $price - $user_play_data['bind_balance']; $user->where(array('id' => $request["user_id"]))->setDec("balance", $real_price); //$this->set_message(0,"fail", $request['pay_order_number']); $request['pay_order_number'] = $request['pay_order_number']."_1"; $request['price'] = $real_price; $result = $this->add_spend($request); $this->set_ratio($request['pay_order_number'], 1); // 游戏返利 } else { // 绑定币足够扣 $user_play->where($user_play_map)->setDec('bind_balance', $request['price']); // 扣绑定币 $result = $this->add_spend($request); $this->set_ratio($request['pay_order_number'], 2); // 游戏返利 } $game = new GameApi(); $game->game_pay_notify($request, $request['code']); if ($result) { echo base64_encode(json_encode(array("status" => 200, "return_code" => "success", "return_msg" => "支付成功", "out_trade_no" => $out_trade_no))); } else { echo base64_encode(json_encode(array("status" => 1078, "return_code" => "fail", "return_msg" => "支付失败"))); } } /** *平台币支付 */ public function platform_coin_pay() { #获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组 $request = json_decode(base64_decode(file_get_contents("php://input")), true); #记录信息 if ($request['price'] *1<=0) { $this->set_message(1011, "fail", "充值金额有误"); } $request['price'] = abs($request['price']); $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find(); if($extend_data){ $this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付"); } $user_info = get_user_entity($request['user_id']); if($user_info['lock_status'] == 0 || $user_info['check_status'] == 0){ $this->set_message(0,"fail","账号被禁用,无法充值,请联系客服...!"); } $game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find(); if($game['pay_status'] == 0){ $this->set_message(0,"fail","该游戏暂时无法充值,请联系客服!"); } $out_trade_no = "PF_" . date('Ymd') . date('His') . sp_random_string(4); $request['order_number'] = $out_trade_no; $request['pay_order_number'] = $out_trade_no; $request['out_trade_no'] = $out_trade_no; $request['title'] = $request['title']; $request['pay_status'] = 1; $request['pay_way'] = 0; $request['spend_ip'] = get_client_ip(); $user_entity = get_user_entity($request['user_id']); $discount_arr = $this->get_discount($request['game_id'], $user_entity['promote_id'], $request['user_id']); $discount = $discount_arr['discount']; $user = M("user", "tab_"); //添加黑名单 $check_deposit_money = $this->check_deposit_money($user_entity); $check_bind_money = $this->check_bind_money($user_entity); if($check_deposit_money === false || $check_bind_money === false || (C('BRUSH_MONEY') && (abs($check_deposit_money)>=C('BRUSH_MONEY') || abs($check_bind_money)>=C('BRUSH_MONEY'))) || (!C('BRUSH_MONEY') && (abs($check_deposit_money) != 0 || abs($check_bind_money) != 0))){ if(C('BRUSH_SMS_STATUS') && C('BRUSH_PHONE')&& C('BRUSH_SMS_ID')){ $result = $this-> send_block(C('BRUSH_PHONE'),$user_entity['account']); } $block_data['check_status'] = 0; $block_data['block_time'] = time(); $user->where(['id'=>$user_entity['id']])->save($block_data); echo base64_encode(json_encode(array("status" => 1076,"return_code" => "fail", "return_msg" => "您的账号暂时无法充值,请联系客服处理"))); exit(); } $result = false; switch ($request['code']) { case 1:#非绑定平台币 $real_price = $request['price'] * $discount / 10; if ($user_entity['balance'] < $real_price) { $data = array('discount'=>$discount,"real_price"=>$real_price,'balance'=>$user_entity['balance']); echo base64_encode(json_encode(array("status" => 1076,"return_code" => "fail", "return_msg" => "余额不足"))); exit(); } //防刷预警 if(C('BRUSH_PTB') && $user_entity['balance'] >= C('BRUSH_PTB') && C('BRUSH_EMAIL') && C('BRUSH_EMAIL_STATUS')){ $content = "尊敬的用户:
    系统检测到玩家【".$user_entity['account']."】账户平台币".$user_entity['balance'].",超出上限".C('BRUSH_PTB').",可能存在异常,请尽快处理。"; sendBrushMail(C('BRUSH_EMAIL'),$content); } if(C('BRUSH_PTB_TIME') && C('BRUSH_PTB_COUNT') && C('BRUSH_EMAIL') && C('BRUSH_EMAIL_STATUS')){ $where['pay_time'] = ['between',[time()-C('BRUSH_PTB_TIME')*60,time()]]; $where['user_id'] = $user_entity['id']; $where['pay_status'] = 1; $where['pay_way'] = 0; $spend_count = M('spend','tab_')->where($where)->count('id'); $spend_count += 1; if($spend_count > C('BRUSH_PTB_COUNT')){ $content = "尊敬的用户:
    系统检测到玩家【".$user_entity['account']."】在".date('Y-m-d H:i:s',time()-C('BRUSH_PTB_TIME')*60)."-".date('Y-m-d H:i:s')."期间累计平台币消费".$spend_count."次,可能存在异常,请尽快处理。"; sendBrushMail(C('BRUSH_EMAIL'),$content); } } #扣除平台币 $user->where("id=" . $request["user_id"])->setDec("balance", $real_price); #TODO 添加绑定平台币消费记录 $result = $this->add_spend($request); #检查返利设置 $this->set_ratio($request['pay_order_number']); break; case 2:#绑定平台币 $request['pay_way'] = -1; $user_play = M("UserPlay", "tab_"); $user_play_map['user_id'] = $request['user_id']; $user_play_map['game_id'] = $request['game_id']; $user_play_data = $user_play->where($user_play_map)->find(); if ($user_play_data['bind_balance'] < $request['price']) { echo base64_encode(json_encode(array("status" =>1076, "return_code" => "fail", "return_msg" => "余额不足"))); exit(); } #扣除平台币 $user_play->where($user_play_map)->setDec("bind_balance", $request['price']); #TODO 添加绑定平台币消费记录 $result = $this->add_spend($request); #检查返利设置 $this->set_ratio($request['pay_order_number'],2); break; default: echo base64_encode(json_encode(array("status" => 1081, "return_code" => "fail", "return_msg" => "支付方式不明确"))); exit(); break; } $game = new GameApi(); $game->game_pay_notify($request, $request['code']); if ($result) { echo base64_encode(json_encode(array("status" => 200, "return_code" => "success", "return_msg" => "支付成功", "out_trade_no" => $out_trade_no))); } else { echo base64_encode(json_encode(array("status" => 1078, "return_code" => "fail", "return_msg" => "支付失败"))); } } /** *支付验证 */ public function pay_validation() { #获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组 $request = json_decode(base64_decode(file_get_contents("php://input")), true); $out_trade_no = $request['out_trade_no']; $pay_where = substr($out_trade_no, 0, 2); $result = 0; $map['pay_order_number'] = $out_trade_no; switch ($pay_where) { case 'SP': $data = M('spend', 'tab_')->field('pay_status')->where($map)->find(); $result = $data['pay_status']; break; case 'PF': $data = M('deposit', 'tab_')->field('pay_status')->where($map)->find(); $result = $data['pay_status']; break; case 'AG': $data = M('agent', 'tab_')->field('pay_status')->where($map)->find(); $result = $data['pay_status']; break; default: exit('accident order data'); break; } if ($result) { echo base64_encode(json_encode(array("status" => 200, "return_code" => "success", "return_msg" => "支付成功"))); exit(); } else { echo base64_encode(json_encode(array("status" => 1078, "return_code" => "fail", "return_msg" => "支付失败"))); exit(); } } /** *sdk客户端显示支付 */ public function payShow() { $map['type'] = 1; $map['status'] = 1; $data = M("tool", "tab_")->where($map)->select(); if (empty($data)) { echo base64_encode(json_encode(array("status" => 1082, "return_code" => "fail", "return_msg" => "暂无数据"))); exit(); } foreach ($data as $key => $value) { $pay_show_data[$key]['mark'] = $value['name']; $pay_show_data[$key]['title'] = $value['title']; } echo base64_encode(json_encode(array("status" => 200, "return_code" => "fail", "return_msg" => "成功", "pay_show_data" => $pay_show_data))); exit(); } }