帮老板 客户做的 提现秒到 用到的 第三方平台 畅捷,这个平台 是老板客户自己找的。
首先看了一下文档 感觉 不难,由于写完很久了才想起写博客 详细过程记不清了 大概说一下 下面 我就直接贴代码 供你们参考吧
说一下步骤,1 首先你要生成 提现的 订单 见图片是我生成的订单
2. 提现生成订单时查一下 畅捷账户的余额 够不够用户提现的 不够 return ,够提现继续
3 生成订单的同事 调用 agent($money,$orderNo) 方法 把提现金额 跟生成的订单号 传过去 这时 提现到没到用户手中 属于未知状态,下面再写一个查询畅捷提现 是否成功的接口
4 查询 提现是否成功接口 searchPay($orderNo)把订单传过去
5 利用linux 定时 chanPay() 每5分钟 查一次 上面 4步骤 的接口 如果成功返回状态 如果失败了 要把钱退回到用户账户的账户里
具体 看下面代码吧 耐心看 都能写通。
public function tx() //提现生成订单 同时调用 畅捷接口{$money = input('money', '');$type = input('type', 'total_money'); // total_money 为除分润余额 //share_money 为分润余额$user = app()->user;$chan_data = $this->balance(); //这调用畅捷接口 查一下 畅捷 账户里的余额 够不够提现if ($chan_data['PayBalance'] < $money){return Y::json(1,'畅捷平台余额不足');}$real = Db::table('user')->where('id', $user['id'])->value('real');if ($real == 0) {return Y::json(1, '实名认证后才能提现');}if ($real == 2) {return Y::json(3, '您已上传认证信息,请耐心等待');}$n = Db::table('mach')->where('user_id', $user['id'])->count();if ($n <= 0) {return Y::json(1, '必须购买过机具才能提现');}$status = Db::table('repay')->where('user_id', $user['id'])->order('id', 'desc')->value('status');if (isset($status)) {if ($status == 0) {return Y::json(1, '未还款不能提现');}}$bank_address = Db::table('user')->where('id', $user['id'])->value('bank_address');if (empty($bank_address)) {return Y::json(1, '绑定开户行地址后方可提现');}$info = Cache::store('redis')->get($user['id'] . 'tx');if (!empty($info)) {return Y::json(1, '每天只能提现一次');}$data = Db::table('tx_set')->find();if ($type == 'total_money') {if ($money < $data['min_tx']) { // 除分润提现限制return Y::json(1, "提现金额至少" . $data['min_tx']);}} else {if ($money < $data['share_tx']) { //分润提现限制return Y::json(1, "提现金额至少" . $data['share_tx']);}}if ($type == 'total_money') {$ye = Db::table('purse')->where('user_id', $user['id'])->order('id', 'desc')->value('total_money');//申请提现金额 大于余额 returnif ($money > $ye) {return Y::json(1, "可提余额不足");}} else {$ye = Db::table('purse')->where('user_id', $user['id'])->order('id', 'desc')->value('share_money');//申请提现金额 大于余额 returnif ($money > $ye) {return Y::json(1, "可提余额不足");}}//提现时间限制$t1 = strtotime(date('Y-m-d H:i:s'));$t2 = strtotime(date("Y-m-d 00:00:00", strtotime("+1 day")));$time = $t2 - $t1;Cache::store('redis')->set($user['id'] . 'tx', 'tx', $time);// 税款if ($type == 'total_money') {$tax_money = $money * $data['lv'];} else {$tax_money = $money * $data['share_lv'];}//申请提现金额 -税款 = 应提金额$tx_money = bcsub($money, $tax_money, 2);//提现金额小于500扣2块手续费if ($money < 500) {$charge = 2;$tx_money = bcsub($tx_money, $charge, 2);} else {$charge = 0;}//申请提现后 剩余的 余额$total_ye = bcsub($ye, $money, 2);$orderNo = time() + mt_rand(2,50);if ($type == 'total_money'){Db::table('tx')->where('user_id', $user['id'])->insert(['user_id'=>$user['id'],'money' => $money,'charge' =>$charge,'tx_money' =>$tx_money,'create_time' =>date('Y-m-d H:i:s'),'operator'=>'畅捷支付','orderNo'=> $orderNo,'type' =>1,]);$share_money =Db::table('purse')->where('user_id', $user['id'])->order('id', 'desc')->value('share_money');Db::table('purse')->insert(['user_id' => $user['id'],'total_money' => $total_ye,'share_money' => $share_money,'tx' => $money,'trade_time' => date('Y-m-d H:i:s'),'create_time' => date('Y-m-d H:i:s')]);}else{Db::table('tx')->where('user_id', $user['id'])->insert(['user_id'=>$user['id'],'share_money' => $money,'charge' =>$charge,'tx_money' =>$tx_money,'create_time' =>date('Y-m-d H:i:s'),'operator'=>'畅捷支付','orderNo'=> $orderNo,'type' =>2,]);$total_money =Db::table('purse')->where('user_id', $user['id'])->order('id', 'desc')->value('total_money');Db::table('purse')->insert(['user_id' => $user['id'],'total_money' => $total_money,'share_money' => $total_ye,'share_tx' => $money,'trade_time' => date('Y-m-d H:i:s'),'create_time' => date('Y-m-d H:i:s')]);}$result = $this->agent($tx_money, $orderNo);if (!isset($result['OriginalRetCode'] ) ){return Y::json(1,'系统错误',$result);}elseif($result['OriginalRetCode'] == '000001'){return Y::json(0,'提现成功,处理中',$result);}}//畅捷提现public function agent($money,$orderNo){$user = app()->user;$rsa = new \rsasc();$comm = new \comm();$postData = $needEncryptData = array();$needEncryptData['AcctNo'] = $user['bank_card']; //对手人账号$needEncryptData['AcctName'] = $user['nickname'];//对手人姓名
// $needEncryptData['AcctNo'] = '622203***0868223'; //对手人账号
// $needEncryptData['AcctName'] = '付振卓';//对手人姓名$needEncryptData = $rsa->publicRsaSign($needEncryptData);$postData['Service'] = 'cjt_dsf';$postData['Version'] = '1.0';$postData['PartnerId'] = '200*****410';//商户号$postData['TradeDate'] = date('Ymd') . '';$postData['TradeTime'] = date('His') . '';$postData['InputCharset'] = 'UTF-8';$postData['TransCode'] = "T10000"; //功能码$postData['OutTradeNo'] = $orderNo; //外部流水号
// $postData['OutTradeNo'] = time(); //外部流水号$postData['BusinessType'] = '0';//业务类型 0私人 1公司$postData['BankCommonName'] = $user['bank_name'];// 通用银行名称
// $postData['BankCommonName'] = '中国工商银行';// 通用银行名称//$postData['BankCode'] = 'CCB';//对公必填$postData['AccountType'] = '00';//账户类型 00借记卡 01贷记卡$postData['Currency'] = 'CNY';$postData['TransAmt'] = $money;//交易金额$postData['CorpPushUrl'] = 'http://39.98.165.44';//商户推送的URL地址$postData['PostScript'] = '提现';//交易金额$postData = array_merge($postData, $needEncryptData);$postData['Sign'] = $rsa->rsaSign($postData);$postData['SignType'] = 'RSA'; //签名类型$query = http_build_query($postData);$url = 'https://pay.chanpay.com/mag-unify/gateway/receiveOrder.do?' . $query;$cfg = array('ssl' => true);
// echo '<meta charset="utf-8">';$response = $comm->curlOpen($url, $cfg);$data = json_decode($response);$data = ArrayHelp::object2array($data);return $data;}//畅捷查询订单状态public function searchPay($orderNo){$rsa = new \rsasc();$comm = new \comm();$postData = $needEncryptData = array();$needEncryptData = $rsa->publicRsaSign($needEncryptData);$postData['Service'] = 'cjt_dsf';$postData['Version'] = '1.0';$postData['PartnerId'] = '20000***0410';$postData['TradeDate'] = date('Ymd') . '';$postData['TradeTime'] = date('His') . '';$postData['InputCharset'] = 'UTF-8';$postData['TransCode'] = "C00000"; //功能码$postData['OutTradeNo'] = time() + mt_rand(2,50); //外部流水号$postData['OriOutTradeNo'] = $orderNo; //原交易单号$postData = array_merge($postData, $needEncryptData);$postData['Sign'] = $rsa->rsaSign($postData);$postData['SignType'] = 'RSA'; //签名类型
// print_R($postData);$query = http_build_query($postData);$url = 'https://pay.chanpay.com/mag-unify/gateway/receiveOrder.do?' . $query;$cfg = array('ssl' => true);$response = $comm->curlOpen($url, $cfg);$data = json_decode($response);$data = ArrayHelp::object2array($data);return $data;}//畅捷余额查询public function balance(){$rsa = new \rsasc();$comm = new \comm();$postData = $needEncryptData = array();
// $needEncryptData['AcctNo'] = 'xxx'; //用户id
// $needEncryptData['AcctName'] = 'xxx';$needEncryptData = $rsa->publicRsaSign($needEncryptData);$postData['Service'] = 'cjt_dsf';$postData['Version'] = '1.0';$postData['PartnerId'] = '200***0410';$postData['TradeDate'] = date('Ymd') . '';$postData['TradeTime'] = date('His') . '';$postData['InputCharset'] = 'UTF-8';$postData['TransCode'] = "C00005"; //功能码$postData['OutTradeNo'] = time() + mt_rand(2,50); //外部流水号$postData = array_merge($postData, $needEncryptData);$postData['Sign'] = $rsa->rsaSign($postData);$postData['SignType'] = 'RSA'; //签名类型$query = http_build_query($postData);$url = 'https://pay.chanpay.com/mag-unify/gateway/receiveOrder.do?' . $query;$cfg = array('ssl' => true);
// echo '<meta charset="utf-8">';$response = $comm->curlOpen($url, $cfg);$data = json_decode($response);$data = ArrayHelp::object2array($data);// return Y::json(1,'余额查询成功',$data) ;return $data ;}//每5分钟linux定时查询10分钟以前提现订单是否成功public function chanPay(){$timer=strtotime('now');$timer=$timer - 15 * 60;$time = date('Y-m-d G:i:s',$timer);//查询10分钟以前 提现订单是否成功$data = Db::table('tx')->where('status',0) ->whereTime('create_time', 'today')->whereTime('create_time','<',$time)->select();foreach ($data as $val){//调用查询接口$order_data = $this->searchPay($val['orderNo']);// 如果是6个0 则 是成功状态if (isset($order_data['OriginalRetCode']) =='000000'){$result = Db::table('tx')->where('orderNo',$val['orderNo'])->update(['audit_time'=>date('Y-m-d H:i:s'),'status'=>1]);}else{//如果失败 钱包里的钱 退回Db::table('tx')->where('orderNo',$val['orderNo'])->update(['audit_time'=>date('Y-m-d H:i:s'),'status'=>2]);$tx_data = Db::table('tx')->where('orderNo',$val['orderNo'])->find();if ($tx_data['type'] == 1){ //除分润提现$purse = Db::table('purse')->where('user_id',$tx_data['user_id'])->order('id','desc')->find();$total_money = bcadd($purse['total_money'],$tx_data['money'],2);$result = Db::table('purse')->where('user_id',$tx_data['user_id'])->insert(['user_id'=>$tx_data['user_id'],'back' => $tx_data['money'],'total_money'=>$total_money,'share_money' =>$purse['share_money'],'trade_time' =>date('Y-m-d H:i:s'),'create_time' =>date('Y-m-d H:i:s'),]);}else{ //分润提现$purse = Db::table('purse')->where('user_id',$tx_data['user_id'])->order('id','desc')->find();$share_money = bcadd($purse['share_money'],$tx_data['share_money'],2);$result = Db::table('purse')->where('user_id',$tx_data['user_id'])->insert(['user_id'=>$tx_data['user_id'],'back' => $tx_data['share_money'],'total_money'=>$purse['total_money'],'share_money' =>$share_money,'trade_time' =>date('Y-m-d H:i:s'),'create_time' =>date('Y-m-d H:i:s'),]);}}}}