WIN-2308041133\Administrator 5 months ago
parent
commit
ee6394d736
2 changed files with 107 additions and 53 deletions
  1. 59 8
      application/api/controller/Lave.php
  2. 48 45
      extend/liuniu/WechatService.php

+ 59 - 8
application/api/controller/Lave.php

@@ -195,19 +195,26 @@ class Lave extends Api
         @file_put_contents("quanju.txt", $plan_id . "-签约模版编号\r\n", 8);
         @file_put_contents("quanju.txt", $plan_id . "-签约模版编号\r\n", 8);
 //        unset($where1['plan_id']);
 //        unset($where1['plan_id']);
         $where1['contract_code'] = WechatPlanRecord::getNewCode();
         $where1['contract_code'] = WechatPlanRecord::getNewCode();
-        $order = LaveMonthModel::create($where1);
+        if ($where['uid']!=6779&&$where['uid']!=12125){
+            $order = LaveMonthModel::create($where1);
+            if (!$order) $this->error(LaveMonthModel::getErrorInfo());
+            $orderId = $order['order_id'];
+            $order['plan_id'] = $plan_id;
+        }else{
+            $orderId = $where1['order_id'];
+        }
         $where1['contract_display_account'] = $where1['name'];
         $where1['contract_display_account'] = $where1['name'];
         cache('lave_' . $where['user_id'], '1', 10);
         cache('lave_' . $where['user_id'], '1', 10);
-        if (!$order) $this->error(LaveMonthModel::getErrorInfo());
-        $orderId = $order['order_id'];
+
         $info = compact('orderId');
         $info = compact('orderId');
