$open_id, 'order_id' => $order_id, 's_timestamp' => time(), 'call_back' => 'stjsby' ]; $this->setLog(self::TYPENAME.'量表测评地址 进入', $this->startTime, $postArr, 'debug'); $url = $this->_makeUrl($op, $task, $postArr, $ap, '1.1.0'); return $url; } public function jssdkGetMedia(string $media_id) { $this->setLog(self::TYPENAME.'获取微信语音文件 进入', $this->startTime(), ['media_id'=>$media_id], 'debug'); $op = 'core'; $task = 'jssdkGetMedia'; $url = 'http://wechat.qingerai.com/index.php'; $secret = 'a1f073170fa3e945365ba15746861e141'; $weid = '36'; $token = md5(md5($secret . $weid . $media_id)); $getArr = [ 'ap' => 'api', 'op' => $op, 'task' => $task, 'weid' => $weid, 'media_id' => $media_id, 'token' => $token ]; try { $client = new httpClient(); $res = $client->request('get', $url, ['query'=>$getArr]); $body = $res->getBody(); $data = (object)json_decode($body); $this->setLog(self::TYPENAME.'_curl 远程请求到的数据', $this->startTime, [$data]); if ($data->status === TRUE) { //获取到的微信语音地址 $wxMediaUrl = $data->datas->url; $this->setLog(self::TYPENAME.'_curl 微信语音下载的URL', $this->startTime, [$wxMediaUrl]); //将语音文件下载到本地并转为mav格式 $client = new httpClient(); $response = $client->get($wxMediaUrl); $body = $response->getBody(); $this->setLog(self::TYPENAME.'_curl 微信远程请求到的数据', $this->startTime, [$body]); $name = array_slice(explode('=', $wxMediaUrl), -1)[0]; $fileName = public_path() . '/storage/speex/' .$name.'.speex'; $outFileName = public_path() . '/storage/speex/out_' .$name.'.wav'; file_put_contents($fileName, $body); exec("speex2wav $fileName $outFileName"); return $this->response('out_' .$name.'.wav'); }else{ $this->error()->fail($data->message); } } catch (\Exception $e) { $this->setLog(self::TYPENAME.'_curl 远程请求失败', $this->startTime, [$e->getMessage()]); $this->error()->fail($e->getMessage()); } } public function hospMyOutModule(string $open_id) { $op = 'hosp'; $task = 'hospMyOutModule'; $postArr = [ 'open_id' => $open_id, 'start' => 0, 'count' => 10000 ]; $this->setLog(self::TYPENAME.'量表记录 进入', $this->startTime, $postArr, 'debug'); $url = $this->_makeUrl($op, $task, $postArr); $curlData = $this->_curl($url, $postArr); return $this->response($curlData); } public function orderSync(string $order_id, int $status, string $prepay_id, int $pay_money, string $pay_time, string $refund_id, string $refund_datetime, int $refund_money) { $op = 'hosp'; $task = 'orderSync'; $postArr = [ 'order_id' => $order_id, 'status' => $status, 'prepay_id' => $prepay_id, 'pay_money' => $pay_money, 'pay_time' => $pay_time, 'refund_id' => $refund_id, 'refund_datetime' => $refund_datetime, 'refund_money' => $refund_money ]; $this->setLog(self::TYPENAME.'门诊付费同步 进入', $this->startTime, $postArr, 'debug'); $url = $this->_makeUrl($op, $task, $postArr); $curlData = $this->_curl($url, $postArr); return $this->response($curlData); } public function orderSelect(string $openId, int $payStatus = 0, int $orderType = 0) { $op = 'hosp'; $task = 'orderSelect'; $postArr = [ 'open_id' => $openId, 'pay_status' => $payStatus, 'order_type' => $orderType, 'start' => 0, 'count' => 10000 ]; $this->setLog(self::TYPENAME.'查询指定患者门诊缴费情况 进入', $this->startTime, $postArr, 'debug'); $url = $this->_makeUrl($op, $task, $postArr); $curlData = $this->_curl($url, $postArr); return $this->response($curlData); } public function moduleList(int $start, int $count, string $keyword='',string $mid='') { $op = 'module'; $task = 'moduleList'; $postArr = [ 'start' => $start, 'count' => $count, 'keyword' => $keyword, 'mid' => $mid ]; $this->setLog(self::TYPENAME.'获取量表列表 进入', $this->startTime, $postArr, 'debug'); $url = $this->_makeUrl($op, $task, $postArr); $curlData = $this->_curl($url, $postArr); return $this->response($curlData); } public function uploadFile(string $open_id, $filename, int $file_type) { $op = 'hosp'; $task = 'uploadFile'; $file = fopen($filename, 'r'); $postArr = [ 'file_type' => $file_type, 'open_id' => $open_id ]; $postArr2 = [ [ 'name' => 'file_path', 'contents' => $file ], [ 'name' => 'file_type', 'contents' => $file_type ], [ 'name' => 'open_id', 'contents' => $open_id ], ]; $url = $this->_makeUrl($op, $task, $postArr); $curlData = $this->_curl($url, $postArr2, 'multipart'); $curlData->res = true; return $curlData; } public function outCancel(string $apply_open_id) { $op = 'hosp'; $task = 'outCancel'; $postArr = [ 'apply_open_id' => $apply_open_id, ]; $this->setLog(self::TYPENAME.'取消未付款预约 进入', $this->startTime, $postArr, 'debug'); $url = $this->_makeUrl($op, $task, $postArr); $curlData = $this->_curl($url, $postArr); return $this->response($curlData); } public function outConfirm(string $apply_open_id, string $visit_card_no, string $prepay_id, int $pay_money, string $pay_time) { $op = 'hosp'; $task = 'outConfirm'; $postArr = [ 'apply_open_id' => $apply_open_id, 'visit_card_no' => $visit_card_no, 'prepay_id' => $prepay_id, 'pay_money' => $pay_money, 'pay_time' => $pay_time ]; $this->setLog(self::TYPENAME.'门诊确认预约/已付款 进入', $this->startTime, $postArr, 'debug'); $url = $this->_makeUrl($op, $task, $postArr); $curlData = $this->_curl($url, $postArr); return $this->response($curlData); } public function outApply(string $open_id, string $work_open_id, int $time_select) { $op = 'hosp'; $task = 'outApply'; $postArr = [ 'open_id' => $open_id, 'work_open_id' => $work_open_id, 'time_select' => $time_select ]; $this->setLog(self::TYPENAME.'门诊预约锁号 进入', $this->startTime, $postArr, 'debug'); $url = $this->_makeUrl($op, $task, $postArr); $curlData = $this->_curl($url, $postArr); return $this->response($curlData); } public function hospWork(string $dockor_open_id, string $work_date_start, string $work_date_end) { $op = 'hosp'; $task = 'hospWork'; $postArr = [ 'dockor_open_id' => $dockor_open_id, 'work_date_start' => $work_date_start, 'work_date_end' => $work_date_end ]; $this->setLog(self::TYPENAME.'排班信息获取 进入', $this->startTime, $postArr, 'debug'); $url = $this->_makeUrl($op, $task, $postArr); $curlData = $this->_curl($url, $postArr); return $this->response($curlData); } public function hospWorkSave(string $day) { $op = 'hosp'; $task = 'hospWorkSave'; $status = self::STATUS_2; //排班日期 $registerDate = $day; //取出需要更新排除的医生 $fields = ['doctors.id','doctors.third_openid','doctors.third_type','doctors.his_employeecode','his_deptcode','third_section_open_id']; $doctors = Doctor::leftJoin('sections','sections.id','doctors.sectionId1')->where('third_type',1)->get($fields); //医生排班日期 $doctorVisitieData = ['week'=>$registerDate,'is_visit'=>$status]; //医生排班时间段 $doctorVisityExtendData = [ ['title'=>'09:00-10:00', 'quantity'=>0,'end_time'=>$registerDate.' 09:00:00'], ['title'=>'10:30-11:30', 'quantity'=>0,'end_time'=>$registerDate.' 10:30:00'], ['title'=>'14:30-15:30', 'quantity'=>0,'end_time'=>$registerDate.' 14:30:00'], ['title'=>'16:30-17:30', 'quantity'=>0,'end_time'=>$registerDate.' 16:30:00'] ]; //组合杨总数据 $postArr = [ 'doctor_open_id' => 0, 'work_date' => $registerDate, 'work_is_ol' => 2, // 门诊类型 1线下 2线上 'work_ol_type' => 2, // 诊间模式 1 医护模式 2纯医模式 'day_type' => 1, // 时间划分 1上午 2下午 'status' => $status, // 诊间状态 1正常 2停诊 'is_type' => 2, // 排班方式 1 顺序模式 2固定时间 'order_start_datetime' => '', 'order_estimate_time' => 60, //每个患者预估时间 'order_max_num' => 2, // 'rest_time_start' => '11:30:59', // 'rest_time_end' => '14:29:59' ]; foreach ($doctors as $doctor){ //一天两条,上午一条和下午一条 $postArrs = [ $postArr, $postArr ]; //加入医生id $doctorVisitieData['doctorId'] = $doctor->id; $doctorVisityExtendData[0]['doctor_id'] = $doctor->id; $doctorVisityExtendData[1]['doctor_id'] = $doctor->id; $doctorVisityExtendData[2]['doctor_id'] = $doctor->id; $doctorVisityExtendData[3]['doctor_id'] = $doctor->id; $postArrs[0]['doctor_open_id'] = $doctor->third_openid; $postArrs[1]['doctor_open_id'] = $doctor->third_openid; //从HIS获取排班数据 $hisDatas = HisApiFacade::useableNumQuery($registerDate, $doctor->his_deptcode, $doctor->his_employeecode); if ($hisDatas->getData()->code == self::SUCCESS_CODE && $hisDatas->getData()->data) { $hisDatas = $hisDatas->getData()->data; }elseif ($hisDatas->getData()->code == self::SUCCESS_CODE && $hisDatas->getData()->data == null){ $this->setLog(self::TYPENAME.'从HIS获取到的排班信息为空', $this->startTime,['doctorid'=>$doctor->id,'registerDate'=>$registerDate],'error'); continue; // $this->error()->dataDoesNotExist('从HIS获取到的排班信息为空'); } foreach ($hisDatas as $hisData){ if ($hisData->workTimeName == '上午班' && $hisData->useableNum > 0) { //有数据表示医生坐诊 $status = self::STATUS_1; $doctorVisityExtendData[0]['quantity'] = 1; $doctorVisityExtendData[1]['quantity'] = 1; $doctorVisityExtendData[0]['his_worktime_code'] = $hisData->workTimeCode; $doctorVisityExtendData[1]['his_worktime_code'] = $hisData->workTimeCode; $doctorVisityExtendData[0]['his_fee'] = $hisData->numFee; $doctorVisityExtendData[1]['his_fee'] = $hisData->numFee; $postArrs[0]['day_type'] = self::DAY_TYPE_1; $postArrs[0]['status'] = self::STATUS_1; // $postArrs[0]['order_start_datetime'] = '09:00'; $postArrs[0]['fixed_json'] = '[{"start_time":"09:00:00","end_time":"09:59:59"},{"start_time":"10:30:00","end_time":"11:29:59"}]'; }elseif ($hisData->workTimeName == '下午班' && $hisData->useableNum > 0) { //有数据表示医生坐诊 $status = self::STATUS_1; $doctorVisityExtendData[2]['quantity'] = 1; $doctorVisityExtendData[3]['quantity'] = 1; $doctorVisityExtendData[2]['his_worktime_code'] = $hisData->workTimeCode; $doctorVisityExtendData[3]['his_worktime_code'] = $hisData->workTimeCode; $doctorVisityExtendData[2]['his_fee'] = $hisData->numFee; $doctorVisityExtendData[3]['his_fee'] = $hisData->numFee; $postArrs[1]['day_type'] = self::DAY_TYPE_2; $postArrs[1]['status'] = self::STATUS_1; // $postArrs[1]['order_start_datetime'] = '14:30'; $postArrs[1]['fixed_json'] = '[{"start_time":"14:30:00","end_time":"15:29:59"},{"start_time":"16:30:00","end_time":"17:29:59"}]'; } } //重新给医生赋值坐诊状态 $doctorVisitieData['is_visit'] = $status; $doctorVisity = DoctorVisity::create($doctorVisitieData); foreach ($postArrs as $postKey=>$post){ if (!isset($post['fixed_json'])) { continue; } $this->setLog(self::TYPENAME.'创建排班 进入', $this->startTime, $post, 'debug'); $url = $this->_makeUrl($op, $task, $post); $thirdData = $this->_curl($url, $post); if ($thirdData) { foreach ($doctorVisityExtendData as $key=>$extend){ $extend['third_work_open_id'] = $thirdData->work_open_id; $extend['doctor_visity_id'] = $doctorVisity->id; if ($postKey===0 && $key<2) { $extend['third_work_index'] = $key; DoctorVisityExtend::create($extend); } if ($postKey===1 && $key>=2) { $extend['third_work_index'] = $key-2; DoctorVisityExtend::create($extend); } } } } } } public function customerCreate(string $open_id, string $id_card, string $name, int $sex, int $marry_type, int $age, string $contact, $wechat_uid, $face_path='') { $op = 'customer'; $task = 'customerCreate'; $postArr = [ 'open_id' => $open_id, 'name' => $name, 'sex' => $sex, 'marry_type' => $marry_type, 'age' => $age, 'contact' => $contact, 'wechat_uid' => $wechat_uid, 'face_path' => '' ]; $this->setLog(self::TYPENAME.'创建患者 进入', $this->startTime, $postArr, 'debug'); $url = $this->_makeUrl($op, $task, $postArr); $url = $this->_makeUrl($op, $task, $postArr); $curlType = 'form_params'; if($face_path == true){ $curlType = 'multipart'; $file = fopen($face_path, 'r'); $postArr = [['name'=>'open_id','contents'=>$open_id],['name'=>'name','contents'=>$name],['name'=>'sex','contents'=>$sex],['name'=>'marry_type','contents'=>$marry_type],['name'=>'age','contents'=>$age],['name'=>'contact','contents'=>$contact],['name'=>'wechat_uid','contents'=>$wechat_uid]]; } $curlData = $this->_curl($url, $postArr, $curlType); return $this->response($curlData); } public function getDoctor(array $postArr) { $op = 'hosp'; $task = 'doctor'; $url = $this->_makeUrl($op, $task, $postArr); $datas = $this->_curl($url, $postArr); return $this->response($datas); } public function getDepartment(array $postArr) { $op = 'hosp'; $task = 'department'; $url = $this->_makeUrl($op, $task, $postArr); $datas = $this->_curl($url, $postArr); return $this->response($datas); } /** * 请求接口 * * @param string $url 请求地址 * @param array $postArr 请求参数 * @param string $paramType 请求类型 form_params multipart * @return array */ private function _curl(string $url, array $postArr, string $paramType = 'form_params') { $this->setLog(self::TYPENAME.'_curl 进入', $this->startTime(), ['url'=>$url, 'postArr'=>$postArr]); try { $client = new httpClient(); $res = $client->request('post', $url, [$paramType=>$postArr]); $body = $res->getBody(); $data = (object)json_decode($body); $this->setLog(self::TYPENAME.'_curl 远程请求到的数据', $this->startTime, [$data]); if ($data->status === TRUE && $data->code == 9000) { return $data->data; }else{ $this->error()->fail($data->message); } } catch (\Exception $e) { $this->setLog(self::TYPENAME.'_curl 远程请求失败', $this->startTime, [$e->getMessage()]); $this->error()->fail($e->getMessage()); } } private function _makeUrl(string $op, string $task, array $postArr, string $ap='', string $version='1.0.0') { self::setLog(self::TYPENAME.'加密 进入'); //按键排序 ksort($postArr); //取出值并拼接字符串 $postStr = implode('', array_values($postArr)); $appId = config('console.third_consult.appid'); //按规则拼接加密字符串 APPID + op + task + 接口版本号 + post数据按键排序连接字符串 + 秘钥 $signStr = $appId.$op.$task.$version.$postStr.config('console.third_consult.secret'); $md5Sign = md5($signStr); self::setLog(self::TYPENAME.'加密得到字符串',$this->startTime,['拼接后的字符串'=>$signStr,'md5后结果'=>$md5Sign]); $querys = [ 'op=' . $op, 'task=' . $task, 'version=' . $version, 'appid=' . urlencode($appId), 'sign=' . $md5Sign ]; //在线咨询的地址 $url = config('console.third_consult.url'); if ($ap != '') { //在线测评的地址 $url = config('console.third_consult.scale_url'); $querys[] = 'ap='.$ap; $querys[] = 'open_id='.urlencode($postArr['open_id']); $querys[] = 'order_id='.urlencode($postArr['order_id']); $querys[] = 's_timestamp='.$postArr['s_timestamp']; $querys[] = 'call_back='.$postArr['call_back']; } return $url.'?'.implode('&', array_values($querys)); } }