-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommon.php
65 lines (59 loc) · 1.75 KB
/
Common.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* Typecho 插件 CommentReminder 附属类
*
* @author Wis Chu
* @link https://wischu.com/
*/
class CommentReminder_Common extends Typecho_Widget
{
/**
* 对邮件头字符串进行 base64 编码
* *
* @access public
* @return string
*/
protected function encodeStr($str){
return '=?UTF-8?B?' . base64_encode(str_replace(array("\r", "\n"), '', $str)) . '?=';
}
/**
* 获取 token 目录内文件路径
* *
* @access public
* @return mix [string|boolean]
*/
protected function getTokenPath($prefix)
{
$tokenDir = dirname(__FILE__) .'/token';
$dir = scandir($tokenDir);
foreach($dir as $val){
if(stripos($val, $prefix) === 0){
return $tokenDir .'/'. $val;
}
}
return false;
}
/**
* POST 方法
* *
* @access public
* @return mix [string|boolean]
*/
protected function post_request($remote_server, array $post_array)
{
$post_string = http_build_query($post_array);
$context = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded; charset=UTF-8'. '\r\n'.
'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36'. '\r\n'.
'Content-length:'. strlen($post_string),
'content' => $post_string,
),
);
$stream_context = stream_context_create($context);
$data = @file_get_contents($remote_server, false, $stream_context);
return $data;
}
}