Exemple #1
0
        return true;
    }
    return false;
}
$method = $_SERVER['REQUEST_METHOD'];
$data = array();
if ($method == "GET") {
    $data = $_GET;
} elseif ($method == "POST") {
    $data = $_POST;
} else {
    error_log(FormatLogStr('gm', 'magic.php', ERROR_0, 'invalidate request method : ' . $method));
    die('false');
}
if (empty($data['sign'])) {
    //没有发现签名数据
    error_log(FormatLogStr('gm', 'magic.php', ERROR_0, 'not found sign param with param ' . json_encode($data)));
    die('false');
}
//得到请求中的sign
$sign = $data['sign'];
//去除sign字段
unset($data['sign']);
//得到请求参数
$str = getDataStr($data);
if (verify($str, $sign, $pubKey)) {
    echo https_get($gmaddr . '?' . $str);
} else {
    error_log(FormatLogStr('gm', 'magic.php', ERROR_0, 'verify sign failed with param ' . $str . " with sign : {$sign}"));
    echo 'false';
}
Exemple #2
0
        array_push($query_string, $key . '=' . $val);
    }
    $query_string = join('&', $query_string);
    return $query_string;
}
function https_get($url, $timeout = 10)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_HEADER, 0);
    // 不要http header 加快效率
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    // https请求 不验证证书和hosts
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
// $uri = 'gmtype=adddiamond&uin=10050&value=20';
$uri = array('gmtype' => 'adddiamond', 'uin' => 10000014, 'value' => 20);
$str = getDataStr($uri);
$uri['sign'] = urlencode(getSign($str, $priKey));
//必需urlencode
$str = getDataStr($uri);
$url = 'http://10.10.2.39/gm/magic.php?' . $str;
echo "url is {$url}\n";
echo https_get($url);