diff --git a/app/Controller/CallBackController.php b/app/Controller/CallBackController.php index f5fb591..f2aaf4f 100644 --- a/app/Controller/CallBackController.php +++ b/app/Controller/CallBackController.php @@ -532,6 +532,7 @@ class CallBackController extends AbstractController // 发送短信消息 + // 告知处方平台 return $server->serve(); } diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index c4e6691..08c147f 100644 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -14,6 +14,7 @@ use App\Services\UserDoctorService; use App\Services\UserService; use App\Utils\Http; use App\Utils\Log; +use Extend\Prescription\Prescription; use Extend\TencentIm\Account; use Extend\TencentIm\Friend; use Extend\TencentIm\Group; @@ -104,25 +105,25 @@ class UserController extends AbstractController // return $this->response->json($pay_config); // 发起退款 - $WechatPay = new WechatPay(1,2); - - $params = array(); - $params['order_inquiry_id'] = 1; - $order_inquiry = OrderInquiry::getOne($params); - - - $options = array(); - $options['transaction_id'] = "4200001756202303145016495897"; - $options['out_refund_no'] = "123456"; - $options['reason'] = "退款原因"; - $options['amount'] = [ - 'refund' => (int)1, - 'total' => (int)1, - 'currency' => "CNY", - ]; - - $result = $WechatPay->refund($options); - dump($result); +// $WechatPay = new WechatPay(1,2); +// +// $params = array(); +// $params['order_inquiry_id'] = 1; +// $order_inquiry = OrderInquiry::getOne($params); +// +// +// $options = array(); +// $options['transaction_id'] = "4200001756202303145016495897"; +// $options['out_refund_no'] = "123456"; +// $options['reason'] = "退款原因"; +// $options['amount'] = [ +// 'refund' => (int)1, +// 'total' => (int)1, +// 'currency' => "CNY", +// ]; +// +// $result = $WechatPay->refund($options); +// dump($result); // 创建账号 $account = new Account(); @@ -234,5 +235,9 @@ class UserController extends AbstractController // return fail(HttpEnumCode::HTTP_ERROR, $res); // } + // 对接处方平台 + $Prescription = new Prescription(); + $token = $Prescription->getProd(); + dump($token); } } \ No newline at end of file diff --git a/app/Request/PatientFamilyRequest.php b/app/Request/PatientFamilyRequest.php index a796a30..2654d2a 100644 --- a/app/Request/PatientFamilyRequest.php +++ b/app/Request/PatientFamilyRequest.php @@ -106,7 +106,7 @@ class PatientFamilyRequest extends FormRequest 'card_name' => 'required', 'type' => ['required',Rule::in(['1', '2', '3', '4'])], 'id_number' => "required", - 'mobile' => ['required','regex:/^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/'], + 'mobile' => ['sometimes','regex:/^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/'], 'relation' => ['required',Rule::in(['1', '2', '3', '4', '5', '6'])], 'city_id' => 'required_with:province_id', 'province_id' => 'required_with:city_id,county_id', @@ -137,7 +137,7 @@ class PatientFamilyRequest extends FormRequest 'type.required' => "请选择证件类型", 'type.in' => "证件类型错误", 'id_number.required' => "请选择证件号", - 'mobile.required' => "手机号不能为空", +// 'mobile.required' => "手机号不能为空", 'mobile.regex' => "手机号格式错误", 'relation.required' => "请选择患者关系", 'relation.in' => "患者关系错误", diff --git a/extend/Prescription/Prescription.php b/extend/Prescription/Prescription.php new file mode 100644 index 0000000..13a0013 --- /dev/null +++ b/extend/Prescription/Prescription.php @@ -0,0 +1,165 @@ +api_url = "http://49.233.3.200:6304/api/thridapi/"; + $this->client_id = "ZD-004"; + $this->client_secret = "0baa5927164710b9f800bf33546b6da3"; + $this->container = ApplicationContext::getContainer(); + } + + /** + * 获取token接口 + * @return string token数据 + */ + protected function getToken(): string + { + $option = [ + "json" => array( + "clientId" => $this->client_id, + "clientSecret" => $this->client_secret, + ) + ]; + + try { + $response = $this->httpRequest($this->api_url . $this->version . '/user_thrid/token', $option); + + if (empty($response['result'])){ + // 返回值为空 + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } + + if (empty($response['result']['token'])){ + // 返回值为空 + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } + + } catch (GuzzleException $e) { + throw new BusinessException($e->getMessage()); + } + + $this->header = [ + "Authorization" => "Bearer " . $response['result']['token'] + ]; + + $this->redis->set("prescription_token",$response['result']['token'],60 * 60 * 1.5); + return $response['result']['token']; + } + + // 获取药品 + public function getProd(){ + $option = [ + "json" => array( + "page" => 1, + "pageSize" => 1, + ), + ]; + + try { + $response = $this->httpRequest($this->api_url . $this->version . '/drug/syncDrugCatalogue', $option); + if (empty($response['result'])){ + // 返回值为空 + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } + + if (empty($response['result']['rows'])){ + return true; + } + dump($response); + // 获取总数 +// $count + } catch (GuzzleException $e) { + throw new BusinessException($e->getMessage()); + } + +// return $response['token']; + } + + + /** + * 请求封装 + * @param string $path + * @param array $option + * @return array + * @throws GuzzleException + */ + protected function httpRequest(string $path,array $arg = []): array + { + if ($path != "http://49.233.3.200:6304/api/thridapi/v1/drug/syncDrugCatalogue"){ + $this->redis = $this->container->get(Redis::class); + + $access_token = $this->redis->get("prescription_token"); + if (empty($access_token)){ + $access_token = $this->getToken(); + } + } + + if (!empty($access_token)){ + $option = [ + "headers" => [ + "Authorization" => "Bearer " . $access_token + ] + ]; + } + if (!empty($option)){ + $arg = array_merge($arg,$option); + } + + + dump($arg); + + $response = $this->client->post($path, $arg); + + if ($response->getStatusCode() != '200'){ + // 请求失败 + throw new BusinessException($response->getBody()->getContents()); + } + + $body = json_decode($response->getBody(),true); + if (empty($body)){ + // 返回值为空 + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } + dump($body); + + if (empty($body['data'])){ + // 返回值为空 + if (!empty($body['message'])){ + throw new BusinessException($body['message']); + } + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } + + return $body['data']; + } +} \ No newline at end of file