Php combined with Fetion free weather forecast text message _ PHP

Source: Internet
Author: User
I recently found an API of Apsara stack. to make good use of this resource, I made this weather forecast text message notification. Fetion

Start to teach you how to get it
1. a PHP environment is required. Download APMServ software to quickly build a PHP environment
2. download the weather forecast text message notification PHP program. Click here to download the code
3. modify the PHP program configuration
Use Notepad to open the WeatherForecast. php file
The code is as follows:
/**
* Apsara notification weather forecast
* 2009-4-23
*/

// Execution prohibition time limit
Set_time_limit (0 );

// Set the MB encoding
Mb_internal_encoding ("GB2312 ");

/**
* Collect Sina weather forecast information
*
* @ Param string $ city name
* @ Return unknown
*/
Function getWF ($ city ){

If (empty ($ city) return "";
$ Wf = @ file_get_contents ('http: // php.weather.sina.com.cn/search.php? City = '. urlencode ($ city).' & f = 1 & dpc = 1 ');
If (empty ($ wf )){
Return "";
}

// Intercept related information
$ Return = "";
$ Star = strpos ($ wf ,"

");
$ Return = substr ($ wf, $ star, 1000 );
$ End2 = strpos ($ return ," ");
$ Return = strip_tags (substr ($ return, 0, $ end2 ));


// Filter
$ Return = str_replace ("", "", $ return );
$ Return = str_replace ("", "", $ return );
$ Return = str_replace ("\ t", "", $ return );
$ Return = str_replace ("\ n", "", $ return );
$ Return = str_replace ("℃", "degree", $ return );
$ Return = str_replace ("≤", "", $ return );
$ Return = trim (str_replace ("\ r", $ return ),",");
$ Return = str_replace ("~ ","-", $ Return );
$ Return = str_replace (":", ":", $ return );

// Return value
Return $ return;
}

// Set The Apsara stack account
$ Fetion ['user'] = '';
$ Fetion ['pass'] = '';

// Set the weather forecast city
$ Citys [] = array ('id' => 'BJ ', 'name' => 'Beijing ');
$ Citys [] = array ('id' => 'sys', 'name' => 'Shenyang ');

// Beijing mobile phone number
$ Tel ['BJ '] [] = '137xxxxxxx ';
$ Tel ['BJ '] [] = '137xxxxxxx ';
// Shenyang mobile phone no.
$ Tel ['sy '] [] = '138xxxxxxxx ';
$ Tel ['sy '] [] = '137xxxxxxx ';


If (is_array ($ citys) & count ($ citys)> 0 ){

// Traverse the city
Foreach ($ citys as $ city ){

// Obtain the collection information
$ Info = getWF ($ city ['name']);

If (! Empty ($ info )){
If (is_array ($ tel [$ city ['id']) & count ($ tel [$ city ['id'])> 0 ){

// Process large amounts of information
If (mb_strlen ($ info)> 171 ){
$ Sum = ceil (mb_strlen ($ info)/168)-1;
For ($ I = 0; $ I <= $ sum; $ I ++ ){
$ Starj= 168 * $ I;
$ QInfo = mb_substr ($ info, $ starj, 168 );
$ N = $ I + 1;
Foreach ($ tel [$ city ['id'] as $ val ){
$ Url = "http://sms.api.bz/fetion.php? Username = ". $ Fetion ['user']. "& password = ". $ Fetion ['pass']. "& sendto = ". $ val. "& message = ". urlencode ("weather forecast [". $ n. "],". "Tomorrow ". date ("Y, m, d "). "". $ city ['name']. "". $ qInfo );
@ File_get_contents ($ url );
}
}
} Else {
Foreach ($ tel [$ city ['id'] as $ val ){
$ Url = "http://sms.api.bz/fetion.php? Username = ". $ Fetion ['user']. "& password = ". $ Fetion ['pass']. "& sendto = ". $ val. "& message = ". urlencode ("weather forecast, Tomorrow ". date ("Y, m, d "). "". $ city ['name']. "". $ info );
@ File_get_contents ($ url );
}
}
}
}
}
}
?>

Modify
The code is as follows:
// Set The Apsara stack account
$ Fetion ['user'] = 'mobile phone number of your Apsara stack account ';
$ Fetion ['pass'] = 'login to Fetion password ';

Modify your city
The code is as follows:
// Set the weather forecast city
$ Citys [] = array ('id' => 'BJ ', 'name' => 'Beijing ');

Modify the phone number for which you want to receive the weather forecast.
The code is as follows:
// Beijing mobile phone number
$ Tel ['BJ '] [] = '137xxxxxxx ';
$ Tel ['BJ '] [] = '137xxxxxxx ';

Bj here must be the same as bj in the city.
After the configuration is complete, you can test whether the weather forecast information can be received.
4. set daily scheduled sending
In WINDOWS, set the scheduled task
Start> Program> nearby> System Tools> schedule tasks
Add a task as Prompted. click "php.exe" in the execution program.
Select the location where you want to install APMServ. my local location is D: \ APMServ5.2.6 \ PHP \ php.exe WeatherForecast. php absolute path.
I am local D: \ APMServ5.2.6 \ PHP \ php.exe D: \ APMServ5.2.6 \ www \ htdocs \ WeatherForecast. php
Complete.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.