使用飞信

ZSP 包装接口

张沈鹏 <[email protected]>
reply-to        [email protected]
to      [email protected]
date    Sun, Dec 28, 2008 at 09:05
subject [CPyUG:75167] Re: 关于Python应用飞信

我只封装我需要的两个函数,你可以照着样子接着封装

sms.cpp ::

#include "libfetion/libfetion.h"
#include <boost/python.hpp>
#include <boost/foreach.hpp>
#include <string>
using std::string;
using namespace boost;
using namespace boost::python;
#define foreach BOOST_FOREACH
using namespace std;
BOOST_PYTHON_MODULE(sms)
{
    fx_init();
        def("login",fs_login);
        def("send",fs_send_sms_by_mobile_no);
}

sms.py ::

#python 
#coding:utf-8
import sms
print sms.login("用户名", "密码")
print sms.send("手机号码","is张沈鹏")

CMake.txt

cmake_minimum_required(VERSION 2.6)

#项目名称
PROJECT (zsp)

#头文件路径
INCLUDE_DIRECTORIES(
.
/usr/include/python/
)

LINK_DIRECTORIES(
.
)

#表示cpp文件列表的变量,如${DIRA_SRCS}代表src/dira目录下的所有源文件
AUX_SOURCE_DIRECTORY(. src)

#定义宏,多个用空格隔开
ADD_DEFINITIONS(
    -DNDEBUG
    #-std=c++0x
    -O3
    -march=i686
)

SET(EXECUTABLE_OUTPUT_PATH ./bin)
SET(LIBRARY_OUTPUT_PATH .)

#添加可执行文件生成任务
#ADD_EXECUTABLE(sms.exe ${src})
ADD_LIBRARY(pylib SHARED ${src})
#添加链接库
TARGET_LINK_LIBRARIES(pylib pthread curl fetion_32 boost_python)


反馈

创建 by -- ZoomQuiet [2008-12-28 02:56:01]

Name Password4deL ;) :( X-( B-)

PageCommentData