用java对短信猫进行二次开发。用短信猫发短信时,手机能收到 短信,但是出现乱码。如果输入的为英文的则没有问题!这样怎么解决 。。

解决方案 »

  1.   

    我指定编码了。但还是乱码
    我贴下我发送时的代码
    jnative = new JNative("SMSDLL.dll", "SMSSendMessage");// 声明库名和调用的启动服务的方法名
    int i = 0;
    // 传入方法参数
    jnative.setParameter(i++,new String(smsContent.getBytes(),"UTF-8"));// 短信内容
    jnative.setParameter(i++, telNum);// 收件人号码 jnative.invoke();// 执行程序
    System.out.println("发送成功!");
      

  2.   

    最好在容器里通一设置,或在Elipse设置,或加过滤器。当然页面也要设成一置的。
      

  3.   

    没用过smsdll,搜索了半天都没搜索手册什么的.帮不了你了
      

  4.   

    UTF-8不行就换GB2312或GBK试试。
      

  5.   


     这个是人家给的使用说明1对外接口函数说明
    一,启动服务int _stdcall SMSStartService(int nPort,DWORD BaudRate = 57600, int Parity=2, int DataBits = 8,int StopBits=0,int FlowControl=0,char* csca="card") 参数:nPort 串口号 如1 则表示COM1
    BaudRate 拨特率 115200  
    Parity 校验位 2 
    DataBits 数据位 8
    StopBits停止位 0
    FlowControl 流控制 0
    Csca 短信中心号码,可以使用默认值,若设置则格式如:” +8613800591500”   返回值:1成功,0失败二, 发送短消息DWORD _stdcall SMSSendMessage(char* Msg,char* PhoneNo) 参数:Msg消息内容,如果为中文则一条最多70个字,多于70个字分多条短信发送
               如果全为英文则一条最多为140个字符,多余于140则分多条发送
          PhoneNo 目标号码 格式如“13800591500”
     返回值无意义,查询短信成功与否请调用函数四三, 接收短消息int _stdcall SMSGetNextMessage(SMSMessageStruct* Msg) 结构体类如下
    typedef struct _sms_msg_t_
    {
    char Msg[256];          //短信内容
    char    PhoneNo[32];       //对方手机号码
    char    ReceTime[32];      //接收时间
    } SMSMessageStruct;参数 Msg读取的短消息
    返回 1有短信 0无
    四, 查询发送状态报告 int _stdcall SMSReport(SMSReportStruct* rept)五, 停止服务int _stdcall SMSStopSerice() 六, 最近一次错误 int _stdcall SMSGetLastError(char* err)参数 err为错误内容
    返回错误长度2调用方法以及用例
    2.1.1 声明
    //消息结构体 类型声明
    typedef struct _sms_msg_t_
    {
    char Msg[256];     //短信内容
    char    PhoneNo[32];   //对方手机号码
    char    ReceTime[32];      //接收时间
    } SMSMessageStruct;//消息状态报告结构体 类型声明
    typedef struct _sms_report_t_
    {
    DWORD index;          //短消息编号:index,从0开始递增
    char Msg[256];     //短信内容
    int Success;      //是否发送成功 0为失败,非0为成功
    char    PhoneNo[32];   //目标手机号码
    } SMSReportStruct;//启动服务函数类型说明
    typedef int (_stdcall *pSMSStartServiceFun)(int nPort,DWORD BaudRate = 57600, int Parity=2, int DataBits = 8,int StopBits=0,int FlowControl=0,char* csca="card");
    //读取短信函数类型说明
     typedef int (_stdcall *pSMSGetNextMessageFun)(SMSMessageStruct* Msg);
     //发送消息类型说明
    typedef DWORD (_stdcall *pSMSSendMessageFun)(char* Msg,char* PhoneNo);
    //读取状态报告类型说明
    typedef int (_stdcall *pSMSReportFun)(SMSReportStruct* rept);
    //停止服务函数类型说明
    typedef int (_stdcall *pSMSStopSericeFun)();
    2.1.2调用过程
    HINSTANCE hDll = LoadLibrary("MC8331AT.dll"); //调用程序目录下须要有此动态库文件
    pSMSSendMessageFun SMSSendMessageFun; //函数定义
    SMSSendMessageFun = (pSMSSendMessageFun)GetProcAddress(hDll, "SMSSendMessage");
    //获取函数指针
    If(SMSSendMessageFun != NULL)
    SMSSendMessageFun(“短信内容”, “手机号码”);
    //发送短信
    FreeLibrary(hDll); //释放动态库
    3备注
    1, SMSStartService 和SMSStopSerice 应该配对出现,在程序退出之前一定要释放资源
    2, SMSGetNextMessage 这个需要一个定时器和线程来管理。如果短信多了而不调用此函数,新的短信会覆盖以前的未读取短信下面是带的一个类
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;import org.xvolks.jnative.JNative;
    import org.xvolks.jnative.Type;
    import org.xvolks.jnative.exceptions.NativeException;
    import org.xvolks.jnative.misc.basicStructures.AbstractBasicData;
    import org.xvolks.jnative.pointers.Pointer;
    import org.xvolks.jnative.pointers.memory.GlobalMemoryBlock;
    import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;public class Jnative {
    public static void main(String[] args) throws NoSuchMethodException { JNative n = null;
    try {
    n = new JNative("SMSDLL.dll", "SMSStartService");// 给出库名方法名 n.setRetVal(Type.INT); // 设定返回类型
    int i = 0; n.setParameter(i++, 1);// 传入方法参数
    n.setParameter(i++, 115200);
    n.setParameter(i++, 2);
    n.setParameter(i++, 8);
    n.setParameter(i++, 0);
    n.setParameter(i++, 0);
    n.setParameter(i++, "card"); n.invoke(); // 执行程序 String res = n.getRetVal();// 得到返回结果 System.out.println(res);
    n = new JNative("SMSDLL.dll", "SMSGetNextMessage");
    n.setRetVal(Type.INT); // 设定返回类型// public class Individual extends AbstractBasicData<Individual>{
    // public char[] Msg = new char[256];    
    // public char[] PhoneNo = new char[32];  
    // public char[] ReceTime = new char[32];
    // }
    // public Pointer createPointer(){
    //
    // }
     i=0;
    // Individual in = new Individual();
    Pointer pTar = new Pointer(MemoryBlockFactory.createMemoryBlock(320));
    //Pointer pTar1 =pTar.createPointer(256);
    n.setParameter(0, pTar);
    while(true){
    n.invoke();
    String res11 = n.getRetVal();
    if(Integer.parseInt(res11)==1){
    System.out.println("接受到短心了");
    //System.out.println(""+pTar);
    System.out.println(pTar.getAsString());
    //StringBuffer bb= new StringBuffer();
    List temp = new ArrayList();
    for(int k=256;k<256+32;k++){
    if(pTar.getAsByte(k) != 0){
    temp.add(pTar.getAsByte(k));
    }
    }
    char[] dest = new char[temp.size()];
     for(int k=256;k<256+temp.size();k++){
    System.out.println(pTar.getAsByte(k));
    //bb.append(pTar.getAsByte(k));

    dest[k-256]=(char)pTar.getAsByte(k);
     }
     String st = new String(dest);
    //String str=Arrays.toString(dest);
     System.out.println(st);

     
     
     List temp1 = new ArrayList();
    for(int k=256+32;k<256+32+32;k++){
    if(pTar.getAsByte(k) != 0){
    temp1.add(pTar.getAsByte(k));
    }
    }
    char[] dest1 = new char[temp1.size()];
     
     for(int k=256+32;k<256+32+32;k++){
    if(pTar.getAsByte(k) != 0){
    dest1[k-256-32]=(char)pTar.getAsByte(k);
    }
    }
     String st1 = new String(dest1);
     System.out.println(st1);
    //System.out.println(pTar1.getAsString());
    //System.out.println(pTar.createPointer(256).getAsString());
    //pTar.createPointerToNativeMemory(pTar., 32);

    }
    }

    } catch (Exception e1) { e1.printStackTrace();
    } finally {
    if (n != null) {
    try {
    n.dispose();// 释放资源
    } catch (NativeException e) { e.printStackTrace();
    } catch (IllegalAccessException e) { e.printStackTrace();
    }
    }
    } }}还有一个动态库,就这么多
      

  6.   


     这个是人家给的使用说明1对外接口函数说明
    一,启动服务int _stdcall SMSStartService(int nPort,DWORD BaudRate = 57600, int Parity=2, int DataBits = 8,int StopBits=0,int FlowControl=0,char* csca="card")  参数:nPort 串口号 如1 则表示COM1
    BaudRate 拨特率 115200   
    Parity 校验位 2  
    DataBits 数据位 8
    StopBits停止位 0
    FlowControl 流控制 0
    Csca 短信中心号码,可以使用默认值,若设置则格式如:” +8613800591500”  返回值:1成功,0失败二, 发送短消息DWORD _stdcall SMSSendMessage(char* Msg,char* PhoneNo)  参数:Msg消息内容,如果为中文则一条最多70个字,多于70个字分多条短信发送
      如果全为英文则一条最多为140个字符,多余于140则分多条发送
      PhoneNo 目标号码 格式如“13800591500”
     返回值无意义,查询短信成功与否请调用函数四三, 接收短消息int _stdcall SMSGetNextMessage(SMSMessageStruct* Msg)  结构体类如下
    typedef struct _sms_msg_t_
    {
    char Msg[256]; //短信内容
    char PhoneNo[32]; //对方手机号码
    char ReceTime[32]; //接收时间
    } SMSMessageStruct;参数 Msg读取的短消息
    返回 1有短信 0无
    四, 查询发送状态报告 int _stdcall SMSReport(SMSReportStruct* rept)五, 停止服务int _stdcall SMSStopSerice()  六, 最近一次错误 int _stdcall SMSGetLastError(char* err)参数 err为错误内容
    返回错误长度2调用方法以及用例
    2.1.1 声明
    //消息结构体 类型声明
    typedef struct _sms_msg_t_
    {
    char Msg[256]; //短信内容
    char PhoneNo[32]; //对方手机号码
    char ReceTime[32]; //接收时间
    } SMSMessageStruct;//消息状态报告结构体 类型声明
    typedef struct _sms_report_t_
    {
    DWORD index; //短消息编号:index,从0开始递增
    char Msg[256]; //短信内容
    int Success; //是否发送成功 0为失败,非0为成功
    char PhoneNo[32]; //目标手机号码
    } SMSReportStruct;//启动服务函数类型说明
    typedef int (_stdcall *pSMSStartServiceFun)(int nPort,DWORD BaudRate = 57600, int Parity=2, int DataBits = 8,int StopBits=0,int FlowControl=0,char* csca="card");
    //读取短信函数类型说明
     typedef int (_stdcall *pSMSGetNextMessageFun)(SMSMessageStruct* Msg);
     //发送消息类型说明
    typedef DWORD (_stdcall *pSMSSendMessageFun)(char* Msg,char* PhoneNo);
    //读取状态报告类型说明
    typedef int (_stdcall *pSMSReportFun)(SMSReportStruct* rept);
    //停止服务函数类型说明
    typedef int (_stdcall *pSMSStopSericeFun)();
    2.1.2调用过程
    HINSTANCE hDll = LoadLibrary("MC8331AT.dll"); //调用程序目录下须要有此动态库文件
    pSMSSendMessageFun SMSSendMessageFun; //函数定义
    SMSSendMessageFun = (pSMSSendMessageFun)GetProcAddress(hDll, "SMSSendMessage");
    //获取函数指针
    If(SMSSendMessageFun != NULL)
    SMSSendMessageFun(“短信内容”, “手机号码”);
    //发送短信
    FreeLibrary(hDll); //释放动态库
    3备注
    1, SMSStartService 和SMSStopSerice 应该配对出现,在程序退出之前一定要释放资源
    2, SMSGetNextMessage 这个需要一个定时器和线程来管理。如果短信多了而不调用此函数,新的短信会覆盖以前的未读取短信下面是带的一个类
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;import org.xvolks.jnative.JNative;
    import org.xvolks.jnative.Type;
    import org.xvolks.jnative.exceptions.NativeException;
    import org.xvolks.jnative.misc.basicStructures.AbstractBasicData;
    import org.xvolks.jnative.pointers.Pointer;
    import org.xvolks.jnative.pointers.memory.GlobalMemoryBlock;
    import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;public class Jnative {
    public static void main(String[] args) throws NoSuchMethodException {JNative n = null;
    try {
    n = new JNative("SMSDLL.dll", "SMSStartService");// 给出库名方法名n.setRetVal(Type.INT); // 设定返回类型
    int i = 0;n.setParameter(i++, 1);// 传入方法参数
    n.setParameter(i++, 115200);
    n.setParameter(i++, 2);
    n.setParameter(i++, 8);
    n.setParameter(i++, 0);
    n.setParameter(i++, 0);
    n.setParameter(i++, "card");n.invoke(); // 执行程序String res = n.getRetVal();// 得到返回结果System.out.println(res);
    n = new JNative("SMSDLL.dll", "SMSGetNextMessage");
    n.setRetVal(Type.INT); // 设定返回类型// public class Individual extends AbstractBasicData<Individual>{
    // public char[] Msg = new char[256];   
    // public char[] PhoneNo = new char[32];   
    // public char[] ReceTime = new char[32];
    // }
    // public Pointer createPointer(){
    // 
    // }
    i=0;
    // Individual in = new Individual();
    Pointer pTar = new Pointer(MemoryBlockFactory.createMemoryBlock(320));
    //Pointer pTar1 =pTar.createPointer(256);
    n.setParameter(0, pTar);
    while(true){
    n.invoke();
    String res11 = n.getRetVal();
    if(Integer.parseInt(res11)==1){
    System.out.println("接受到短心了");
    //System.out.println(""+pTar);
    System.out.println(pTar.getAsString());
    //StringBuffer bb= new StringBuffer();
    List temp = new ArrayList();
    for(int k=256;k<256+32;k++){
    if(pTar.getAsByte(k) != 0){
    temp.add(pTar.getAsByte(k));
    }
    }
    char[] dest = new char[temp.size()];
    for(int k=256;k<256+temp.size();k++){
    System.out.println(pTar.getAsByte(k));
    //bb.append(pTar.getAsByte(k));dest[k-256]=(char)pTar.getAsByte(k);
    }
    String st = new String(dest);
    //String str=Arrays.toString(dest);
    System.out.println(st);  
      
    List temp1 = new ArrayList();
    for(int k=256+32;k<256+32+32;k++){
    if(pTar.getAsByte(k) != 0){
    temp1.add(pTar.getAsByte(k));
    }
    }
    char[] dest1 = new char[temp1.size()];
      
    for(int k=256+32;k<256+32+32;k++){
    if(pTar.getAsByte(k) != 0){
    dest1[k-256-32]=(char)pTar.getAsByte(k);
    }
    }
    String st1 = new String(dest1);
    System.out.println(st1);
    //System.out.println(pTar1.getAsString());
    //System.out.println(pTar.createPointer(256).getAsString());
    //pTar.createPointerToNativeMemory(pTar., 32);}
    }} catch (Exception e1) {e1.printStackTrace();
    }finally {
    if (n != null) {
    try {
    n.dispose();// 释放资源
    } catch (NativeException e) {e.printStackTrace();
    } catch (IllegalAccessException e) {e.printStackTrace();
    }
    }
    }}}还有一个动态库,就这么多
      

  7.   

    xiaolng_ndsc帅哥,我现在也要做个这样的东西,请问你现在可以了吗?我用了你上面的方法就是服务启动了,发送就发不了了,如果有可不可以把代码发到我邮箱来《[email protected]》,谢谢...