-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATingPush.class.php
164 lines (153 loc) · 4.96 KB
/
ATingPush.class.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/***************************************************************************
*
* Copyright (c) 2012 Baidu.com, Inc. All Rights Reserved
*
**************************************************************************/
/**
* @file ATingPush.class.php
* @brief 推送类
* @author sunhuai([email protected])
* @version
* @date 2012-12-3 13:28:22
*/
class ATingPush extends ATingExt {
protected $_logFile = NULL;
public $_logDir = NUll;
public $_logPath = NULL;
protected $pushUrl = 'http://10.40.71.98:8001/mmsg/r';//线下地址
public function init() {
$this->_logDir = ROOT_PATH.'/data/ting/appLog/';
if (!TingExtUtil::createDir($this->_logDir)) {
exit("dir error");
}
if ($this->_logFile) {
$this->_logPath = $this->_logDir . $this->_logFile;
}
else {
exit('log file coult not empty');
}
}
public function request($url, $data = array(), $method = 'POST', $isHttps = TRUE, $cookie = NULL) {
//return json_encode(array('error_no'=>1));
$ch = curl_init();
$curlOptions = array(
CURLOPT_URL => $url,
CURLOPT_CONNECTTIMEOUT => 1,
CURLOPT_TIMEOUT => 1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => 'ting',
);
$curlOptionsLog = array(
'CURLOPT_URL' => $url,
'CURLOPT_CONNECTTIMEOUT' => 1,
'CURLOPT_TIMEOUT' => 1,
'CURLOPT_RETURNTRANSFER' => true,
'CURLOPT_HEADER' => false,
'CURLOPT_FOLLOWLOCATION' => true,
'CURLOPT_USERAGENT' => 'ting',
);
if('POST' === $method)
{
$curlOptions[CURLOPT_POST] = true;
$curlOptions[CURLOPT_POSTFIELDS] = http_build_query($data);
}
if(true === $isHttps)
{
$curlOptions[CURLOPT_SSL_VERIFYPEER] = false;
}
if(isset($cookie))
{
$curlOptions[CURLOPT_COOKIE] = $cookie;
}
curl_setopt_array($ch, $curlOptions);
$response = curl_exec($ch);
$errno = curl_errno($ch);
$this->writeLog('send status', $opt = array('curlOptions' => $curlOptionsLog, 'response' => $response, 'errno' => $errno));
if(0 != $errno)
{
return FALSE;
}
curl_close($ch);
return $response;
}
//为百度音乐app服务的格式化$ext 目前包含ipad的
public function getFormatExt($type, $ext) {
$extContent = array();
$extContent['type'] = $type;
switch($type) {
case 1 :
$extContent['songid'] = $ext;//歌曲
break;
case 2 :
$extContent['album_id'] = $ext;//专辑
break;
case 3 :
$extContent['code'] = $ext;//Ting精选
break;
case 4 :
$extContent['code'] = 'ten';
break;
case 5 :
$extContent['billlist_id'] = $ext;//榜单
break;
case 6 :
$extContent['artist_id'] = $ext;//歌手
break;
case 7 :
//春节活动 无实体
break;
default :
exit();
break;
}
return json_encode($extContent);
}
//为艺人app服务的格式化$ext
public function getAppFormatExt($appid, $type, $ext) {
$extContent = array();
$extContent['appid'] = $appid;
$extContent['type'] = $type;
switch($type) {
case 1 :
$extContent['song_id'] = $ext;//歌曲
break;
case 2 :
$extContent['album_id'] = $ext;//专辑
break;
case 3 :
$extContent['news_id'] = $ext;//资讯
break;
case 4 :
//$extContent[''] = $ext;//专辑
break;
case 5 :
$extContent['post_id'] = $ext;//帖子
break;
case 6 :
$extContent['video_id'] = $ext;//视频
break;
default :
exit();
break;
}
return json_encode($extContent);
}
public function writeLog($words,$opt = array()) {
$words .= '|||' . date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']);
$words .= '|||' . json_encode($opt);
$words .= "\r\n";
return file_put_contents($this->_logPath, $words, FILE_APPEND);
}
public function checkLen($ext, $content) {
$checkResult = array();
$checkResult['check'] = TRUE;
$checkResult['len'] = strlen($ext . json_encode($content));
if ($checkResult['len'] > 400) {
$checkResult['check'] = FALSE;
}
return $checkResult;
}
}