| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1625 人关注过本帖
标题:飞行发送短信
取消只看楼主 加入收藏
sweet6hero
Rank: 1
等 级:新手上路
帖 子:87
专家分:0
注 册:2013-6-9
结帖率:40%
收藏
 问题点数:0 回复次数:1 
飞行发送短信
# -*- coding:utf-8 -*-
import sys  
import httplib  
import urllib  
import re  
import time
import json
url = "https://quanapi.   
class Fetion:
    def __init__(self,toTel,msg,fromTel = 'you number',pwd = 'you fei xin pwd'):         
        self.fromTel = fromTel         
        self.pwd = pwd         
        self.toTel = toTel         
        self.msg = self.Trans(msg)
    def Trans(self, msg):         
        # change space to '%20', otherwise error raised         
        return re.sub(" ", "%20", str(msg))
    def format_url(self):
        url_address = url+self.fromTel+ "&p=" + self.pwd\
            + "&to=" + self.toTel + "&m=" + self.msg         
        return url_address
    def SendMsg(self):         
        # call the api by http get method
        return urllib.urlopen(self.format_url())
def msg2log(msg):      
    logfile = open('MyFetion.log', 'a')      
    now = time.strftime('%Y%m%d %H:%M:%S')      
    logfile.write('\n'+ now + '\n' + msg + '\n')      
    logfile.close()

def main():      
    # format mutual message      
    print "\n" + " "*10 + "*"*60      
    print " "*10 + " Personal Fetion"     
    print " "*10 + " Enter the number and message what you want to send to."     
    print " "*10 + " blank number means yourself,"     
    print " "*10 + " and a blank message line to exit."     
    print " "*10 + "*"*60      
    # get the destination phone number
    toTel = raw_input("Input the target telphone number:")  
    if toTel == "":  
        toTel = "151xxxxxxxx"  # none input for a target most used
    # get the message and send by Fetion class      
    while True:
        msg = raw_input("Message:")
        if msg == "":              
            break  # none input to quit         
        else:
            print "Sending...."            
            msg2log(msg)              
            ff = Fetion(toTel, msg)              
            answer = ff.SendMsg()              
            data = answer.read()              
            jdata=json.loads(data)
            if jdata['result']==0:                  
                print 'Done.^_^\n'            
            else:                  
                print 'Fail.-_=\n'
if __name__ == '__main__':      
    main()                        
搜索更多相关主题的帖子: otherwise change Fetion number import 
2013-11-15 14:03
sweet6hero
Rank: 1
等 级:新手上路
帖 子:87
专家分:0
注 册:2013-6-9
收藏
得分:0 
package test;

import

import org.
import org.
import org.
import org.
import org.

public class Fetion {

    public void sendMsg(String _phone, String _pwd, String _to, String _msg)
            throws HttpException, IOException {
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod("http://3.ibtf.);
        post.addRequestHeader("Content-Type",
                "application/x-www-form-urlencoded;charset=utf-8");// 在头文件中设置转码
        
        NameValuePair[] data = { new NameValuePair("phone", _phone),
                new NameValuePair("pwd", _pwd), new NameValuePair("to", _to),
                new NameValuePair("msg", _msg), new NameValuePair("type", "0") };
        post.setRequestBody(data);

        client.executeMethod(post);
        Header[] headers = post.getResponseHeaders();
        int statusCode = post.getStatusCode();
        System.out.println("statusCode:" + statusCode);
        for (Header h : headers) {
            System.out.println(h.toString());
        }
        // String result = new
        // String(post.getResponseBodyAsString().getBytes("utf-8"));
        // System.out.println(result);
        System.out.println("ok!");
        post.releaseConnection();
    }

}
2013-11-15 15:42
快速回复:飞行发送短信
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017706 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved