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 ;}?>