2017-04-11 101 views
0

警報響應我想OT找出客場取得本網站的響應: https://www.primarycare.nhs.uk/publicfn/catchment.aspx?oc=P91012&h=600&w=800&if=0獲得來自外部網站

OC = P91012 - 這是慣例標識。

然後我們有一個郵政編碼場,其中用戶檢查,如果他們是在集水區

該網站發出JavaScript警告如果他們/或不在集水區通知用戶。

是否可以發送PHP Curl請求,向本網站發送郵政編碼並檢查郵政編碼是否位於集水區,並將回覆發送回我的網站?

<?php 
$POSTurl = 'https://www.primarycare.nhs.uk/publicfn/geocode.ashx'; 
$fields = array(
'postcode' => urlencode('M41 0UX'), 
); 

foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
rtrim($fields_string, '&'); 

$ch = curl_init(); 
curl_setopt($ch,CURLOPT_URL, $POSTurl); 
curl_setopt($ch,CURLOPT_POST, count($fields)); 
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); 
$result = curl_exec($ch); 



$url = 'https://www.primarycare.nhs.uk/publicfn/catchment.aspx?oc=P91012&h=600&w=800&if=0'; 
$ch = curl_init(); 
$result = curl_exec($ch); 


curl_close($ch); 

?> 
+0

,有你的嘗試? – hassan

+0

我有,我可以發送一個curl post請求到不同的oc代碼和郵政編碼的網站,但那是它結束了我,我不知道如何收到JavaScript警報。 – memaxt

+0

您的代碼返回''53.4519424438477; -2.3516891002655''。但是你想在alert中顯示相同的回報? – Tauras

回答

0

所以,在這裏,它是:

的問題,爲什麼你不是不能挑適當的反應是因爲所有有效座標是NHS的源代碼。我刪除了不需要的代碼,並通過郵編和列表中的現有座標檢查座標。請記住,如果原始數據源中的任何內容都將在列表中進行更改,則還需要進行更新。

此外,此代碼,技術上是不是100%正確並且可能你會花更多的時間使它更正確地滿足您的需求。正如我在評論中所說的那樣,這將起到一點作用。

只需複製/粘貼到您的PHP文件,並刷新頁面。

代碼: '?難道......'

<?php 
$postcode = 'M41 0UX'; 
$postcode = urlencode($postcode); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://www.primarycare.nhs.uk/publicfn/geocode.ashx"); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, "PostCode=".$postcode); 
curl_setopt($ch, CURLOPT_POST, 1); 
$result = curl_exec($ch); 
if (curl_errno($ch)) { 
echo 'Error:' . curl_error($ch); 
} 
else { 
echo $result; 
echo '<input id="checker" type="hidden" value="'.$result.'" />'; 
?> 
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> 
<script src="https://www.primarycare.nhs.uk/Private/js/gpos.js" type="text/javascript"></script> 
<script type="text/javascript" src="https://maps-api-ssl.google.com/maps/api/js?v=3.7&sensor=false"></script> 
<script type="text/javascript"> 
var point; 
var poly1=[{x:53.45801,y: -2.33768},{x:53.46046,y: -2.32996},{x:53.45882,y: -2.32447},{x:53.45637,y: -2.3188},{x:53.45351,y: -2.31709},{x:53.44932,y: -2.31468},{x:53.44523,y: -2.31365},{x:53.44216,y: -2.31279},{x:53.43961,y: -2.31417},{x:53.43858,y: -2.31657},{x:53.4394,y: -2.32155},{x:53.44001,y: -2.32893},{x:53.44145,y: -2.33408},{x:53.44329,y: -2.33751},{x:53.44053,y: -2.33648},{x:53.4395,y: -2.34095},{x:53.43838,y: -2.34352},{x:53.44083,y: -2.34627},{x:53.44022,y: -2.35107},{x:53.43899,y: -2.35193},{x:53.43787,y: -2.35107},{x:53.43797,y: -2.35399},{x:53.43715,y: -2.35622},{x:53.43562,y: -2.3576},{x:53.43592,y: -2.35949},{x:53.43449,y: -2.36103},{x:53.43275,y: -2.36017},{x:53.43153,y: -2.36137},{x:53.43275,y: -2.36343},{x:53.43183,y: -2.36515},{x:53.43347,y: -2.36738},{x:53.4349,y: -2.36704},{x:53.43664,y: -2.36738},{x:53.43736,y: -2.3679},{x:53.43705,y: -2.37167},{x:53.43725,y: -2.37459},{x:53.43592,y: -2.37511},{x:53.43664,y: -2.377},{x:53.43623,y: -2.37974},{x:53.43787,y: -2.38077},{x:53.43858,y: -2.37888},{x:53.4395,y: -2.3782},{x:53.43981,y: -2.38197},{x:53.4392,y: -2.38403},{x:53.43797,y: -2.38352},{x:53.43848,y: -2.38609},{x:53.4395,y: -2.38592},{x:53.44073,y: -2.3842},{x:53.44063,y: -2.38747},{x:53.44001,y: -2.3909},{x:53.43776,y: -2.39193},{x:53.43603,y: -2.39141},{x:53.4348,y: -2.38884},{x:53.43255,y: -2.39038},{x:53.43388,y: -2.39553},{x:53.43459,y: -2.39914},{x:53.43684,y: -2.40051},{x:53.43766,y: -2.40223},{x:53.4394,y: -2.4012},{x:53.44012,y: -2.40429},{x:53.4394,y: -2.40824},{x:53.43868,y: -2.41219},{x:53.44533,y: -2.40807},{x:53.4485,y: -2.40669},{x:53.4529,y: -2.40309},{x:53.45545,y: -2.39965},{x:53.45995,y: -2.39313},{x:53.46363,y: -2.38438},{x:53.46608,y: -2.37614},{x:53.46894,y: -2.3703},{x:53.46588,y: -2.36532},{x:53.46455,y: -2.35931},{x:53.46281,y: -2.35296},{x:53.46158,y: -2.3461},{x:53.45995,y: -2.34198},{x:53.4577,y: -2.33974}]; 

function isPointInPoly(poly, pt){ 
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) 
((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y)) 
&& (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y)/(poly[j].y - poly[i].y) + poly[i].x) 
&& (c = !c); 
return c; 
}; 

function ispostcodein(postcode) { 
var ok = 1; 
if (ok == 1) { 
var responseText = $('#checker').val(); 
point = responseText.split(';'); 
} 
var incatch = 0; 
if (isPointInPoly(poly1, {x: point[0],y: point[1]})) { incatch = 1 }; 
if (incatch==0) { 
alert("We're sorry, but your postcode is outside the catchment area for PRIMROSE AVENUE SURGERY."); 
} 
else { 
alert("Your postcode is in the catchment area for PRIMROSE AVENUE SURGERY. You are able to register with this practice."); 
}       
} 

ispostcodein('<?= $result; ?>'); 
</script> 
<?php 
} 
curl_close($ch); 
?> 
+0

你是上帝!這工作正如我想要的一樣!我稍微修改了它,因爲一些源代碼根據oc改變了...但是我不能夠感謝你了......再次感謝你花時間來幫助這個! – memaxt

+0

你也可以upvote:D祝你好運與你的代碼:) – Tauras