dealData($result); echo $return; } } /** * 微信支付--商品支付成功回调订单 */ public function WxOrderNotify(){ $payXml = file_get_contents("php://input"); //将xml格式转化为json格式 $jsonXml = json_encode(simplexml_load_string($payXml, 'SimpleXMLElement', LIBXML_NOCDATA)); //将json格式转成数组格式 $result['out_trade_no'] $result = json_decode($jsonXml, true); file_put_contents("wx_pay_return.txt", json_encode($result) . "\n" . "\n", FILE_APPEND); if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { $return = $this->dealData($result); if ($return){ $arr = array( 'return_code' => 'SUCCESS', 'return_msg' => 'OK', ); return $this->arrayToXml($arr); }else{ file_put_contents("order_pay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); } } } // /** // * 支付宝支付--支付成功回调订单 // */ // public function alipayOrderNotify(){ // $result = input('post.'); // file_put_contents("zfb_pay_return.txt", json_encode($result) . "\n" . "\n", FILE_APPEND); // if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') { // $return = $this->dealData($result); // if ($return){ // echo 'success'; // }else{ // file_put_contents("order_alipay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); // } // } // } /** * 支付宝支付--支付成功回调订单 */ public function alipayOrderNotify(){ $results = input('post.'); $zfb = new AliPay3(); $result= json_decode($zfb->sslDeReturn($results['notifyData']),true); file_put_contents("zfb_pay_return.txt", json_encode($result,true) . "\n" . "\n", FILE_APPEND); if ($result['status'] == 'success') { $result['out_trade_no'] = $result['out_trade_id']; $return = $this->dealData($result); if ($return){ echo 'success'; }else{ file_put_contents("order_alipay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 汇聚支付支付宝h5,银联h5 */ public function ylOrderNotify(){ $result = input(); debug($result); if ($result['r6_Status'] == '100'){ $result['out_trade_no'] = $result['r2_OrderNo']; $result['attach'] = $result['r5_Mp']; $return = $this->dealData($result); if ($return){ echo 'success'; }else{ file_put_contents("order_alipay_error.txt", json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 处理数据库信息 * @param $result * @return bool */ function dealData($result){ Db::startTrans(); $redis = new Redis(); $key = 'order_not_pay_'.$result['attach']; $com = true; try { $order = $redis->hGet($key,$result['out_trade_no']); if (!$order) return false; $order = json_decode($order,true); $is_order = Db::name('store_order')->where('order_no',$result['out_trade_no'])->find(); if (isset($is_order) && $is_order['status']==1) return false; $order['status'] = 1; $order['pay_at'] = date('Y-m-d H:i:s'); $order['return_success_info'] = json_encode($result,true); $order_id = Db::name('store_order')->insertGetId($order); $array = []; $pro_info = json_decode($order['pro_info'],true); $is_nft = Db::name('hash2')->where('goods_id',$order['c_id'])->where('success',1)->find(); for ($i=0;$i<$order['num'];$i++){ //获取排名 $rank = getRanking($order['c_id'])+1; $tag = getTag($order['c_id'],$rank,$order['inventory']); saveRanking($order['c_id']); $collectors_hash = ''; $date = [ 'order_id'=>$order_id, 'order_no'=>get_order_sn(), 'tag'=>$tag, 'mid'=>$order['mid'], 'c_id'=>$order['c_id'], 'name'=>$pro_info['name'], 'cover'=>$pro_info['cover'], 'pro_info'=>$order['pro_info'], 'type'=>$pro_info['type'], 'tokenid'=>$is_nft['class_id'], 'nfttype'=>$is_nft['operationId'], 'collectors_hash'=>$collectors_hash ]; $array[] = $date; } Db::name('store_order_info')->insertAll($array); //送积分 // $by_collection_integral = getConfigValue('by_collection_integral'); // if ($by_collection_integral){ // $by_collection_integral = bcmul($by_collection_integral,$order['num']); // memberMoneyChange($by_collection_integral,1,$order['mid'],'购买藏品',1,$order['id']); // } Db::commit(); } catch (\Exception $e){ $com = false; Db::rollback(); } if ($com){ $redis->hdel($key,$result['out_trade_no']); return true; }else{ return false; } } /** * 微信支付--充值盲盒成功回调订单 */ public function BlindRechargeNotify(){ $payXml = file_get_contents("php://input"); //将xml格式转化为json格式 $jsonXml = json_encode(simplexml_load_string($payXml, 'SimpleXMLElement', LIBXML_NOCDATA)); //将json格式转成数组格式 $result['out_trade_no'] $result = json_decode($jsonXml, true); if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { $return = $this->dealBox($result); if ($return){ $arr = array( 'return_code' => 'SUCCESS', 'return_msg' => 'OK', ); return $this->arrayToXml($arr); }else{ file_put_contents("order_pay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 支付宝支付--充值盲盒回调订单 */ public function alipayBlindRechargeNotify(){ $result = input('post.'); if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') { $return = $this->dealBox($result); if ($return){ echo 'success'; }else{ file_put_contents("order_alipay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 盲盒充值次数处理数据库信息 * @param $result * @return bool */ function dealBox($result){ $com = true; Db::startTrans(); try { $order = Db::name('store_blind_recharge')->where('order_no',$result['out_trade_no'])->find(); if ($order['status']==1) return true; Db::name('store_blind_recharge') ->where('order_no',$result['out_trade_no']) ->update(['status'=>1,'pay_at'=>date('Y-m-d H:i:s'),'return_success_info'=>json_encode($result,true)]); //用户加次数 Db::name('store_member')->where('id',$order['m_id'])->setInc('lottery_number',$order['num']); Db::commit(); } catch (\Exception $e){ $com = false; Db::rollback(); } if ($com){ setMemberInfoHash($order['m_id']); return true; }else{ return false; } } /** * 微信支付--二级市场回调订单 */ public function SecondaryWxOrderNotify(){ $payXml = file_get_contents("php://input"); //将xml格式转化为json格式 $jsonXml = json_encode(simplexml_load_string($payXml, 'SimpleXMLElement', LIBXML_NOCDATA)); //将json格式转成数组格式 $result['out_trade_no'] $result = json_decode($jsonXml, true); if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { $return = $this->dealSecondary($result); if ($return){ $arr = array( 'return_code' => 'SUCCESS', 'return_msg' => 'OK', ); return $this->arrayToXml($arr); }else{ file_put_contents("order_pay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 支付宝支付--二级市场回调订单 */ public function alipaySecondaryNotify(){ $results = input('post.'); $zfb = new AliPay3(); $result= json_decode($zfb->sslDeReturn($results['notifyData']),true); file_put_contents("zfbse_pay_return.txt", json_encode($result) . "\n" . "\n", FILE_APPEND); if ($result['status'] == 'success') { $result['out_trade_no'] = $result['out_trade_id']; $return = $this->dealSecondary($result); if ($return){ echo 'success'; }else{ file_put_contents("order_alipay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 杉德支付--二级市场回调订单 */ public function shandeSecondaryNotify(){ $data = stripslashes($_POST['data']); //支付数据 file_put_contents("shandepay.txt", $data . "\n" , FILE_APPEND); $data = json_decode($data,true); if ($data['body']['orderStatus']==1){ //$data['body']['orderCode'] $return = $this->dealSecondary($data,'sd'); if ($return){ return 'respCode=000000'; }else{ file_put_contents("shandepay_error.txt", $data . "\n" . json_encode($data) . "\n" . "\n", FILE_APPEND); } } } /** * 二级市场-汇聚支付支付宝h5,银联h5 */ public function ylSecondaryNotify(){ $result = input(); debug($result); if ($result['r6_Status'] == '100'){ $return = $this->dealSecondary($result,'huijuh5'); if ($return){ echo 'success'; }else{ file_put_contents("order_error.txt", json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 二级市场处理数据库信息 * @param $result * @return bool */ function dealSecondary($result,$from=''){ $com = true; Db::startTrans(); try { if ($from=='sd'){ $out_trade_no = $result['body']['orderCode']; }elseif ($from=='sd'){ $out_trade_no = $result['out_trade_no']; } elseif($from=='huijuh5'){ $out_trade_no = $result['r2_OrderNo'];; } $order = Db::name('store_order_info_order')->where('order_no',$out_trade_no)->find(); if ($order['status']==1) return false; if (!$order) return false; $resale_status = Db::name('store_order_info')->where('id',$order['info_id'])->value('resale_status'); if ($resale_status!=2){ }else{ Db::name('store_order_info_order') ->where('order_no',$out_trade_no) ->update(['status'=>1,'pay_at'=>date('Y-m-d H:i:s'),'return_success_info'=>json_encode($result,true)]); //藏品修改状态 Db::name('store_order_info')->where('id',$order['info_id'])->update([ 'status'=>2, 'resale_status'=>3, 'selling_time'=>date('Y-m-d H:i:s') ]); $info = Db::name('store_order_info')->where('id',$order['info_id'])->find(); //增加一条记录 $to_date = [ 'order_id'=>$info['order_id'], 'order_no'=>get_order_sn(), 'tag'=>$info['tag'], 'mid'=>$order['mid'], 'c_id'=>$info['c_id'], 'name'=>$info['name'], 'cover'=>$info['cover'], 'pro_info'=>$info['pro_info'], 'type'=>$info['type'], 'status'=>3, 'from'=>2, 'to_mid'=>$info['mid'], 'over_time'=>date('Y-m-d H:i:s'), 'tokenid'=>$info['tokenid'], 'nfttype'=>$info['nfttype'], 'collectors_hash'=>'', 'collectors_hash_time'=>date('Y-m-d H:i:s') ]; Db::name('store_order_info')->insert($to_date); //增加用户余额 memberMoneyChange($order['to_account'],3,$info['mid'],'出售藏品',1,$order['id']); Db::commit(); } } catch (\Exception $e){ $com = false; Db::rollback(); } if ($com){ setMemberInfoHash($order['mid']); return true; }else{ return false; } } /** * 余额充值--汇聚云闪付,支付宝h5支付回调 */ public function ylrechargeNotify(){ $result = input(); debug($result); if ($result['r6_Status'] == '100'){ $return = $this->dealRecharge($result,'huijuh5'); if ($return){ echo 'success'; }else{ file_put_contents("recharge_error.txt", json_encode($result) . "\n" . "\n", FILE_APPEND); } } } //处理充值 function dealRecharge($result,$from=''){ $com = true; Db::startTrans(); try { if($from=='huijuh5'){ $out_trade_no = $result['r2_OrderNo'];; } $order = Db::name('store_member_recharge')->where('order_no',$out_trade_no)->find(); if (!$order || $order['status']==1) return false; //增加用户余额 $re = memberMoneyChange($order['pay_price'],3,$order['m_id'],'余额充值',1,$order['id']); if ($re){ Db::name('store_member_recharge') ->where('order_no',$out_trade_no) ->update(['status'=>1,'pay_at'=>date('Y-m-d H:i:s'),'return_success_info'=>json_encode($result,true)]); Db::commit(); }else{ $com = false; Db::rollback(); } } catch (\Exception $e){ $com = false; Db::rollback(); } if ($com){ setMemberInfoHash($order['m_id']); return true; }else{ return false; } } /** * 数组转xml * @ApiInternal */ public function arrayToXml($arr) { $xml = ""; foreach ($arr as $key => $val) { if (is_numeric($val)) { $xml .= "<" . $key . ">" . $val . ""; } else $xml .= "<" . $key . ">"; } $xml .= ""; return $xml; } }