| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- declare (strict_types=1);
- namespace app\api\controller;
- use app\Request;
- use app\BaseController;
- use app\model\api\PayTrade;
- use library\services\UtilService;
- use library\utils\WxpayV2 as wxpayApi;
- use WeChatPay\Transformer;
- use app\lib\OrderLib;
- use think\Exception;
- class Pay extends BaseController{
- /**
- * 微信支付V2异步反馈
- * @param Request $request
- * @return boolean
- */
- public function wxpayNotify(Request $request){
- $logfile = app()->getRootPath().'public/log/wxnotify.log';
- file_put_contents($logfile, date("Y-m-d H:i:s").PHP_EOL,FILE_APPEND | LOCK_EX);
- $xmlData = $request->getInput();
- if(empty($xmlData)){
- return false;
- }
- file_put_contents($logfile, $xmlData.PHP_EOL,FILE_APPEND | LOCK_EX);
- $wxpay = new wxpayApi();
- $res = $wxpay->notifyCheckSign($xmlData);
- if(!$res){
- return false;
- }
- // if($res["return_code"] && $res["return_code"]=""){
- // return false;
- // }
-
-
-
-
-
-
- //
- // if(empty($post["event_type"]) || $post["event_type"] != "TRANSACTION.SUCCESS"){
- // return false;
- // }
- // if(empty($post["resource_type"]) || $post["resource_type"]!="encrypt-resource"){
- // return false;
- // }
- // if(empty($post["resource"])){
- // return false;
- // }
- // $wxpay = new wxpayApi();
- // $result = $wxpay->aesGcmDecrypt([
- // "associated_data"=>$post["resource"]["associated_data"],
- // "nonce"=>$post["resource"]["nonce"],
- // "ciphertext"=>$post["resource"]["ciphertext"],
- // ]);
- //
- // if(!$result){
- // return false;
- // }
- // //商家内部订单号
- // $out_trade_no = $result["out_trade_no"];
- // $res = $wxpay->searchOrder($out_trade_no);
- // if(!$res){
- // return false;
- // }
- // $data = json_decode($res,true);
- // //支付成功
- // if($data["trade_state"]=="SUCCESS"){
- // $payDataInfo = [
- // 'totalMoney' =>(empty($data["amount"]) || empty($data["amount"]["total"])) ?"未返回":$data["amount"]["total"]/100,
- // 'payMoney' =>(empty($data["amount"]) || empty($data["amount"]["payer_total"]))?"未返回":$data["amount"]["payer_total"]/100,
- // 'payTradeNo' =>empty($data["transaction_id"]) ? "未返回" : $data["transaction_id"],
- // 'outTradeNo' =>empty($data["out_trade_no"]) ? "未返回" : $data["out_trade_no"],
- // "tradeStatus"=>empty($data["trade_state"]) ? "未返回" : $data["trade_state"],
- // "payTime" =>empty($data["success_time"]) ? "未返回" : $data["success_time"],
- // ];
- // $pay_json = json_encode($payDataInfo);
- // (new OrderLib)->orderPay($out_trade_no, $pay_json);
- // }
- }
- /**
- * 微信支付V3异步反馈
- * @param Request $request
- * @return boolean
- */
- public function wxpayNotifyV3(Request $request){
- $post = UtilService::getMore([
- ['id', ''],
- ['create_time', ''],
- ['event_type',''],
- ['resource_type', ''],
- ['resource',[]],
- ['summary', ''],
- ], $request);
- if(empty($post["event_type"]) || $post["event_type"] != "TRANSACTION.SUCCESS"){
- return false;
- }
- if(empty($post["resource_type"]) || $post["resource_type"]!="encrypt-resource"){
- return false;
- }
- if(empty($post["resource"])){
- return false;
- }
- $wxpay = new wxpayApi();
- $result = $wxpay->aesGcmDecrypt([
- "associated_data"=>$post["resource"]["associated_data"],
- "nonce"=>$post["resource"]["nonce"],
- "ciphertext"=>$post["resource"]["ciphertext"],
- ]);
-
- if(!$result){
- return false;
- }
- //商家内部订单号
- $out_trade_no = $result["out_trade_no"];
- $res = $wxpay->searchOrder($out_trade_no);
- if(!$res){
- return false;
- }
- $data = json_decode($res,true);
- //支付成功
- if($data["trade_state"]=="SUCCESS"){
- $payDataInfo = [
- 'totalMoney' =>(empty($data["amount"]) || empty($data["amount"]["total"])) ?"未返回":$data["amount"]["total"]/100,
- 'payMoney' =>(empty($data["amount"]) || empty($data["amount"]["payer_total"]))?"未返回":$data["amount"]["payer_total"]/100,
- 'payTradeNo' =>empty($data["transaction_id"]) ? "未返回" : $data["transaction_id"],
- 'outTradeNo' =>empty($data["out_trade_no"]) ? "未返回" : $data["out_trade_no"],
- "tradeStatus"=>empty($data["trade_state"]) ? "未返回" : $data["trade_state"],
- "payTime" =>empty($data["success_time"]) ? "未返回" : $data["success_time"],
- ];
- $pay_json = json_encode($payDataInfo);
- (new OrderLib)->orderPay($out_trade_no, $pay_json);
- }
- }
- }
|