学习自alipay
- function gateway($url, $time_out="60") {
- $urlinfo = parse_url($url);
- $errno = "";
- $errstr = "";
- $transports = "";
- if ($urlinfo['scheme'] == "https") {
- $transports = "ssl://";
- $urlinfo['port'] = "443";
- }else{
- $transports = "tcp://";
- $urlinfo['port'] = "80";
- }
-
- $fp = @fsockopen($transports.$urlinfo['host'], $urlinfo['port'], $errno, $errstr, $time_out);
- if (!$fp) {
- die("ERROR: $errno - $errstr
n");
- }else{
- fputs($fp, "POST ".$urlinfo['path']." HTTP/1.1rn");
- fputs($fp, "Host: ".$urlinfo['host']."rn");
- fputs($fp, "Content-type: application/x-www-form-urlencodedrn");
- fputs($fp, "Content-length: ".strlen($urlinfo['query'])."rn");
- fputs($fp, "Connection: closernrn");
- fputs($fp, $urlinfo['query']."rnrn");
- while(!feof($fp)) {
- $info[]=@fgets($fp, 1024);
- }
- fclose($fp);
- $info = implode(",", $info);
-
- var_dump($info);
- }
- }
复制代码
|