/*
Simulate resource push class
2012-09-14 by POOY
*/
Class TuisongPost {
// Construct login authentication
Function TuisongPost (){
// The file that stores the COOKIE
Global $ cookie_jar;
$ This-> cookie_jar = tempnam ('./tmp', 'cooker ');
$ Url = "http: // www. Your address ";
$ Post_data = array ("username" => "admin", "password" => "admin ");
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 0 );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_data );
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ this-> cookie_jar); // save cookie Information
$ Output1 = curl_exec ($ ch );
Curl_close ($ ch );
// Echo $ this-> cookie_jar. "n ";
}
/* Get the group ID */
Function getGid ($ groupname, $ channel, $ lanmu ){
$ Url = "http://XXXX.com/creategroup ";
// Format the data to be pushed
$ Data = $ this-> getGidArr ($ groupname, $ channel, $ lanmu );
$ Ch = curl_init ();
$ Ref_url = "http: // www. Your address ";
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_REFERER, $ Ref_url); // disguise REFERER
Curl_setopt ($ ch, CURLOPT_POST, 1); // submit data in post Mode
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // return data instead of directly outputting
Curl_setopt ($ ch, CURLOPT_HEADER, 0); // you can specify whether to display the header information. 0 indicates that the header information is not displayed. 1 indicates that the default value is 0.
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ this-> cookie_jar); // send the cookie file
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); // send POST data
$ Output2 = curl_exec ($ ch); // send an HTTP request
// The returned value is used as the basis for judgment.
Return $ output2;
Curl_close ($ ch );
// $ This-> unlink ($ this-> cookie_jar );
}
// Push data
Function sendPic ($ note, $ groupid, $ groupindex, $ img ){
$ Url = "http: // XXXX/addimage ";
$ Groupid = intval ($ groupid );
$ Data = $ this-> sendPicArr ($ note, $ groupid, $ groupindex, $ img );
$ Ch = curl_init ();
$ Ref_url = "http: // www. Your address ";
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_REFERER, $ Ref_url); // disguise REFERER
Curl_setopt ($ ch, CURLOPT_POST, 1); // submit data in post Mode
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // return data instead of directly outputting
Curl_setopt ($ ch, CURLOPT_HEADER, 0); // you can specify whether to display the header information. 0 indicates that the header information is not displayed. 1 indicates that the default value is 0.
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ this-> cookie_jar); // send the cookie file
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); // send POST data
$ Output2 = curl_exec ($ ch); // send an HTTP request
Return $ output2;
Curl_close ($ ch );
// $ This-> unlink ($ this-> cookie_jar );
}
/* Push data operation */
Function sendMes ($ url, $ img, $ imgdesc, $ groupid, $ groupname, $ channel, $ lanmu)
{
// Var_dump ($ this-> cookie_jar );
// Exit ();
$ Url = "http: // XXXX/add ";
$ Data = $ this-> getArr ($ img, $ imgdesc, $ groupid, $ groupname, $ channel, $ lanmu );
$ Ch = curl_init ();
$ Ref_url = "http: // www. Your address ";
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_REFERER, $ Ref_url); // disguise REFERER
Curl_setopt ($ ch, CURLOPT_POST, 1); // submit data in post Mode
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // return data instead of directly outputting
Curl_setopt ($ ch, CURLOPT_HEADER, 0); // you can specify whether to display the header information. 0 indicates that the header information is not displayed. 1 indicates that the default value is 0.
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ this-> cookie_jar); // send the cookie file
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); // send POST data
$ Output2 = curl_exec ($ ch); // send an HTTP request
Curl_close ($ ch );
// $ This-> unlink ($ this-> cookie_jar );
}
Function getArr ($ img, $ imgdesc, $ groupid, $ groupname, $ channel, $ lanmu)
{
$ Post_data = array (
// Use the following statement in windows. linux is not applicable.
// "Img" => "@". $ img. "; type = image/jpeg ",
"Img" => "@". $ img,
"Imgdesc" => $ imgdesc,
"Groupid" => $ groupid,
"Groupname" => $ groupname,
"Channel" => $ channel,
"Lanmu" => $ lanmu,
"Cdate" => date ('Y-m-d ')
);
Return $ post_data;
}
// Format getGidArr
Function getGidArr ($ groupname, $ channel, $ lanmu)
{
$ Post_data = array (
"Groupname" => $ groupname,
"Channel" => $ channel,
"Lanmu" => $ lanmu,
"Cdate" => date ('Y-m-d ')
);
Return $ post_data;
}
// Format sendPicArr
Function sendPicArr ($ note, $ groupid, $ groupindex, $ img)
{
$ Post_data = array (
"Notes" => $ note,
"Id" => $ groupid,
"Index" => $ groupindex,
"Cdate" => date ('Y-m-d '),
// Use the following statement in windows. linux is not applicable.
// "Img" => "@". $ img. "; type = image/jpeg ",
"Img" => "@". $ img
);
Return $ post_data;
}
// Clear cookie files
Function unlink ($ cookie_jar ){
Unlink ($ cookie_jar );
}
} |