Use PHP to send timed messages free of charge

Source: Internet
Author: User
Tags config documentation error code mail php script

Use PHP to send timed messages free of charge

Background: Mom is old, not highly educated, but need to know the weather information every day to work in the fields, and can not get the weather through the network, only through television. So I thought about crawling the weather information on the Internet and sending it to my mother by SMS.

Problem: It is not possible to send the weather message to my mother every day, the existing weather forecast to subscribe to SMS is Money.

Solve:

Send SMS to mobile phone for free

Scenario 1: Using the fly-through API

Because there is no development platform, the existing APIs are Third-party development, seemingly by cracking WAP flying or 3G flying, simulate the behavior of the browser to send text messages. In addition, Google Code has open source PHP fly Letter Send class Php-fetion (http://code.google.com/p/php-fetion/). These fly-through interface facilitates the development of timed SMS.

The only drawback is that the Third-party API is not stable, but also the risk of flying letter account leakage.

Here, I use http://3.ibtf.sinaapp.com/provided by the Flying Letter API to send text messages. The station itself hangs on the Sina SAE, the source code can be found in the http://www.oschina.net/code/snippet_202258_9754 (inside provide download address).

The API simply provides the sender's cell phone number, the password, the recipient's cell phone number, and the message content as a URL parameter. The only attention is the Chinese garbled problem (using GBK instead of UTF-8 encoding, direct input Chinese garbled, input Chinese GBK code phone to receive normal), you can use the Iconv function or add parameters "&u=1" to solve.

For example: Invoke the Free API

http://2.ibtf.sinaapp.com/?phone= mobile phone number &pwd= Fly letter password &to= receive mobile phone number (must be flying friends or their own mobile phone number) &msg= message content &u=1 (solve garbled problem)

Option 2: Use the SMS alert function of 139 mailboxes

139 mailbox is also a mobile business in China, providing the function of email message reminder. As long as the mail in the mailbox to set up the arrival of the notification OK, in addition to MMS, other letters, ordinary text messages, hands-free text messages are available. Note that time is long, the Outbox and Inbox should be cleared, so as not to occupy too much space and affect the normal use.

In addition, you only need to write a Simple mail-sent PHP script. And the Sina SAE also provides this mail service. Using the functions in mail service, you can quickly send mail with the following code:

    1. 		<?php
    2. $mail = new Saemail ();
    3. $ret = $mail->quicksend (
    4. ' Recipient @139.com ',
    5. ' This is the theme ',
    6. ' This is the text ',
    7. ' This is the sender's mailbox ',
    8. ' This is the sender's password ',
    9. ' This is the SMTP Service host ',
    10. [This is the Smpt service port]);
    11. Output error code and error message when sending fails
    12. if ($ret = = False)
    13. Var_dump ($mail->errno (), $mail->errmsg ());
    14. ?>

Please refer to the Mail Service API documentation http://apidoc.sinaapp.com/sae/SaeMail.html for more information.

The effect is as follows:

Timed Send function

After the message is sent successfully, it needs to be timed. Fortunately, the Sina SAE provides a cron service. The cron service is a distributed, timed service provided by the SAE for developers to periodically trigger specific actions of the developer to meet the needs of such as the timing list. Cron settings are implemented through the app's Config.yaml, and as long as the user is configured in the Config.yaml in the app directory according to our provided syntax format, it will take effect after deployment.

Example: detailed tutorial Reference API documentation http://sae.sina.com.cn/?m=devcenter&catId=195

Add cron

    1. 		Edit Saetest/1/config.yaml, add cron segments, Config.yaml examples are as follows:
    2. Name:saetest
    3. Version:1
    4. Cron:
    5. -Description:cron Test
    6. url:mycron/test.php
    7. Schedule: $ Day of October 19:00
    8. Timezone:beijing
    9. -Description:another cron Test
    10. url:mycron/another_test.php
    11. Schedule:every mins
    12. Timezone:beijing

The above example describes two timed tasks: mycron/test.php every October 2 19 o'clock, performing mycron/another_test.php every 10 minutes

PHP Weather Crawl

There are many places on the Internet to provide weather information, such as Sina, China Weather Network, there are also relevant APIs and open source code. This is more simple than to elaborate. Of course, the above mentioned the letter of the API site http://3.ibtf.sinaapp.com/The source code also has about the weather to crawl, you can learn from.

Implementation of the effect diagram



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.