``` <?php // APP-KEY 与 密钥 $api_key = 'XXXXXXXX'; $secret_key = 'XXXXXXXXXX'; // 计算签名 $timestamp = time(); $sign = apiGenerateSignature($timestamp, $api_key, $secret_key ); // 公用必备参数 $pub_sign = [ 'api_key' => $api_key, 'timestamp' => $timestamp, 'sign' => $sign, ]; // 这里是接口,例如 新增链接接口 $api = 'http://api.fof.ink/urls/add'; $real_url = "https://www.umeng.com/"; // 接口必需参数 $post_data = []; $post_data['real_url'] = $real_url; // 将签名相关公用参数 与 接口参数组合 $data = array_merge($post_data, $pub_sign); $res = https_request( $api, $data ); // 返回数据 echo $res; exit; /** * 抓https数据 * * @param unknown $url * @param string $data * @param string $timeout */ function https_request($url, $data = null, $timeout = 20) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (! empty($data)) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } if ($timeout) { curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); if ($output === false) { my_log('Curl error: ' . curl_error($curl).". url:".$url); } curl_close($curl); return $output; } /** * [apiGenerateSignature 生成签名] * @param [type] $timestamp [时间戳] * @param [type] $api_key [api_key] * @param [type] $secret_key [secret_key] * @return [type] [sign签名字段] */ function apiGenerateSignature($timestamp, $api_key, $secret_key ) { $token = $secret_key; $tmpArr = array($token, $timestamp, $api_key); sort($tmpArr, SORT_STRING); $tmpStr = implode( $tmpArr ); $signature = sha1( $tmpStr ); return $signature; } ```