WIN-2308041133\Administrator 6 meses atrás
pai
commit
9eb3ea9bc0
1 arquivos alterados com 20 adições e 11 exclusões
  1. 20 11
      application/api/controller/Wechat.php

+ 20 - 11
application/api/controller/Wechat.php

@@ -2,6 +2,7 @@
 
 namespace app\api\controller;
 
+use app\admin\model\Company;
 use app\admin\model\WechatPlan;
 use app\admin\model\WechatPlanRecord;
 use app\common\model\UserRelation;
@@ -113,19 +114,22 @@ class Wechat extends Api
     {
         $price = intval($request->param('price'));
         $uid = intval($request->param('uid'));
+        $cid = intval($request->param('cid'));
         $plan_id = WechatPlan::where('price', $price)->value('plan_id');
         $p_id = WechatPlan::where('price', $price)->value('id');
-        var_dump($plan_id);
-        var_dump($p_id);die();
+//        var_dump($plan_id);
+//        var_dump($p_id);die();
 //        $plan_id = 11;
 //        $p_id = 12;
         try {
 //            $notify_url=Request::instance()->domain() . "/api/wechat/notify/" . $cid; //回调接口
-            $app_id = 'wx5681205d1ef4d9d3';
-            $mch_id = '1623907696';
-            $sub_mch_id = '';
+//            $app_id = 'wx5681205d1ef4d9d3';
+            $app_id = Company::where('id', $cid)->value('wechat_appid');
+//            $mch_id = '1623907696';
+            $mch_id = Company::where('id', $cid)->value('pay_weixin_mchid');
+
             $contract_code = $this->generateRandomString(12);
-            $notify_url = Request::instance()->domain() . "/api/wechat/notify/" . 12; //回调接口  $cid 企业id
+            $notify_url = Request::instance()->domain() . "/api/wechat/notify/" . $cid; //回调接口  $cid 企业id
 //            $num = time() + mt_rand(10, 999999) . '' . substr($msec, 2, 3);//生成随机数
 //            $request_serial=$this->generateUniqueSerialNumber();
             $request_serial = WechatPlanRecord::where('is_signing', 0)->order('request_serial desc')->value('request_serial');
@@ -134,7 +138,10 @@ class Wechat extends Api
             } else {
                 $request_serial = $request_serial + 1;
             }
-            $contract_display_account = '咸宁红十字';
+            $contract_display_account = User::where('id', $uid)->value('nickname');
+            if (empty($contract_display_account)){
+                $this->error('用户不存在!');
+            }
             $timestamp = time();
             $version = '1.0';
             $array = array(
@@ -165,7 +172,7 @@ class Wechat extends Api
             @file_put_contents("quanju.txt", $url . "-链接\r\n", 8);
 //            var_dump($url);
             $response = $this->curl_get($url);
-            $url = $this->OfficialAccountSigning($app_id, $mch_id, $plan_id, $contract_code, $request_serial, $contract_display_account, $notify_url, $version, $sign, $timestamp);
+//            $url = $this->OfficialAccountSigning($app_id, $mch_id, $plan_id, $contract_code, $request_serial, $contract_display_account, $notify_url, $version, $sign, $timestamp);
             @file_put_contents("quanju.txt", $response . '返回链接');
 
             WechatPlanRecord::create([
@@ -184,7 +191,8 @@ class Wechat extends Api
             $this->success('获取成功', $response);
 //            return $response;
         } catch (Exception $e) {
-            var_dump($e->getMessage());
+//            var_dump($e->getMessage());
+            @file_put_contents("quanju.txt", $e->getMessage() . "-报错信息\r\n", 8);
             @file_put_contents("error.txt", $e->getFile() . '-', $e->getLine(), '-' . $e->getMessage());
         }
     }
@@ -201,10 +209,11 @@ class Wechat extends Api
     {
         $record_id = intval($request->param('id'));
         $uid = intval($request->param('uid'));
+        $cid = intval($request->param('uid'));
         try {
 //            $notify_url=Request::instance()->domain() . "/api/wechat/notify/" . $cid; //回调接口
-            $app_id = 'wx5681205d1ef4d9d3';
-            $mch_id = '1623907696';
+            $app_id = Company::where('id', $cid)->value('wechat_appid');
+            $mch_id = Company::where('id', $cid)->value('pay_weixin_mchid');
             $contract_code = WechatPlanRecord::where('id', $record_id)->value('contract_code');
             $plan_id = WechatPlanRecord::where('id', $record_id)->value('wechat_plan_id');
             $contract_termination_remark = '解约备注';