社区
Java SE
帖子详情
短信猫 发短信时 出现乱码
xiaolng_ndsc
2011-06-24 12:44:45
用java对短信猫进行二次开发。用短信猫发短信时,手机能收到 短信,但是出现乱码。如果输入的为英文的则没有问题!这样怎么解决 。。
...全文
653
10
打赏
收藏
短信猫 发短信时 出现乱码
用java对短信猫进行二次开发。用短信猫发短信时,手机能收到 短信,但是出现乱码。如果输入的为英文的则没有问题!这样怎么解决 。。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
10 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
qjsbmqj123
2012-01-19
打赏
举报
回复
xiaolng_ndsc帅哥,我现在也要做个这样的东西,请问你现在可以了吗?我用了你上面的方法就是服务启动了,发送就发不了了,如果有可不可以把代码发到我邮箱来《ligang891@163.com》,谢谢...
xiaolng_ndsc
2011-06-24
打赏
举报
回复
[Quote=引用 2 楼 chenchenyangll 的回复:]
乱码问题都是编码的原因
[/Quote]
具体怎么指定,给点见意!
xiaolng_ndsc
2011-06-24
打赏
举报
回复
[Quote=引用 1 楼 araychou 的回复:]
指定编码
[/Quote]我指定编码了。但还是乱码
我贴下我发送时的代码
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("发送成功!");
chenchenyangll
2011-06-24
打赏
举报
回复
乱码问题都是编码的原因
ArayChou
2011-06-24
打赏
举报
回复
指定编码
xiaolng_ndsc
2011-06-24
打赏
举报
回复
[Quote=引用 6 楼 araychou 的回复:]
没用过smsdll,搜索了半天都没搜索手册什么的.帮不了你了
[/Quote]
这个是人家给的使用说明
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();
}
}
}
}
}
还有一个动态库,就这么多
xiaolng_ndsc
2011-06-24
打赏
举报
回复
[Quote=引用 5 楼 azhangjw 的回复:]
最好在容器里通一设置,或在Elipse设置,或加过滤器。当然页面也要设成一置的。
[/Quote]
这个是人家给的使用说明
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();
}
}
}
}
}
还有一个动态库,就这么多
其实我是真性情
2011-06-24
打赏
举报
回复
UTF-8不行就换GB2312或GBK试试。
ArayChou
2011-06-24
打赏
举报
回复
没用过smsdll,搜索了半天都没搜索手册什么的.帮不了你了
azhangjw
2011-06-24
打赏
举报
回复
最好在容器里通一设置,或在Elipse设置,或加过滤器。当然页面也要设成一置的。
短信
猫
搭建
短信
猫
搭建指南 随着技术的发展和需求的增加,
短信
猫
的搭建变得越来越重要。
短信
猫
是一种服务器端的工具,可以将服务器的状态和情况实
时
监控,并将警报信息发送到报警人。为了搭建
短信
猫
,需要安装相应的软件和配置...
企业
短信
群发系统(
短信
猫
)源代码
4. **
短信
编码与解码**:
短信
内容可能包含各种字符,需要正确处理编码问题,确保
短信
在发送和接收过程中不
出现乱码
。熟悉Unicode、GBK等编码方式至关重要。 5. **异常处理与日志记录**:为了保证系统的稳定性和可...
java
短信
猫
文档
Java
短信
猫
文档主要涉及到的是如何在Java环境中进行
短信
猫
的二次开发,以及如何利用Java接口与
短信
猫
设备进行通信。
短信
猫
,又称
短信
调制解调器,是一种硬件设备,可以连接到计算机或其他网络设备,通过GSM或CDMA...
c#
短信
猫
二次开发包
【标题】:“C#
短信
猫
二次开发包”
短信
猫
是一种硬件设备,用于通过GSM网络进行
短信
收发,常被开发者用于系统集成或自动化任务中。这个“C#
短信
猫
二次开发包”是为了帮助程序员利用C#语言与
短信
猫
设备进行交互而...
短信
猫
开发包
在使用
短信
猫
开发包
时
,开发者需要注意以下关键知识点: 1. **驱动安装**:`
短信
通_Setup.exe`是安装程序,运行后会为
短信
猫
安装相应的驱动程序,使计算机能够识别并与其通信。确保操作系统兼容性和正确安装驱动是...
Java SE
62,634
社区成员
307,269
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章