|
@@ -0,0 +1,127 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+class refill_proxy
|
|
|
+{
|
|
|
+ private $mKey;
|
|
|
+
|
|
|
+ public function __construct($key)
|
|
|
+ {
|
|
|
+ $this->mKey = $key;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function send($url,$params)
|
|
|
+ {
|
|
|
+ $body = $this->body($params);
|
|
|
+ $body .= "&key={$this->mKey}";
|
|
|
+ $params['sign'] = md5($body);
|
|
|
+
|
|
|
+ $resp = $this->http_request($url,$params,'POST');
|
|
|
+ if($resp === false) {
|
|
|
+ return [false,'网络错误'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $resp = json_decode($resp,true);
|
|
|
+ $code = $resp['code'];
|
|
|
+ if($resp['code'] == 200) {
|
|
|
+ return [$code,'success'];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return [$code,$resp['message']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function body($params)
|
|
|
+ {
|
|
|
+ ksort($params);
|
|
|
+ $body = "";
|
|
|
+ $i = 0;
|
|
|
+ foreach ($params as $k => $v)
|
|
|
+ {
|
|
|
+ if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
|
|
|
+ {
|
|
|
+ if ($i == 0) {
|
|
|
+ $body .= "{$k}" . "=" . urlencode($v);
|
|
|
+ } else {
|
|
|
+ $body .= "&" . "{$k}" . "=" . urlencode($v);
|
|
|
+ }
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $body;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function check_empty($value)
|
|
|
+ {
|
|
|
+ if (!isset($value))
|
|
|
+ return true;
|
|
|
+ if ($value === null)
|
|
|
+ return true;
|
|
|
+ if (trim($value) === "")
|
|
|
+ return true;
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function http_request($url, $params = array(), $method = 'GET', $multi = false, $extheaders = array())
|
|
|
+ {
|
|
|
+ if (!function_exists('curl_init')) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $method = strtoupper($method);
|
|
|
+ $ci = curl_init();
|
|
|
+ curl_setopt($ci, CURLOPT_USERAGENT, 'PHP-SDK OAuth2.0');
|
|
|
+ curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($ci, CURLOPT_HEADER, false);
|
|
|
+ curl_setopt($ci, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
|
|
+
|
|
|
+ $headers = (array) $extheaders;
|
|
|
+ switch ($method)
|
|
|
+ {
|
|
|
+ case 'POST':
|
|
|
+ curl_setopt($ci, CURLOPT_POST, TRUE);
|
|
|
+ if (!empty($params))
|
|
|
+ {
|
|
|
+ if ($multi)
|
|
|
+ {
|
|
|
+ foreach ($multi as $key => $file) {
|
|
|
+ $params[$key] = '@' . $file;
|
|
|
+ }
|
|
|
+ curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
|
|
|
+ $headers[] = 'Expect: ';
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ curl_setopt($ci, CURLOPT_POSTFIELDS, http_build_query($params));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'DELETE':
|
|
|
+ case 'GET':
|
|
|
+ if($method == 'DELETE') {
|
|
|
+ curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
|
|
+ }
|
|
|
+ if (!empty($params)) {
|
|
|
+ $url = $url . (strpos($url, '?') ? '&' : '?') . (is_array($params) ? http_build_query($params) : $params);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
|
|
|
+ curl_setopt($ci, CURLOPT_URL, $url);
|
|
|
+ if ($headers) {
|
|
|
+ curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
|
|
|
+ }
|
|
|
+
|
|
|
+ $response = curl_exec($ci);
|
|
|
+ if($response == false) {
|
|
|
+ $err = curl_error($ci);
|
|
|
+ Log::record("http_post_data err={$err}",Log::ERR);
|
|
|
+ }
|
|
|
+
|
|
|
+ curl_close($ci);
|
|
|
+
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+}
|