社区
Java SE
帖子详情
短信猫 发短信时 出现乱码
xiaolng_ndsc
2011-06-24 12:44:45
用java对短信猫进行二次开发。用短信猫发短信时,手机能收到 短信,但是出现乱码。如果输入的为英文的则没有问题!这样怎么解决 。。
...全文
636
10
打赏
收藏
短信猫 发短信时 出现乱码
用java对短信猫进行二次开发。用短信猫发短信时,手机能收到 短信,但是出现乱码。如果输入的为英文的则没有问题!这样怎么解决 。。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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设置,或加过滤器。当然页面也要设成一置的。
CDMA
猫
用AT命令发中文
短信
(C#)
CDMA
猫
连PDU都不支持,只能发文本
短信
。而且发中文
短信
居然是UNICODE,无法在超级终端里输入。只能写程序。网上这个问题谈论地比较多,做起来比较累,还偶尔会出乱码。还是将C#的成功代码帖一下吧。
asp.Net下
短信
猫
发送
短信
中的中文乱码解决
现象:用c#编码调用
短信
猫
发送包含中文字符的
短信
,但收到的总是乱码或问号(?),使用了Default, Unicode-16等多种编码方式仍然无效,而其他非中文字符都可以正常接收。另外,在超级终端中直接输入AT指令发送中英文,可以...
Java中文乱码问题全搞定
JAVA初学者遇到的常见问题就是中文乱码问题,但是导致中文乱码的原因有很多,经常搞得焦头烂额。这个视频帮助大家解决日常编程中常见的中文问题。
利用
短信
猫
发送
短信
教程&解决windows上发送成功而linux上失败问题
前言 目前用过的开源
短信
猫
工具有jSMSEngine和SMSLib,下载地址及使用网上有很多,本文只是...2.将usb
短信
猫
插入服务器usb口,使用dmesg命令查看,出现以下信息则说明系统已经识别出
短信
猫
,接口为/dev/ttyUSB0 ...
把安卓手机当作
短信
猫
的三款ANDROID应用
把安卓手机当作
短信
猫
,性能稳定,管理方便,最近研究了一下相关的ANDROID
短信
猫
应用,推荐一下三款:虫虫云
猫
,SMSSync,中文版SMS Gateway,下面做分别做介绍。 1、虫虫云
猫
: 收到
短信
后,接收到
短信
后,立刻...
Java SE
62,616
社区成员
307,307
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章