Use the php api to obtain weather forecasts and send them to friends.

Source: Internet
Author: User

The API obtains weather forecasts and sends text messages to friends using the Apsara API.
With the scheduled task, you can automatically send weather forecasts to yourself and your loved ones on a daily basis...

 

<? Php ########## jiam 2012/12/5 # 1113160783@qq.com # automatic sending of fetion # The intermediate part of the fetion interface # Weather Forecast API # And city code ######## ### 101180101 is the Zhengzhou city code #101180301 is the Xinxiang city code $ url = 'HTTP: // configure ($ url); $ weather = json_decode ($ w); $ weatherinfo = object_to_array ($ weather); $ info = $ weatherinfo ['weatherinfo']; $ str = $ info ['date _ y']. ','. $ info ['Week ']. '. '. $ Info ['city']. 'Today's temperature :'. $ info ['temp1']. ', weather :'. $ info ['Weather 1']. 'you '. $ info ['wind1 ']. ', wind power :'. $ info ['fx1 ']. ', recommended dressing :'. $ info ['index _ d']. $ info ['index48 _ d']; $ feixin = 'HTTP: // response $ send = curl ($ feixin, $ postArray); print_r ($ send ); Die (); function curl ($ url, $ postFields = null) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url ); curl_setopt ($ ch, CURLOPT_FAILONERROR, false); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true); // https request if (strlen ($ url)> 5 & strtolower (substr ($ url, 0,5) = "https") {curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, false);} if (is_array ($ postFields) & 0 <Count ($ postFields) {$ postBodyString = ""; $ postMultipart = false; foreach ($ postFields as $ k => $ v) {if ("@"! = Substr ($ v, 0, 1) // determines whether the file is uploaded {$ postBodyString. = "$ k = ". urlencode ($ v ). "&";} else // multipart/form-data for file upload; otherwise, www-form-urlencoded {$ postMultipart = true ;}} unset ($ k, $ v); curl_setopt ($ ch, CURLOPT_POST, true); if ($ postMultipart) {curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ postFields);} else {curl_setopt ($ ch, CURLOPT_POSTFIELDS, substr ($ postBodyString, 0,-1); }}$ reponse = curl_exec ($ ch); if (curl_errno ($ ch )) {Throw new Exception (curl_error ($ ch), 0);} else {$ httpStatusCode = curl_getinfo ($ ch, CURLINFO_HTTP_CODE); if (200! ==$ HttpStatusCode) {throw new Exception ($ reponse, $ httpStatusCode) ;}} curl_close ($ ch); return $ reponse;} function object_to_array ($ obj) {$ _ arr = is_object ($ obj )? Get_object_vars ($ obj): $ obj; foreach ($ _ arr as $ key => $ val) {$ val = (is_array ($ val) | is_object ($ val ))? Object_to_array ($ val): $ val; $ arr [$ key] = $ val;} return $ arr ;}?>

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.