-        $order['plan_id'] = $plan_id;
         if ($orderId) {
         if ($orderId) {
-            $orderInfo = LaveMonthModel::where('order_id', $orderId)->find();
-            if (!$orderInfo || !isset($orderInfo['paid'])) {
-                $this->error('支付订单不存在!');
+            if ($where['uid']!=6779&&$where['uid']!=12125){
+                $orderInfo = LaveMonthModel::where('order_id', $orderId)->find();
+                if (!$orderInfo || !isset($orderInfo['paid'])) {
+                    $this->error('支付订单不存在!');
+                }
+                if ($orderInfo['paid']) $this->error('支付已支付!');
             }
             }
-            if ($orderInfo['paid']) $this->error('支付已支付!');
 //          创建签约
 //          创建签约
             $plan_record = [
             $plan_record = [
                 'plan_id' => $plan_id,
                 'plan_id' => $plan_id,
@@ -317,6 +324,50 @@ class Lave extends Api
         $this->success('扣款完成');
         $this->success('扣款完成');
 //        }
 //        }
     }
     }
+    //    申请进行第一次的扣款
+    public static function paySignPap($contract_code)
+    {
+        @file_put_contents("quanju3.txt", $contract_code."测试申请扣款-\r\n", 8);
+//        die();
+
+        $plan = WechatPlanRecord::where('contract_code', $contract_code)->find();
+        if ($plan['uid']!=6779&&$plan['uid']!=12125){
+            return false;
+        }
+        if (!empty($plan)){
+                    $cid = $plan['cid'];
+                    $mch_id = Company::where('id', $cid)->value('pay_weixin_mchid');
+                    $where1['cid'] = $cid;
+                    $where1['user_id'] = $plan['uid'];
+                    $where1['order_name'] = $plan['order_name'];
+                    $where1['order_id'] = LaveMonthModel::getNewOrderId();;
+
+//                $where1['category_id']=$v['category_id'];
+                    $where1['amount'] = $plan['price'];
+                    $where1['name'] = $plan['contract_display_account'];
+                    $where1['contact'] = '';
+                    $where1['tel'] = $plan['tel'];
+                    $where1['address'] = '用户未填写联系地址';
+                    $where1['is_open'] = $plan['is_open'];
+                    $where1['is_ticket'] = '0';
+                    $where1['type'] = '0';
+                    $where1['record_id'] = $plan['id'];
+                    $where1['contract_code'] = $plan['contract_code'];
+                    $where1['plan_id'] = $plan['plan_id'];
+
+                    $where1['nonce_str'] = uniqid();
+//                $where1['help_id']='0';
+//                    @file_put_contents("quanju.txt", json_encode($where1)."测试申请扣款-\r\n", 8);
+                    $order = LaveMonthModel::create($where1);
+//            }
+//                    var_dump(988745613);die();
+                    $rs = WechatService::papPayApply($mch_id, $where1['order_id'], $where1['amount'], "lave", '月捐款', 'PAP', [], $cid, $v['contract_id'], $where1['order_name'], $where1['nonce_str']);
+                    @file_put_contents("quanju.txt", json_encode($rs)."-月捐汇报\r\n", 8);
+//                }
+//            }
+        }
+        return true;
+    }
 //    检查签约用户是否有符合签约月份数量的扣款记录
 //    检查签约用户是否有符合签约月份数量的扣款记录
     public function check_pay_pap(){
     public function check_pay_pap(){
         $list = WechatPlanRecord::where('is_signing', 0)->select();  //签约中
         $list = WechatPlanRecord::where('is_signing', 0)->select();  //签约中

+ 48 - 45
extend/liuniu/WechatService.php

@@ -4,6 +4,7 @@ namespace liuniu;
 
 
 use app\admin\model\Company;
 use app\admin\model\Company;
 use app\admin\model\WechatPlanRecord;
 use app\admin\model\WechatPlanRecord;
+use app\api\controller\Lave;
 use app\common\model\LaveMonth;
 use app\common\model\LaveMonth;
 use app\common\model\WechatContext;
 use app\common\model\WechatContext;
 use EasyWeChat\Factory;
 use EasyWeChat\Factory;
@@ -381,6 +382,8 @@ class WechatService
                         $params = [$cid, $notify['contract_code']];
                         $params = [$cid, $notify['contract_code']];
                         Hook::exec("\\liuniu\\repositories\\PaymentRepositories", "wechat" . ucfirst('MonthLave'), $params);
                         Hook::exec("\\liuniu\\repositories\\PaymentRepositories", "wechat" . ucfirst('MonthLave'), $params);
                         @file_put_contents("quanju.txt", json_encode($params)."-不知道行不行\r\n", 8);
                         @file_put_contents("quanju.txt", json_encode($params)."-不知道行不行\r\n", 8);
+                        $tf = Lave::paySignPap($notify['contract_code']);
+                        @file_put_contents("quanju3.txt", $tf."-第一次扣款\r\n", 8);
                     }elseif ($notify['change_type']=='DELETE'){
                     }elseif ($notify['change_type']=='DELETE'){
                         @file_put_contents("quanju.txt", "-关闭签约\r\n", 8);
                         @file_put_contents("quanju.txt", "-关闭签约\r\n", 8);
                         $cs=WechatPlanRecord::where('contract_code',$notify['contract_code'])->Update(['is_signing' => 1,'deletetime'=>time()]);
                         $cs=WechatPlanRecord::where('contract_code',$notify['contract_code'])->Update(['is_signing' => 1,'deletetime'=>time()]);
@@ -650,49 +653,49 @@ class WechatService
         $url = 'https://api.mch.weixin.qq.com/papay/entrustweb?' . rtrim($queryString, '&');
         $url = 'https://api.mch.weixin.qq.com/papay/entrustweb?' . rtrim($queryString, '&');
 
 
 // 记录请求URL
 // 记录请求URL
-        @file_put_contents("quanju3.txt", "请求URL: " . $url . "\n");
-        return $url;
-// 发送请求(禁止自动重定向)
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $url);
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
-        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); // 关键:禁止自动重定向
-        curl_setopt($ch, CURLOPT_HEADER, true); // 获取响应头
-
-        $response = curl_exec($ch);
-        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-
-// 记录完整响应
-        @file_put_contents("quanju3.txt", "HTTP状态码: " . $http_code . "\n响应内容: " . $response . "\n", FILE_APPEND);
-
-// 分析响应
-        if ($http_code == 302) {
-            // 解析重定向地址
-            preg_match('/Location: (.*)/i', $response, $matches);
-            $redirect_url = trim($matches[1] ?? '');
-
-            if ($redirect_url) {
-                // 成功重定向到微信签约页面
-                @file_put_contents("quanju3.txt", "签约URL: " . $redirect_url . "\n", FILE_APPEND);
-            } else {
-                @file_put_contents("quanju3.txt", "错误:未找到重定向地址\n", FILE_APPEND);
-            }
-        } else {
-            // 提取可能的错误信息
-            preg_match('/<error_description><!\[CDATA\[(.*?)\]\]><\/error_description>/', $response, $error_matches);
-            $error_msg = $error_matches[1] ?? '未知错误';
-
-            @file_put_contents("quanju3.txt", "错误信息: " . $error_msg . "\n", FILE_APPEND);
-        }
-
-        curl_close($ch);
-        if (curl_errno($ch)) {
-            echo 'CURL Error: ' . curl_error($ch);
-        } else {
-            echo "Response:\n" . $response;
-        }
+//        @file_put_contents("quanju3.txt", "请求URL: " . $url . "\n");
+//        return $url;
+//// 发送请求(禁止自动重定向)
+//        $ch = curl_init();
+//        curl_setopt($ch, CURLOPT_URL, $url);
+//        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+//        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
+//        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
+//        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); // 关键:禁止自动重定向
+//        curl_setopt($ch, CURLOPT_HEADER, true); // 获取响应头
+//
+//        $response = curl_exec($ch);
+//        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+//
+//// 记录完整响应
+//        @file_put_contents("quanju3.txt", "HTTP状态码: " . $http_code . "\n响应内容: " . $response . "\n", FILE_APPEND);
+//
+//// 分析响应
+//        if ($http_code == 302) {
+//            // 解析重定向地址
+//            preg_match('/Location: (.*)/i', $response, $matches);
+//            $redirect_url = trim($matches[1] ?? '');
+//
+//            if ($redirect_url) {
+//                // 成功重定向到微信签约页面
+//                @file_put_contents("quanju3.txt", "签约URL: " . $redirect_url . "\n", FILE_APPEND);
+//            } else {
+//                @file_put_contents("quanju3.txt", "错误:未找到重定向地址\n", FILE_APPEND);
+//            }
+//        } else {
+//            // 提取可能的错误信息
+//            preg_match('/<error_description><!\[CDATA\[(.*?)\]\]><\/error_description>/', $response, $error_matches);
+//            $error_msg = $error_matches[1] ?? '未知错误';
+//
+//            @file_put_contents("quanju3.txt", "错误信息: " . $error_msg . "\n", FILE_APPEND);
+//        }
+//
+//        curl_close($ch);
+//        if (curl_errno($ch)) {
+//            echo 'CURL Error: ' . curl_error($ch);
+//        } else {
+//            echo "Response:\n" . $response;
+//        }
 
 
 //        $request_serial = time();
 //        $request_serial = time();
 //        $timestamp = time();
 //        $timestamp = time();
@@ -703,8 +706,8 @@ class WechatService
 //            $order
 //            $order
 //        );
 //        );
 //        var_dump($result);die();
 //        var_dump($result);die();
-        @file_put_contents("quanju3.txt", json_encode($response) . "-签约返回结果测试\r\n", 8);
-        return $response;
+//        @file_put_contents("quanju3.txt", json_encode($response) . "-签约返回结果测试\r\n", 8);
+        return $url;
     }
     }
     public static function generateWechatMD5Sign($params, $key) {
     public static function generateWechatMD5Sign($params, $key) {
         // 1. 过滤空值和签名参数
         // 1. 过滤空值和签名参数