社区
Java SE
帖子详情
短信猫 发短信时 出现乱码
xiaolng_ndsc
2011-06-24 12:44:45
用java对短信猫进行二次开发。用短信猫发短信时,手机能收到 短信,但是出现乱码。如果输入的为英文的则没有问题!这样怎么解决 。。
...全文
715
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设置,或加过滤器。当然页面也要设成一置的。
asp.Net下
短信
猫
发送
短信
中的中文乱码解决
现象:用c#编码调用
短信
猫
发送包含中文字符的
短信
,但收到的总是乱码或问号(?),使用了Default, Unicode-16等多种编码方式仍然无效,而其他非中文字符都可以正常接收。另外,在超级终端中直接输入AT指令发送中英文,可以正常接收显示。我用的是TC35芯片的
短信
猫
。解决过程:并不是所有的.Net项目都会出现这样的情况,VC++,VB编译后的程序执行也没有出现这样的情形。于是考虑编写一个w
群
发
短信
接口开发对接指南:高效群
发
短信
功能实现与合规管控
本文详细解析群
发
短信
接口开发对接全流程,涵盖核心规范、多语言代码实现及异常处理。首先介绍了接口的通用设计原则和请求响应逻辑,包括必填参数、编码格式等基础要求。随后通过Node.js和Java代码示例演示具体对接方法,并提供批量发送、异步处理等优化技巧。最后总结了常见错误码及解决方案,如签名格式错误、发送频率限制等问题,帮助开发者规避技术风险,提高接口对接效率。全文聚焦实际开发痛点,为高效实现
短信
功能提供完整技术指导。
php 串口+GSM Modem
发
短信
前几天老板拿来一个
短信
猫
,让我用php做一个
发
短信
的程序,哎,我可是菜鸟,什么都不懂,网上查了很多资料,终于找到了方法:php通过调用串口直接用
短信
猫
来
发
短信
。 不过虽然源程序在手,但还是不能直接用,期间碰到很多很多问题,发中文
短信
啊,缺少dio库啊,最后还是解决了。我把代码贴出来,大家有需要的可以参考一 下: 注意几点: 1.必须要有php_dio.dll这个文件,原来我的ph
读
短信
猫
或手机
将sms.dll 文件拷贝到系统安装目录中的system32 文件夹中,然后再根据以下接口函数说明和提供的例程源码开发接口函数:1、Sms_Connection(Com_Port As Integer,Com_BaudRate As Integer, Mobile_Type As String) AsIntegerSms_Connection 函数说明如下:功能描述:用于初始化终端与串口的...
C#
短信
群发源码实战:基于
短信
猫
AT指令与PDU模式全解析
在物联网与企业信息化系统中,批量
短信
通知是常见的业务需求,而实现方式往往面临成本与可控性的权衡。串口通信作为计算机与外围设备交互的基础技术,其稳定性和正确性是底层开发的关键。通过AT指令集控制GSM Modem(
短信
猫
),开发者可以自主完成
短信
的编码、发送与状态确认,实现不依赖第三方平台的私有化消息通道。UCS2编码与PDU协议是处理中文
短信
内容的核心原理,理解字节序与协议帧结构能有效规避乱码和发送失败问题。该技术路线广泛应用于内部告警、预约提醒、物流通知等低频高价值场景,兼顾硬件一次性投入与数据隐私保护。
Java SE
62,620
社区成员
307,251
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章