bar.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. //设置utf-8格式,解决中文乱码
  3. header("Content-type: text/html; charset=utf-8");
  4. date_default_timezone_set("PRC");
  5. // $WorkerCode = 'hg001';
  6. // $WorkerName = '护工001';
  7. // $txm = '1232345634P';
  8. // $NurseConfirmCode = '192.1.1.21';
  9. $reqMsg = $_POST['reqMsg'];
  10. try{
  11. $url = "http://127.0.0.1:8082";
  12. $ret = curl_post($url,['data' => $reqMsg]);
  13. $json = json_decode($ret,true);
  14. if(!empty($json) && $json['success']){
  15. return_ok('成功',$json['data']);
  16. }else{
  17. return_wrong('请求失败');
  18. }
  19. }catch (Exception $e){
  20. return_wrong('请求失败'.$e->getMessage());
  21. }
  22. function curl_post($url, $data) {
  23. $ch = curl_init ();
  24. $header = array ("Accept-Charset: utf-8",'Expect:' );
  25. curl_setopt ( $ch, CURLOPT_URL, $url );
  26. curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
  27. curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
  28. curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
  29. curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
  30. curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)' );
  31. curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
  32. curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 );
  33. curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 );
  34. // 最好加上http_build_query 转换,防止有些服务器不兼容
  35. curl_setopt ( $ch, CURLOPT_POSTFIELDS, http_build_query ( $data ) );
  36. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
  37. $result = curl_exec ( $ch );
  38. curl_close ( $ch );
  39. return $result;
  40. }
  41. function xmltoarr($str){
  42. return json_decode(json_encode(simplexml_load_string($str, null, LIBXML_NOCDATA)),true);
  43. }
  44. function return_ok($msg = '成功',$data = ''){
  45. header('Content-Type:application/json; charset=utf-8');
  46. $result['status'] = 1;
  47. $result['msg'] = $msg ;
  48. $result['data'] = $data;
  49. exit(json_encode($result,JSON_UNESCAPED_UNICODE));
  50. }
  51. function return_wrong($msg = '失败'){
  52. header('Content-Type:application/json; charset=utf-8');
  53. $result['status'] = 0;
  54. $result['msg'] = $msg ;
  55. exit(json_encode($result,JSON_UNESCAPED_UNICODE));
  56. }
  57. ?>