Today's tutorial is to teach you how to send free text messages to your girlfriend .
Send SMS interface , There are two common platforms I know , One is twilio, Free SMS 500 strip , Can send any information , One is Tencent cloud , Free SMS 100 strip , Need to apply for SMS content template .
Whereas twilio More free times , therefore , This time, we will twilio To send the weather information of the day to my parents .
To send a text message , We need now twilio Register an account on the official website .
https://www.twilio.com/
Click on Sign Up Create an account .
Fill in email, password and other information , After submission, there will be a verification to determine whether it is a robot , Click the left and right arrows to display the pattern as a positive picture .
Then go to the email just filled in to verify , Need to fill in mobile number verification .
Just started to use the mobile number to send two times without receiving the verification code , I don't know why , After changing the telecommunication, we received the verification code .
After successful verification, you will be prompted to choose whether to call through code .
choice yes Then select the corresponding language , Of course, we choose Python 了 .
After use , You can get a trial number , Click on Get a Trial Number Button .
We can see the number that the system gave me .
Click OK and a successful page will appear , Show Twilio Number provided , This number is used to send text messages .
Automatically jump back to the home page after obtaining the number successfully , There is Python Example of calling SMS interface .
After entering the interface call description , We see that on the right, directly from Python Example of calling interface to send SMS .
We can use it directly , In the code accountsid and authtoken Replace with your own , The two values are shown on the page where the number is just shown .
And then message Medium body Change to your own text , Change the number of the message sent to the number just provided by the official .
Receiving number before use , Need to be in Twilio Up and down , Click on the right verified numbers Get into , Add number .
Because it's free , So only one number is supported , If you have a verification number before , We need to click on the right X Delete this number to add a new number .
After clicking the button of verification number , On the pop-up page, select the text you instead, That is to use SMS verification code to verify the newly added number , You want to send it to your girlfriend , Of course , The receiving numbers are all for my girlfriend .
After filling in the number , Click verify , Wait for the verification code .
I tried the mobile numbers 、 Unicom No 、 Electrical signals , It is found that the electric signal and the Unicom card can receive the verification code normally and pass the verification , The mobile number has been sent several times and can't receive the verification code , The card has a balance , Maybe the mobile card does not support this interface , You can try .
Before running code , Don't forget to twilio Library use pip Command installation .
pip install twilio
Then replace several values in the code with your own .
Add the successful number to the code , Run code , The message will be sent after success .
Then we send out the weather information by SMS , Of course, you can send other messages . Here I use the previous weather information .
In the previous code, wechat is removed , Weather interface part reserved .
Put them in key Change to your own , Replace the message sent just now with the information returned by the weather interface msg, The timing operation code is the same as before .
The effect of running the code is as follows :
Again , I still put the program on the server , The next day at the same time will continue to send the weather information of the day , I set the gap 24 Hours , Of course , You can change the time between .