WxxcxPush.php 28.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2022/06/13 05:55
 * Time: 05:55
 */

namespace app\api\controller\v1;

use app\admin\model\tytcm\Reservation;
use app\api\controller\Common;
use think\Db;
use think\exception\PDOException;
use think\Request;

/**
 * 微信小程序订阅消息推送
 * @package app\api\controller\v1
 */
class WxxcxPush extends Base
{
    /**
     * 1.提醒社区管理员处理新的入州申请,发送订阅消息
     */
    public function sendDealApplyMessage($openid_arr, $apply_info)
    {
        if (empty($openid_arr)) {
            return $this->array_callback(false, "未找到需要推送的人员");
        }
        $sum_count = 0;//总共需要推送的人
        $react_count = 0;//实际推送人数
        if (!empty($openid_arr)) {
            $sum_count = count($openid_arr);//总共需要推送的人数
            //通知
            $page = 'pages/admin_list/detail?apply_id=' . $apply_info['id'];

            $value1 = "入州报备审核";

            if ($apply_info['is_transfer'] == 1) {
                //判断是否是转办
                $value1 = "入州报备审核【转办】";
            } elseif ($apply_info['user_reapply'] == 1) {
                //判断是否是用户更新申报
                $value1 = "入州报备审核【用户更新】";
            }

            $temp = array(
                'value1' => $value1,
                'value2' => "待处理",
                'value3' => $apply_info['u_name'],
                'value4' => date("Y年m月d日 H:i", $apply_info['createtime']),
                'value5' => "点击立即处理",
            );
            // 启动事务
            Db::startTrans();
            try {
                $createtime = $apply_info['createtime'];
                foreach ($openid_arr as $uk => $uv) {
                    $user = [];
                    $insert_message_log_data = [];

                    $user = Db::name("user")->where("wx_xcx_openid", $uv)->order("id desc")->find();
                    $insert_message_log_data = [
                        "unionid" => $user['unionid'],
                        "wechat_xcx_openid" => $uv,
                        "corp_user_id" => 0,//发送人
                        "createtime" => $createtime,
                    ];
                    if (!empty($uv)) {
                        $res = beingPushed(5, $uv, $page, $temp);
//                        file_put_contents("kevin_wx_xcx_push.log", date("Y-m-d H:i:s") . $uv. "推送》" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
                        $res_arr = !empty($res) ? json_decode($res, true) : [];
                        if (!empty($res_arr) && $res_arr['errcode'] == "0") {
                            //推送成功
                            $react_count = $react_count + 1;
                        } else {
                            //推送失败,记录问题
                            $insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE);
                        }

                    } else {
                        $error = [];
                        $error = ["errcode" => "-1", "errmsg" => "社区管理员未授权小程序"];
                        $insert_message_log_data['error_tips'] = json_encode($error, JSON_UNESCAPED_UNICODE);
                    }
                    //通知已读未读、推送日志记录起来
//                    Db::name("push_log")->insertGetId($insert_message_log_data);
                }

                // 执行提交操作
                Db::commit();
                return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);

            } catch (PDOException $e) {
                Db::rollback();
                return $this->array_callback(false, "请求异常" . $e->getMessage());
            }

        } else {
            return $this->array_callback(false, "未找到可通知的社区管理员!");
        }


    }

    /**
     * 2.提醒申请人员入州报备已处理完毕,发送订阅消息
     */
    public function sendDealSuccessMessage($openid_arr, $deal_info)
    {
        if (empty($openid_arr)) {
            return $this->array_callback(false, "未找到需要推送的人员");
        }
        $sum_count = 0;//总共需要推送的人
        $react_count = 0;//实际推送人数

        $apply_model = new \app\admin\model\AdmissionStateApply;
        $type_stu = Db::name("admission_state_apply")->where("id", $deal_info['id'])->value("type_stu");
        $type_stu_text_arr = $apply_model->getIncludeOldStatuTypeStuList();//处理结果['0'=> '正常','1'=> '健康监测','2'=> '已解除隔离','3'=> '高风险7天集中隔离5次核酸','4'=> '中风险7天居家3次核酸','5'=> '低风险3天2检']
        $type_stu_text = $type_stu_text_arr[$type_stu];
        $tips_text =  $type_stu_text;//"结果:" .

        if (!empty($openid_arr)) {
            $sum_count = count($openid_arr);//总共需要推送的人数
            //通知
            $page = 'pages/declare/detail?apply_id=' . $deal_info['id'];
            $temp = array(
                'value1' => "已审核(" . date("m-d H:i", $deal_info['deal_time']) . ")",
                'value2' => $deal_info['mng_user_name'],
                'value3' => sub_str($tips_text, 20, false)//date("Y-m-d H:i",$deal_info['deal_time'])
            );
            // 启动事务
            Db::startTrans();
            try {
                $createtime = $deal_info['deal_time'];
                foreach ($openid_arr as $uk => $uv) {
                    $user = [];
                    $insert_message_log_data = [];

                    $user = Db::name("user")->where("wx_xcx_openid", $uv)->order("id desc")->find();
                    $insert_message_log_data = [
                        "unionid" => $user['unionid'],
                        "wechat_xcx_openid" => $uv,
                        "corp_user_id" => $deal_info['deal_mng_user_id'],//发送人
                        "createtime" => $createtime,
                    ];
                    if (!empty($uv)) {
                        $res = beingPushed(2, $uv, $page, $temp);
//                        file_put_contents("kevin_wx_xcx_push.log", date("Y-m-d H:i:s") . $uv. "给用户推送》" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
                        $res_arr = !empty($res) ? json_decode($res, true) : [];
                        if (!empty($res_arr) && $res_arr['errcode'] == "0") {
                            //推送成功
                            $react_count = $react_count + 1;
                        } else {
                            //推送失败,记录问题
                            $insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE);
                        }

                    } else {
                        $error = [];
                        $error = ["errcode" => "-1", "errmsg" => "申报人未授权小程序"];
                        $insert_message_log_data['error_tips'] = json_encode($error, JSON_UNESCAPED_UNICODE);
                    }
                    //通知已读未读、推送日志记录起来
//                    Db::name("push_log")->insertGetId($insert_message_log_data);
                }

                // 执行提交操作
                Db::commit();
                return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);

            } catch (PDOException $e) {
                Db::rollback();
                return $this->array_callback(false, "请求异常" . $e->getMessage());
            }

        } else {
            return $this->array_callback(false, "未找到可通知的申报用户!");
        }

    }

    /**
     * 3.提醒监测人员上传核酸报告,发送订阅消息
     */
    public function sendUploadReportMessage($openid_arr, $deal_info,$report)
    {
        if (empty($openid_arr)) {
            return $this->array_callback(false, "未找到需要推送的人员");
        }
        $sum_count = 0;//总共需要推送的人
        $react_count = 0;//实际推送人数

        $apply_model = new \app\admin\model\AdmissionStateApply;
        $type_stu = Db::name("admission_state_apply")->where("id", $deal_info['id'])->value("type_stu");
        $type_stu_text_arr = $apply_model->getIncludeOldStatuTypeStuList();//处理结果['0'=> '正常','1'=> '健康监测','2'=> '已解除隔离','3'=> '高风险7天集中隔离5次核酸','4'=> '中风险7天居家3次核酸','5'=> '低风险3天2检']
        $type_stu_text = $type_stu_text_arr[$type_stu];
        $tips_text = $type_stu_text;

        if (!empty($openid_arr)) {
            $sum_count = count($openid_arr);//总共需要推送的人数
            //通知
            $page = 'pages/declare/detail?apply_id=' . $deal_info['id'];
            $temp = array(
                'value1' => "核酸报告上传提醒(".$report['report_num']."/".$report['need_report_num'].")",
                'value2' => $deal_info['mng_user_name'],
                'value3' => sub_str($tips_text, 20, false)//date("Y-m-d H:i",$deal_info['deal_time'])
            );
            // 启动事务
            Db::startTrans();
            try {
                foreach ($openid_arr as $uk => $uv) {
                    $user = [];
                    $insert_message_log_data = [];

                    $user = Db::name("user")->where("wx_xcx_openid", $uv)->order("id desc")->find();
                    $insert_message_log_data = [
                        "unionid" => $user['unionid'],
                        "wechat_xcx_openid" => $uv,
                        "corp_user_id" => $deal_info['deal_mng_user_id'],//发送人
                        "createtime" => time(),
                    ];
                    if (!empty($uv)) {
                        $res = beingPushed(2, $uv, $page, $temp);
//                        file_put_contents("kevin_wx_xcx_push.log", date("Y-m-d H:i:s") . $uv. "给用户推送》" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
                        $res_arr = !empty($res) ? json_decode($res, true) : [];
                        if (!empty($res_arr) && $res_arr['errcode'] == "0") {
                            //推送成功
                            $react_count = $react_count + 1;
                        } else {
                            //推送失败,记录问题
                            $insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE);
                        }

                    } else {
                        $error = [];
                        $error = ["errcode" => "-1", "errmsg" => "申报人未授权小程序"];
                        $insert_message_log_data['error_tips'] = json_encode($error, JSON_UNESCAPED_UNICODE);
                    }
                    //通知已读未读、推送日志记录起来
//                    Db::name("push_log")->insertGetId($insert_message_log_data);
                }

                // 执行提交操作
                Db::commit();
                return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);

            } catch (PDOException $e) {
                Db::rollback();
                return $this->array_callback(false, "请求异常" . $e->getMessage());
            }

        } else {
            return $this->array_callback(false, "未找到可通知的监测人员!");
        }

    }

    /**
     * 1.问政小程序发送工单订阅消息
     * $id 工单id
     */
    public function sendWorkorderMessage($id,$temp)
    {
        if (empty($id)) {
            return $this->array_callback(false, "id不能为空");
        }
        $workorderInfo = Db::name("workorder_orders")->where("id", $id)->find();

        $sum_count = 0;//总共需要推送的人
        $react_count = 0;//实际推送人数
        if (!empty($workorderInfo)) {
            if (!empty($workorderInfo['user_id'])) {
                //找到用户
                $where["id"] = ["=", $workorderInfo['user_id']];
                $user = Db::name("user")->where($where)->order("id desc")->find();
                if (!empty($user) && !empty($user['wx_xcx_openid'])) {
                    $sum_count = 1;//总共需要推送的人数
                    //通知
                    $page = 'pages/personal/speed/pading'."?id=".$id;


                    // 启动事务
                    Db::startTrans();
                    try {
                        $createtime = time();
                        $insert_message_log_data = [
                            "unionid" => $user['unionid'],
                            "wechat_xcx_openid" => $user['wx_xcx_openid'],
                            "message_id" => $id,
                            "status" => "0",//状态:0=未读,1=已读
                            "createtime" => $createtime,
                            "type"=>"2",//类型 1通知 2网络问政工单进度
                        ];
                        if (!empty($user) && !empty($user['wx_xcx_openid'])) {
                            $res = beingPushed(1, $user['wx_xcx_openid'], $page, $temp);
                            file_put_contents("kevin_wx_xcx_push.log", date("Y-m-d H:i:s") . "《" . $id . "》" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
                            $res_arr = !empty($res) ? json_decode($res, true) : [];
                            if (!empty($res_arr) && $res_arr['errcode'] == "0") {
                                //推送成功
                                $react_count = $react_count + 1;
                            } else {
                                //推送失败,记录问题
                                $insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE);
                            }

                        } else {
                            $error = [];
                            $error = ["errcode" => "-1", "errmsg" => "提工单用户未授权小程序"];
                            $insert_message_log_data['error_tips'] = json_encode($error, JSON_UNESCAPED_UNICODE);
                        }
                        //推送日志记录起来
                        Db::name("workorder_push_log")->insertGetId($insert_message_log_data);

                        // 执行提交操作
                        Db::commit();
                        return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);

                    } catch (PDOException $e) {
                        Db::rollback();
                        return $this->array_callback(false, "请求异常" . $e->getMessage());
                    }

                } else {
                    return $this->array_callback(false, "未找到可通知的成员!");
                }

            } else {
                return $this->array_callback(false, "未找到推送人员");
            }


        } else {
            return $this->array_callback(false, "未查找到有效的工单数据");
        }


    }

    public function sendMessage($data = [])
    {
        $res=[
            'appid'=>$this->AppID,
            'appsecret'=>$this->AppSecret,
        ];
        $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $res['appid'] . '&secret=' . $res['appsecret'];
        //json_encode 	对变量进行 JSON 编码     file_get_contents() 把整个文件读入一个字符串中。
        $res = json_decode(file_get_contents($url),true);
        $access_token = $res['access_token'] ;
        //请求url
        $url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=' . $access_token ;
        return self::curlPost($url,json_encode($data)) ;
    }


