getPushOpenId($exam_id); if(!$openids) { log::record('---------没有找到对应openid--------'); return false; } foreach($openids as $v) { $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid="; $full_url = $url . $v['openid']; // 请求 log::record('---------发送微信通知-发起订单-------'); log::record($full_url); $res = $this->curl_request($full_url, 'GET'); log::record('---------微信通知结果--------'); log::record($res); } return true; } public function pushWechatCancel($exam_id) { $openids = $this->getPushOpenId($exam_id); if(!$openids) { log::record('---------没有找到对应openid--------'); return false; } foreach($openids as $v) { $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid="; $full_url = $url . $v['openid']; // 请求 log::record('---------发送微信通知-取消订单-------'); log::record($full_url); $res = $this->curl_request($full_url, 'GET'); log::record('---------微信通知结果--------'); log::record($res); } return true; } public function pushWechatComplete($exam_id) { $openids = $this->getPushOpenId($exam_id); if(!$openids) { log::record('---------没有找到对应openid--------'); return false; } foreach($openids as $v) { $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid="; $full_url = $url . $v['openid']; // 请求 log::record('---------发送微信通知-完成订单-------'); log::record($full_url); $res = $this->curl_request($full_url, 'GET'); log::record('---------微信通知结果--------'); log::record($res); } return true; } private function getPushOpenId($exam_id) { $exams = DB::table("exams") ->alias('e') ->join('studies s', 'e.study_id = s.id') ->join('patient_infos pi', 'e.patient_id = pi.id') ->field('e.patient_id, s.accession_num, s.studyid, pi.temp_patient_id, pi.card_num, pi.phone') ->where('e.id', $exam_id) ->find(); if(!$exams) { return false; } $options = []; $accession_num = $exams['accession_num']; $studyid = $exams['studyid']; $patient_id = $exams['patient_id']; $temp_patient_id = $exams['temp_patient_id']; $card_num = $exams['card_num']; $phone = $exams['phone']; $sql1 = "select user_id as uid from user_bind where patient_id = ?"; $options[] = $patient_id; $sql2 = "select uid from wechat_bind where "; $sql2 .= "(patientCode = ?"; $options[] = $temp_patient_id; if(!empty($accession_num)) { $sql2 .= " or patientCode = ?"; $options[] = $accession_num; } if(!empty($studyid)) { $sql2 .= " or patientCode = ?"; $options[] = $studyid; } $sql2 .=")"; if($card_num) { $sql2 .= " or idcard = ?"; $options[] = $card_num; } if($card_num) { $sql2 .= " or phone = ?"; $options[] = $phone; } $sql = "select wx_openid as openid from user where id in (".$sql1." union ".$sql2.")"; log::record('---------微信推送sql--------'); log::record($sql); return Db::query($sql, $options); } private function curl_request($url,$method='get',$data=null,$https=true){ //1.初识化curl $ch = curl_init($url); //2.根据实际请求需求进行参数封装 //返回数据不直接输出 curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); //如果是https请求 if($https === true){ curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false); } //如果是post请求 if($method === 'post'){ //开启发送post请求选项 curl_setopt($ch,CURLOPT_POST,true); //发送post的数据 curl_setopt($ch,CURLOPT_POSTFIELDS,$data); } //3.发送请求 $result = curl_exec($ch); //4.返回返回值,关闭连接 curl_close($ch); return $result; } }