From 12bcec2ab1640d53be228f8c5b6f883ade195c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9APD?= <13558507+yao-shipeng@user.noreply.gitee.com> Date: Wed, 7 Aug 2024 04:00:15 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20serve/ap?= =?UTF-8?q?p/controller/Wechat.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- serve/app/controller/Wechat.php | 169 -------------------------------- 1 file changed, 169 deletions(-) delete mode 100644 serve/app/controller/Wechat.php diff --git a/serve/app/controller/Wechat.php b/serve/app/controller/Wechat.php deleted file mode 100644 index ab45955..0000000 --- a/serve/app/controller/Wechat.php +++ /dev/null @@ -1,169 +0,0 @@ -appId=$deploy['wechat']['appid']; - $config->merchantId=$deploy['wechat']['mchid']; - $config->key=$deploy['wechat']['mchkey']; - //单据数据 - $order=new \WxPayMicroPay; - $order->SetBody($deploy['wechat']['title']); - $order->SetOut_trade_no($input['number']); - $money=math()->chain($input['money'])->mul(100)->done(); - $order->SetTotal_fee($money); - $order->SetAuth_code($input['code']); - //发送请求 - $result=\WxPayApi::micropay($config,$order); - if($result['return_code']=='SUCCESS'){ - //判断支付状态 - if($result['result_code']=='SUCCESS'){ - //支付成功 - $result=['state'=>'success','info'=>$result['transaction_id']]; - }else{ - //支付失败 - if(in_array($result['err_code'],['SYSTEMERROR','BANKERROR','USERPAYING'])){ - //返回等待信息 - $result=['state'=>'wait','info'=>'等待操作...']; - }else{ - //确认失败,返回错误信息 - $result=['state'=>'wrong','info'=>$result['err_code_des']]; - } - } - }else{ - $result=['state'=>'wrong','info'=>$result['return_msg']]; - } - }else{ - $result=['state'=>'error','info'=>'支付参数不完整!']; - } - }else{ - $result=['state'=>'error','info'=>'传入参数不完整!']; - } - return json($result); - } - //查询单据 - public function query(){ - $input=input('post.'); - if(existFull($input,['number'])){ - //读取配置 - $deploy=getFrameDeploy(); - if(!empty($deploy)){ - //微信支付SDK - $wxPayPath=root_path('extend/wechat'); - require_once $wxPayPath."WxPay.Api.php"; - require_once $wxPayPath."WxPay.Config.php"; - //配置数据 - $config=new \WxPayConfig; - $config->appId=$deploy['wechat']['appid']; - $config->merchantId=$deploy['wechat']['mchid']; - $config->key=$deploy['wechat']['mchkey']; - //单据数据 - $order=new \WxPayOrderQuery; - $order->SetOut_trade_no($input['number']); - //发送请求 - $result=\WxPayApi::orderQuery($config,$order); - if($result['return_code']=='SUCCESS'){ - //判断查询状态 - if($result['result_code']=='SUCCESS'){ - //查询成功 - if($result['trade_state']=='SUCCESS'){ - //支付成功 - $result=['state'=>'success','info'=>$result['transaction_id']]; - }elseif($result['trade_state']=='USERPAYING'){ - //用户支付中,返回等待信息 - $result=['state'=>'wait','info'=>'等待操作...']; - }else{ - //其他状态,返回数据 - $result=['state'=>'wrong','info'=>$result['trade_state_desc']]; - } - }else{ - //查询失败 - if($result['err_code']=='SYSTEMERROR'){ - //返回等待信息 - $result=['state'=>'wait','info'=>'等待操作...']; - }else{ - //返回查询错误信息 - $result=['state'=>'wrong','info'=>$result['err_code_des']]; - } - } - }else{ - $result=['state'=>'wrong','info'=>$result['return_msg']]; - } - }else{ - $result=['state'=>'error','info'=>'支付参数不完整!']; - } - }else{ - $result=['state'=>'error','info'=>'传入参数不完整!']; - } - return json($result); - } - //撤销单据 - //支付成功退款|未支付关闭单据 - public function cancel(){ - $input=input('post.'); - if(existFull($input,['number'])){ - //读取配置 - $deploy=getFrameDeploy(); - if(!empty($deploy)){ - //微信支付SDK - $wxPayPath=root_path('extend/wechat'); - require_once $wxPayPath."WxPay.Api.php"; - require_once $wxPayPath."WxPay.Config.php"; - $sslCert = tmpfile(); - fwrite($sslCert,$deploy['wechat']['certText']); - $sslKey = tmpfile(); - fwrite($sslKey,$deploy['wechat']['keyText']); - //配置数据 - $config=new \WxPayConfig; - $config->appId=$deploy['wechat']['appid']; - $config->merchantId=$deploy['wechat']['mchid']; - $config->key=$deploy['wechat']['mchkey']; - $config->sslCertPath=stream_get_meta_data($sslCert)['uri']; - $config->sslKeyPath=stream_get_meta_data($sslKey)['uri']; - //单据数据 - $order=new \WxPayReverse; - $order->SetOut_trade_no($input['number']); - //发送请求 - $result=\WxPayApi::reverse($config,$order); - if($result['return_code']=='SUCCESS'){ - //判断查询状态 - if($result['result_code']=='SUCCESS'){ - //撤销成功 - $result=['state'=>'success','info'=>'撤销单据成功!']; - }else{ - //查询失败 - if(in_array($result['err_code'],['SYSTEMERROR','USERPAYING'])){ - //等待信息 - $result=['state'=>'wait','info'=>'等待操作...']; - }else{ - //返回查询错误信息 - $result=['state'=>'wrong','info'=>$result['err_code_des']]; - } - } - }else{ - $result=['state'=>'wrong','info'=>$result['return_msg']]; - } - }else{ - $result=['state'=>'error','info'=>'支付参数不完整!']; - } - }else{ - $result=['state'=>'error','info'=>'传入参数不完整!']; - } - return json($result); - } -} \ No newline at end of file