捐赠页面iframe的php代码, 我自己写(缝合)的:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Donations</title>
<link rel="icon" href="./favicon.ico" type="image/x-icon">
<style type="text/css">
p {overflow:hidden;
text-overflow:ellipsis;
white-space:nowrap;
font-size: 12px;
}
table {table-layout: fixed;
width: 950px;
left:50%;
border-spacing: 0px 10px;
}
body {justify-content: center;
display: flex;
}
img {
border-radius:50%;
left:7px;
position: relative;
}
</style>
</head>
<?php
function getByPage($pagenum,$perpage){
$user_id = "你自己的userid";
$params = json_encode(['page' => $pagenum, 'per_page' => $perpage]);
$ts = time();
$token = '你自己的爱发电开发者token';
$sign = md5(join("",array($token,'params',$params,'ts',$ts,'user_id',$user_id)));
$data = json_encode(["user_id" => $user_id, "params" => $params, "ts" => $ts, "sign" => $sign]);
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/json' . 'Content-Length: ' . strlen($data) . '\r\n', 'content' => $data));
$context = stream_context_create($opts);
$html = file_get_contents('https://afdian.net/api/open/query-sponsor', false, $context);
return $html;
}
$html = json_decode(getByPage(1,24),true);
#echo $html;
$list_temp = $html;
$count = $list_temp['data']['total_count'];
$pagestoask = intval($count/24)+1;
for ($j=1;$j<$pagestoask;$j++){
${'html'.$j} = json_decode(getByPage($j+1,24),true);
$html = array_merge_recursive($html,${'html'.$j});
}
$list = $html;
#echo json_encode($html);
function cmp($a, $b)
{
if ($a == $b) {
return 0;
}
return ($a < $b) ? 1 : -1;
}
foreach ($list['data']['list'] as $m => $n){
$purctime[$m]['oritime'] = $n['last_pay_time'];
$purctime[$m]['oriid'] = $m;
}
usort($purctime,'cmp');
foreach ($purctime as $key => $value) {
#echo "\$purctime[$key]['oritime']: " . $value['oritime'] . "<br>";
#echo "\$purctime[$key]['oriid']: " . $value['oriid'] . "<br>";
$list['data']['list'][$value['oriid']]['align_id_edge'] = $key;
#echo $list['data']['list'][$value['oriid']]['align_id_edge'];
}
#echo $list;
#echo $count;
echo "<table border='0' cellspacing='0'><tr>";
foreach ($list['data']['list'] as $k => $v){
$list2[$v['align_id_edge']] = $v;
}
#echo json_encode($list2);
for ($i=0;$i<24 && $i<$count;$i++){
$m = $i;
$n = $list2[$m];
#echo $m;
${"tbline".$m} = "";
if (!($m%8)){
echo "</tr><tr>";
}
${"all".$m} = $n;
#echo $k . "\n";
#echo json_encode(${"all".$k}["user"]) . "\n";
${"id".$m} = json_encode(${"all".$m}["user"]["user_id"]);
${"name".$m} = str_replace("爱发电用户_","",trim(json_encode(${"all".$m}["user"]["name"], JSON_UNESCAPED_UNICODE),'\"'));
${"avatar".$m} = json_encode(${"all".$m}["user"]["avatar"]);
echo "<td><img src=${"avatar".$m} height='75px' width='75px' ></img>\n<p align=center>${"name".$m}</p></td>";
}
echo "</tr>";
#$name = $list['data']['list'][1]['user'];
#echo json_encode($name);
?>
我的代码会从接口拉取全部捐赠者, 并按最后捐赠时间重新排序. 官方没有做这个功能, 属于是脑血栓中的脑血栓.
翻页懒得做了, 毕竟没谁会想翻页看这个. 链接也是同理, 自己写并不难.
我写的很多地方很冗杂或者怪异, 属于是能跑就行的典范. 最好别学我.
应该只适用于爱发电, 但是改改接口也能干别的. 看你自己的需要了.