//发送post请求 小程序发送一次性订阅消息
    static function curlPost($url,$data)
    {
        $ch = curl_init();
        $params[CURLOPT_URL] = $url;    //请求url地址
        $params[CURLOPT_HEADER] = FALSE; //是否返回响应头信息
        $params[CURLOPT_SSL_VERIFYPEER] = false;
        $params[CURLOPT_SSL_VERIFYHOST] = false;
        $params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回
        $params[CURLOPT_POST] = true;
        $params[CURLOPT_POSTFIELDS] = $data;
        curl_setopt_array($ch, $params); //传入curl参数
        $content = curl_exec($ch); //执行
        curl_close($ch); //关闭连接
        return $content;
    }

    //小程序发送一次性订阅消息
    public function Message($openid,$reservation_id){
        $reservation=Db::name("order")->find($reservation_id);
        if(!empty($reservation)){
            // 启动事务
            Db::startTrans();
            try {
                //查询线路
                $route=Db::name("route")->find($reservation['route_id']);
                $createtime = time();
                if(!$reservation['remarks']){
                    $reservation['remarks']="暂无";
                }
                //通知
                $page = '/pageOne/moreRes/moreRes';
                $temp='oczyQ_SabASMQRRhDedXRGUEzCAuGh1xBw8sp2HVPvQ';
                $insert_message_log_data = array(
                    'value1' => $reservation['starting_point'],
                    'value2' =>  $reservation['end_point'],
                    'value3' => $reservation['number'],
                    'value4' => $reservation['reservation_time'],
                    'value5' => $reservation['remarks'],
                );

                    $res = beingPushed(5, $openid, $page, $insert_message_log_data);

                file_put_contents("kevin_wx_xcx_push.log", date("Y-m-d H:i:s") . "《" . $reservation_id . "》" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
                    $res_arr = !empty($res) ? json_decode($res, true) : [];
                    if (!empty($res_arr) && $res_arr['errcode'] == "0") {
                    } else {
                        //推送失败,记录问题
                        return $this->array_callback(true, "推1送成功".json_encode($res_arr));
                        $insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE);
                    }
                // 执行提交操作
                Db::commit();
                return $this->array_callback(true, "推送成功");

            } catch (PDOException $e) {
                Db::rollback();
                return $this->array_callback(false, "请求异常" . $e->getMessage());
            }


        }
    }
    //小程序发送一次性订阅消息
    public function refundMessage($openid,$reservation_id){
        $reservation=Db::name("order")->find($reservation_id);
        if(!empty($reservation)){
            // 启动事务
            Db::startTrans();
            try {
                //查询线路
                $route=Db::name("route")->find($reservation['route_id']);
                $user=Db::name("user")->find($reservation['user_id']);
                $createtime = time();
                if(!$reservation['remarks']){
                    $reservation['remarks']="暂无";
                }
                //通知
                $page = '/pageOne/moreRes/moreRes';
                $temp='oczyQ_SabASMQRRhDedXRGUEzCAuGh1xBw8sp2HVPvQ';
                $insert_message_log_data = array(
                    'value1' => $reservation['order_no'],
                    'value2' =>  1,
                    'value3' => $user['username'],
                    'value4' =>$reservation['reservation_time'],
                    'value5' => $reservation['remarks'],
                );

                $res = $this->beingPushed(6, $openid, $page, $insert_message_log_data);

                file_put_contents("kevin_wx_xcx_push.log", date("Y-m-d H:i:s") . "《" . $reservation_id . "》" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
                $res_arr = !empty($res) ? json_decode($res, true) : [];
                if (!empty($res_arr) && $res_arr['errcode'] == "0") {
                } else {
                    //推送失败,记录问题
                    return true;//$this->$this->array_callback(true, "推1送成功");
                    $insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE);
                }
                // 执行提交操作
                Db::commit();
                return true;

            } catch (PDOException $e) {
                Db::rollback();
                return $this->$this->array_callback(false, "请求异常" . $e->getMessage());
            }


        }
    }
    /**
     * 小程序模板推送选择类型
     * @param $type @模板类型
     * @param $openid @接收人ID
     * @param $page @跳转页面
     * @param $temp @具体提醒参数
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    function beingPushed($type, $openid, $page, $temp)
    {

        $data = [];
        $data['touser'] = $openid;
        $data['page'] = $page;
        //模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
        switch ($type) {
            case 1:
                //待审批事项提醒(新版本的长期订阅)
                $data['template_id'] = "ws6bz6-WyHHA-upU2oRzc_C5toDUexe9ZicQ-ITtImA";
                $data['data'] = [
                    "thing10" => [
                        'value' =>$temp['value1'],//审核状态(待处理)
                    ],
                    "thing12" => [
                        'value' => $temp['value2'],//申请人(测试黄超)
                    ],

                    "thing8" => [
                        'value' => $temp['value3'],//原因(入州报备审核)
                    ]
                ];
                break;
            case 2:
                //审核结果通知(新版本的长期订阅)
                $data['template_id'] = "Qt2xqfH8uQyTm1A0ReNxeybtAydAhfhi4HinnyB5f0s";
                $data['data'] = [
                    "thing1" => [
                        'value' => $temp['value1'],//提醒内容(已审核)
                    ],
//                    "name1" => [
//                        'value' => $temp['value2'],//审核人
//                    ],
                    "thing4" => [
                        'value' => $temp['value3'],//提示说明
                    ]
                ];
                break;
            case 3:
                //待审批事项提醒(老版本的一次性订阅)
                $data['template_id'] = "vVOonN76AFjxgz77iG-hcWrH6HJ-vPGKyIyAK0VzPIk";
                $data['data'] = [
                    "thing1" => [
                        'value' => $temp['value1'],//待办事项
                    ],
                    "thing4" => [
                        'value' => $temp['value2'],//流程状态
                    ],
                    "thing2" => [
                        'value' => $temp['value3'],//申请人
                    ],
                    "time3" => [
                        'value' => $temp['value4'],//申请时间
                    ],
                    "thing5" => [
                        'value' => $temp['value5'],//备注描述
                    ]
                ];
                break;
            case 4:
                //审核结果通知(老版本的一次性订阅)
                $data['template_id'] = "qR9reAuv_Ulelyg1H2xbN-GoWGWFRhS0t4nhtvnFr5Q";
                $data['data'] = [
                    "character_string1" => [
                        'value' => $temp['value1'],//审核结果
                    ],
                    "date3" => [
                        'value' => $temp['value2'],//审核人
                    ],
                    "thing5" => [
                        'value' => $temp['value3'],//审批时间
                    ],
                    "thing6" => [
                        'value' => $temp['value4'],//审批时间
                    ],
                    "thing7" => [
                        'value' => $temp['value5'],//审批时间
                    ]
                ];
                break;
            case 5:
                //预约结果通知
                $data['template_id'] = "oczyQ_SabASMQRRhDedXRGUEzCAuGh1xBw8sp2HVPvQ";
                $data['data'] = [
                    "thing1" => [
                        'value' => $temp['value1'],//备注
                    ],
                    "thing2" => [
                        'value' =>$temp['value2'],//日期
                    ],
                    "number3" => [
                        'value' => $temp['value3'],//就诊人
                    ],
                    "time4" => [
                        'value' => $temp['value4'],//就诊人
                    ],
                    "thing6" => [
                        'value' => $temp['value5'],//就诊人
                    ]
                ];
                break;
            case 6:
                //预约结果通知
                $data['template_id'] = "Dfvkyn3So2YE5aVJtkUTFWdjgzpo6VvWkNHZBOMb_n4";
                $data['data'] = [
                    "character_string1" => [
                        'value' => $temp['value1'],//备注
                    ],
                    "number2" => [
                        'value' =>$temp['value2'],//日期
                    ],
                    "name3" => [
                        'value' => $temp['value3'],//就诊人
                    ],
                    "date4" => [
                        'value' => $temp['value4'],//就诊人
                    ],
                    "thing9" => [
                        'value' => $temp['value5'],//就诊人
                    ]
                ];
                break;
        }

        return $this->sendSubscribeMessage($data);
    }
    /**
     * 小程序订阅消息推送
     * @param $data
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    function sendSubscribeMessage($data)
    {
        //access_token
        $access_token =$this->getAccessToken();

        //请求url
        $url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=' . $access_token;

        //file_put_contents('notify.txt',$data.PHP_EOL,FILE_APPEND);
        //跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
        $data['miniprogram_state'] = 'formal';

        return $this->curlPost($url, json_encode($data));
    }
    /**
     * 获取access_token
     * @return mixed
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    function getAccessToken()
    {
        $wx_xcx_token = \think\Db::name("wechat_token")->where("type", "wx_xcx")->find();
        if (empty($wx_xcx_token) || empty($wx_xcx_token['access_token']) || $wx_xcx_token['over_time'] <= time()) {
            //微信小程序失效
            //当前时间戳
            $now_time = strtotime(date('Y-m-d H:i:s', time()));

            //获取新的access_token
            $appid = config("site.wxxcx_AppID");
            $secret = config("site.wxxcx_AppSecret");
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret;
            $res = json_decode(file_get_contents($url), true);

            $access_token = $res['access_token'];
            if (!empty($access_token)) {
                $time = time();
                $update_data = [
                    "access_token" => $access_token,
                    "over_time" => $time + 7200,
                    "type" => "wx_xcx",
                    "updatetime" => $time
                ];
                if (!empty($wx_xcx_token)) {
                    //更新
                    \think\Db::name("wechat_token")->where("id", $wx_xcx_token['id'])->update($update_data);
                } else {
                    //新增
                    \think\Db::name("wechat_token")->insertGetId($update_data);
                }
            }
        } else {
            $access_token = $wx_xcx_token['access_token'];
        }
        return $access_token;
    }
    function array_callback($state = true, $msg = '', $data = array())
    {
        return array('state' => $state, 'msg' => $msg, 'data' => $data);
    }
}