From 90a71f4735f26c24813b46124039c8f15ee4fefe Mon Sep 17 00:00:00 2001 From: zhengjun Date: Tue, 9 Mar 2021 09:36:47 +0800 Subject: [PATCH] first commit --- .classpath | 6 ++++++ .idea/.gitignore | 8 ++++++++ .idea/artifacts/Demo_jar.xml | 8 ++++++++ .idea/encodings.xml | 7 +++++++ .idea/inspectionProfiles/Project_Default.xml | 36 ++++++++++++++++++++++++++++++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .project | 17 +++++++++++++++++ Demo.iml | 12 ++++++++++++ bin/META-INF/MANIFEST.MF | 3 +++ bin/mydemo/HttpURLConnectionUtil.class | Bin 0 -> 4940 bytes bin/mydemo/MainFrame$1.class | Bin 0 -> 2302 bytes bin/mydemo/MainFrame$2.class | Bin 0 -> 1599 bytes bin/mydemo/MainFrame$3.class | Bin 0 -> 3071 bytes bin/mydemo/MainFrame$4.class | Bin 0 -> 1492 bytes bin/mydemo/MainFrame$5.class | Bin 0 -> 674 bytes bin/mydemo/MainFrame.class | Bin 0 -> 10616 bytes bin/phonicapi/PhonicConst.class | Bin 0 -> 2243 bytes bin/phonicapi/PhonicHandler.class | Bin 0 -> 337 bytes bin/phonicapi/PhonicNative.class | Bin 0 -> 4101 bytes bin/x64/phonic_native.dll | Bin 0 -> 64000 bytes bin/x64/phonic_ubox.dll | Bin 0 -> 2094080 bytes bin/x64/phonic_utool.dll | Bin 0 -> 2428416 bytes bin/x64/phonic_utoolI.dll | Bin 0 -> 2203648 bytes bin/x64/phonic_utoolII.dll | Bin 0 -> 2589696 bytes bin/x64/phonic_utoolIIEx.dll | Bin 0 -> 2585088 bytes bin/x86/phonic_native.dll | Bin 0 -> 64000 bytes bin/x86/phonic_ubox.dll | Bin 0 -> 1599488 bytes bin/x86/phonic_utool.dll | Bin 0 -> 2425856 bytes bin/x86/phonic_utoolI.dll | Bin 0 -> 2201088 bytes bin/x86/phonic_utoolII.dll | Bin 0 -> 2586624 bytes bin/x86/phonic_utoolIIEx.dll | Bin 0 -> 2495488 bytes classes/artifacts/Demo_jar/Demo.jar | Bin 0 -> 19912235 bytes classes/artifacts/Demo_jar/bin/x64/phonic_native.dll | Bin 0 -> 64000 bytes classes/artifacts/Demo_jar/bin/x64/phonic_ubox.dll | Bin 0 -> 2094080 bytes classes/artifacts/Demo_jar/bin/x64/phonic_utool.dll | Bin 0 -> 2428416 bytes classes/artifacts/Demo_jar/bin/x64/phonic_utoolI.dll | Bin 0 -> 2203648 bytes classes/artifacts/Demo_jar/bin/x64/phonic_utoolII.dll | Bin 0 -> 2589696 bytes classes/artifacts/Demo_jar/bin/x64/phonic_utoolIIEx.dll | Bin 0 -> 2585088 bytes classes/artifacts/Demo_jar/bin/x86/phonic_native.dll | Bin 0 -> 64000 bytes classes/artifacts/Demo_jar/bin/x86/phonic_ubox.dll | Bin 0 -> 1599488 bytes classes/artifacts/Demo_jar/bin/x86/phonic_utool.dll | Bin 0 -> 2425856 bytes classes/artifacts/Demo_jar/bin/x86/phonic_utoolI.dll | Bin 0 -> 2201088 bytes classes/artifacts/Demo_jar/bin/x86/phonic_utoolII.dll | Bin 0 -> 2586624 bytes classes/artifacts/Demo_jar/bin/x86/phonic_utoolIIEx.dll | Bin 0 -> 2495488 bytes src/META-INF/MANIFEST.MF | 3 +++ src/mydemo/HttpURLConnectionUtil.java | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/mydemo/MainFrame.java | 529 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/phonicapi/PhonicConst.java | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/phonicapi/PhonicHandler.java | 23 +++++++++++++++++++++++ src/phonicapi/PhonicNative.java | 577 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 51 files changed, 1496 insertions(+), 0 deletions(-) create mode 100644 .classpath create mode 100644 .idea/.gitignore create mode 100644 .idea/artifacts/Demo_jar.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .project create mode 100644 Demo.iml create mode 100644 bin/META-INF/MANIFEST.MF create mode 100644 bin/mydemo/HttpURLConnectionUtil.class create mode 100644 bin/mydemo/MainFrame$1.class create mode 100644 bin/mydemo/MainFrame$2.class create mode 100644 bin/mydemo/MainFrame$3.class create mode 100644 bin/mydemo/MainFrame$4.class create mode 100644 bin/mydemo/MainFrame$5.class create mode 100644 bin/mydemo/MainFrame.class create mode 100644 bin/phonicapi/PhonicConst.class create mode 100644 bin/phonicapi/PhonicHandler.class create mode 100644 bin/phonicapi/PhonicNative.class create mode 100644 bin/x64/phonic_native.dll create mode 100644 bin/x64/phonic_ubox.dll create mode 100644 bin/x64/phonic_utool.dll create mode 100644 bin/x64/phonic_utoolI.dll create mode 100644 bin/x64/phonic_utoolII.dll create mode 100644 bin/x64/phonic_utoolIIEx.dll create mode 100644 bin/x86/phonic_native.dll create mode 100644 bin/x86/phonic_ubox.dll create mode 100644 bin/x86/phonic_utool.dll create mode 100644 bin/x86/phonic_utoolI.dll create mode 100644 bin/x86/phonic_utoolII.dll create mode 100644 bin/x86/phonic_utoolIIEx.dll create mode 100644 classes/artifacts/Demo_jar/Demo.jar create mode 100644 classes/artifacts/Demo_jar/bin/x64/phonic_native.dll create mode 100644 classes/artifacts/Demo_jar/bin/x64/phonic_ubox.dll create mode 100644 classes/artifacts/Demo_jar/bin/x64/phonic_utool.dll create mode 100644 classes/artifacts/Demo_jar/bin/x64/phonic_utoolI.dll create mode 100644 classes/artifacts/Demo_jar/bin/x64/phonic_utoolII.dll create mode 100644 classes/artifacts/Demo_jar/bin/x64/phonic_utoolIIEx.dll create mode 100644 classes/artifacts/Demo_jar/bin/x86/phonic_native.dll create mode 100644 classes/artifacts/Demo_jar/bin/x86/phonic_ubox.dll create mode 100644 classes/artifacts/Demo_jar/bin/x86/phonic_utool.dll create mode 100644 classes/artifacts/Demo_jar/bin/x86/phonic_utoolI.dll create mode 100644 classes/artifacts/Demo_jar/bin/x86/phonic_utoolII.dll create mode 100644 classes/artifacts/Demo_jar/bin/x86/phonic_utoolIIEx.dll create mode 100644 src/META-INF/MANIFEST.MF create mode 100644 src/mydemo/HttpURLConnectionUtil.java create mode 100644 src/mydemo/MainFrame.java create mode 100644 src/phonicapi/PhonicConst.java create mode 100644 src/phonicapi/PhonicHandler.java create mode 100644 src/phonicapi/PhonicNative.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fb50116 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/artifacts/Demo_jar.xml b/.idea/artifacts/Demo_jar.xml new file mode 100644 index 0000000..3f49563 --- /dev/null +++ b/.idea/artifacts/Demo_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/classes/artifacts/Demo_jar + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..249e792 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..84da703 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3c95a40 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..40826cd --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Demo + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Demo.iml b/Demo.iml new file mode 100644 index 0000000..26db12c --- /dev/null +++ b/Demo.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/META-INF/MANIFEST.MF b/bin/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0278c30 --- /dev/null +++ b/bin/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: mydemo.MainFrame + diff --git a/bin/mydemo/HttpURLConnectionUtil.class b/bin/mydemo/HttpURLConnectionUtil.class new file mode 100644 index 0000000..cdb3860 Binary files /dev/null and b/bin/mydemo/HttpURLConnectionUtil.class differ diff --git a/bin/mydemo/MainFrame$1.class b/bin/mydemo/MainFrame$1.class new file mode 100644 index 0000000..079fffe Binary files /dev/null and b/bin/mydemo/MainFrame$1.class differ diff --git a/bin/mydemo/MainFrame$2.class b/bin/mydemo/MainFrame$2.class new file mode 100644 index 0000000..00e651e Binary files /dev/null and b/bin/mydemo/MainFrame$2.class differ diff --git a/bin/mydemo/MainFrame$3.class b/bin/mydemo/MainFrame$3.class new file mode 100644 index 0000000..aba557e Binary files /dev/null and b/bin/mydemo/MainFrame$3.class differ diff --git a/bin/mydemo/MainFrame$4.class b/bin/mydemo/MainFrame$4.class new file mode 100644 index 0000000..7e4400d Binary files /dev/null and b/bin/mydemo/MainFrame$4.class differ diff --git a/bin/mydemo/MainFrame$5.class b/bin/mydemo/MainFrame$5.class new file mode 100644 index 0000000..2db525c Binary files /dev/null and b/bin/mydemo/MainFrame$5.class differ diff --git a/bin/mydemo/MainFrame.class b/bin/mydemo/MainFrame.class new file mode 100644 index 0000000..dc9fd46 Binary files /dev/null and b/bin/mydemo/MainFrame.class differ diff --git a/bin/phonicapi/PhonicConst.class b/bin/phonicapi/PhonicConst.class new file mode 100644 index 0000000..3d17c2d Binary files /dev/null and b/bin/phonicapi/PhonicConst.class differ diff --git a/bin/phonicapi/PhonicHandler.class b/bin/phonicapi/PhonicHandler.class new file mode 100644 index 0000000..72c71a4 Binary files /dev/null and b/bin/phonicapi/PhonicHandler.class differ diff --git a/bin/phonicapi/PhonicNative.class b/bin/phonicapi/PhonicNative.class new file mode 100644 index 0000000..02c83d1 Binary files /dev/null and b/bin/phonicapi/PhonicNative.class differ diff --git a/bin/x64/phonic_native.dll b/bin/x64/phonic_native.dll new file mode 100644 index 0000000..21f939e Binary files /dev/null and b/bin/x64/phonic_native.dll differ diff --git a/bin/x64/phonic_ubox.dll b/bin/x64/phonic_ubox.dll new file mode 100644 index 0000000..0604b29 Binary files /dev/null and b/bin/x64/phonic_ubox.dll differ diff --git a/bin/x64/phonic_utool.dll b/bin/x64/phonic_utool.dll new file mode 100644 index 0000000..a65cda8 Binary files /dev/null and b/bin/x64/phonic_utool.dll differ diff --git a/bin/x64/phonic_utoolI.dll b/bin/x64/phonic_utoolI.dll new file mode 100644 index 0000000..b3c4a5b Binary files /dev/null and b/bin/x64/phonic_utoolI.dll differ diff --git a/bin/x64/phonic_utoolII.dll b/bin/x64/phonic_utoolII.dll new file mode 100644 index 0000000..6dfe64c Binary files /dev/null and b/bin/x64/phonic_utoolII.dll differ diff --git a/bin/x64/phonic_utoolIIEx.dll b/bin/x64/phonic_utoolIIEx.dll new file mode 100644 index 0000000..78af76d Binary files /dev/null and b/bin/x64/phonic_utoolIIEx.dll differ diff --git a/bin/x86/phonic_native.dll b/bin/x86/phonic_native.dll new file mode 100644 index 0000000..da3f660 Binary files /dev/null and b/bin/x86/phonic_native.dll differ diff --git a/bin/x86/phonic_ubox.dll b/bin/x86/phonic_ubox.dll new file mode 100644 index 0000000..9dfb7db Binary files /dev/null and b/bin/x86/phonic_ubox.dll differ diff --git a/bin/x86/phonic_utool.dll b/bin/x86/phonic_utool.dll new file mode 100644 index 0000000..1dd5255 Binary files /dev/null and b/bin/x86/phonic_utool.dll differ diff --git a/bin/x86/phonic_utoolI.dll b/bin/x86/phonic_utoolI.dll new file mode 100644 index 0000000..57a2ca1 Binary files /dev/null and b/bin/x86/phonic_utoolI.dll differ diff --git a/bin/x86/phonic_utoolII.dll b/bin/x86/phonic_utoolII.dll new file mode 100644 index 0000000..6eb15c6 Binary files /dev/null and b/bin/x86/phonic_utoolII.dll differ diff --git a/bin/x86/phonic_utoolIIEx.dll b/bin/x86/phonic_utoolIIEx.dll new file mode 100644 index 0000000..3fb73c4 Binary files /dev/null and b/bin/x86/phonic_utoolIIEx.dll differ diff --git a/classes/artifacts/Demo_jar/Demo.jar b/classes/artifacts/Demo_jar/Demo.jar new file mode 100644 index 0000000..e8760c9 Binary files /dev/null and b/classes/artifacts/Demo_jar/Demo.jar differ diff --git a/classes/artifacts/Demo_jar/bin/x64/phonic_native.dll b/classes/artifacts/Demo_jar/bin/x64/phonic_native.dll new file mode 100644 index 0000000..21f939e Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x64/phonic_native.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x64/phonic_ubox.dll b/classes/artifacts/Demo_jar/bin/x64/phonic_ubox.dll new file mode 100644 index 0000000..0604b29 Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x64/phonic_ubox.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x64/phonic_utool.dll b/classes/artifacts/Demo_jar/bin/x64/phonic_utool.dll new file mode 100644 index 0000000..a65cda8 Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x64/phonic_utool.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x64/phonic_utoolI.dll b/classes/artifacts/Demo_jar/bin/x64/phonic_utoolI.dll new file mode 100644 index 0000000..b3c4a5b Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x64/phonic_utoolI.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x64/phonic_utoolII.dll b/classes/artifacts/Demo_jar/bin/x64/phonic_utoolII.dll new file mode 100644 index 0000000..6dfe64c Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x64/phonic_utoolII.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x64/phonic_utoolIIEx.dll b/classes/artifacts/Demo_jar/bin/x64/phonic_utoolIIEx.dll new file mode 100644 index 0000000..78af76d Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x64/phonic_utoolIIEx.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x86/phonic_native.dll b/classes/artifacts/Demo_jar/bin/x86/phonic_native.dll new file mode 100644 index 0000000..da3f660 Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x86/phonic_native.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x86/phonic_ubox.dll b/classes/artifacts/Demo_jar/bin/x86/phonic_ubox.dll new file mode 100644 index 0000000..9dfb7db Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x86/phonic_ubox.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x86/phonic_utool.dll b/classes/artifacts/Demo_jar/bin/x86/phonic_utool.dll new file mode 100644 index 0000000..1dd5255 Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x86/phonic_utool.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x86/phonic_utoolI.dll b/classes/artifacts/Demo_jar/bin/x86/phonic_utoolI.dll new file mode 100644 index 0000000..57a2ca1 Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x86/phonic_utoolI.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x86/phonic_utoolII.dll b/classes/artifacts/Demo_jar/bin/x86/phonic_utoolII.dll new file mode 100644 index 0000000..6eb15c6 Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x86/phonic_utoolII.dll differ diff --git a/classes/artifacts/Demo_jar/bin/x86/phonic_utoolIIEx.dll b/classes/artifacts/Demo_jar/bin/x86/phonic_utoolIIEx.dll new file mode 100644 index 0000000..3fb73c4 Binary files /dev/null and b/classes/artifacts/Demo_jar/bin/x86/phonic_utoolIIEx.dll differ diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0278c30 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: mydemo.MainFrame + diff --git a/src/mydemo/HttpURLConnectionUtil.java b/src/mydemo/HttpURLConnectionUtil.java new file mode 100644 index 0000000..3acb29d --- /dev/null +++ b/src/mydemo/HttpURLConnectionUtil.java @@ -0,0 +1,165 @@ +package mydemo; + + +import com.sun.istack.internal.Nullable; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; + + +public class HttpURLConnectionUtil { + + /** + * Http get请求 + * @param httpUrl 连接 + * @return 响应数据 + */ + public static String doGet(String httpUrl){ + //链接 + HttpURLConnection connection = null; + InputStream is = null; + BufferedReader br = null; + StringBuffer result = new StringBuffer(); + try { + //创建连接 + URL url = new URL(httpUrl); + connection = (HttpURLConnection) url.openConnection(); + //设置请求方式 + connection.setRequestMethod("GET"); + //设置连接超时时间 + connection.setReadTimeout(15000); + //开始连接 + connection.connect(); + //获取响应数据 + if (connection.getResponseCode() == 200) { + //获取返回的数据 + is = connection.getInputStream(); + if (null != is) { + br = new BufferedReader(new InputStreamReader(is, "UTF-8")); + String temp = null; + while (null != (temp = br.readLine())) { + result.append(temp); + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (null != br) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (null != is) { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + //关闭远程连接 + connection.disconnect(); + } + return result.toString(); + } + + /** + * Http post请求 + * @param httpUrl 连接 + * @param param 参数 + * @return + */ + public static String doPost(String httpUrl, @Nullable String param) { + StringBuffer result = new StringBuffer(); + //连接 + HttpURLConnection connection = null; + OutputStream os = null; + InputStream is = null; + BufferedReader br = null; + try { + //创建连接对象 + URL url = new URL(httpUrl); + //创建连接 + connection = (HttpURLConnection) url.openConnection(); + //设置请求方法 + connection.setRequestMethod("POST"); + //设置连接超时时间 + connection.setConnectTimeout(15000); + //设置读取超时时间 + connection.setReadTimeout(15000); + //DoOutput设置是否向httpUrlConnection输出,DoInput设置是否从httpUrlConnection读入,此外发送post请求必须设置这两个 + //设置是否可读取 + connection.setDoOutput(true); + connection.setDoInput(true); + //设置通用的请求属性 + connection.setRequestProperty("accept", "*/*"); + connection.setRequestProperty("connection", "Keep-Alive"); + connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"); + connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + + //拼装参数 + if (null != param && param.equals("")) { + //设置参数 + os = connection.getOutputStream(); + //拼装参数 + os.write(param.getBytes("UTF-8")); + } + //设置权限 + //设置请求头等 + //开启连接 + //connection.connect(); + //读取响应 + if (connection.getResponseCode() == 200) { + is = connection.getInputStream(); + if (null != is) { + br = new BufferedReader(new InputStreamReader(is, "GBK")); + String temp = null; + while (null != (temp = br.readLine())) { + result.append(temp); + result.append("\r\n"); + } + } + } + + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + //关闭连接 + if(br!=null){ + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if(os!=null){ + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if(is!=null){ + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + //关闭连接 + connection.disconnect(); + } + return result.toString(); + } + + public static void main(String[] args) { + String message = doPost("https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=13026194071", ""); + System.out.println(message); + } +} diff --git a/src/mydemo/MainFrame.java b/src/mydemo/MainFrame.java new file mode 100644 index 0000000..ba1776f --- /dev/null +++ b/src/mydemo/MainFrame.java @@ -0,0 +1,529 @@ +package mydemo; + +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JTextField; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import phonicapi.PhonicConst; +import phonicapi.PhonicHandler; +import phonicapi.PhonicNative; + + + +public class MainFrame extends JFrame implements PhonicHandler{ + private JButton btnHookOff = new JButton("摘机"); + private JButton btnHookOn = new JButton("挂机"); + private JButton btnCall = new JButton("拨号"); + + private JButton btnSendMsg = new JButton("发送短信"); + private JTextField txtNumb = new JTextField(); + private JComboBox cbxLine = new JComboBox(); + private JTextField txtShortMsgNumber = new JTextField(); + private JTextField txtShortMsg = new JTextField(); + private int uBoxHndOne = 0; //线路1操作句柄 + private int uBoxHndTwo = 0; //线路2操作句柄 + private int uBoxId = 0;// 设备类型 + private boolean bHookOff = false; + private String strDir = "C:\\"; + + MainFrame () + { + try{ + File directory = new File(""); + strDir = directory.getAbsolutePath(); + System.out.println(strDir); + }catch(Exception e){} + + //线路 + cbxLine.setBounds(20, 20, 160, 20); + cbxLine.addItem("线路1"); + cbxLine.addItem("线路2"); + cbxLine.setSelectedItem("线路1"); + + //摘机 + btnHookOff.setBounds(20, 60, 60, 20); + btnHookOff.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; + int nResult = PhonicNative.ubox_soft_hook_off(uBoxHnd); + System.out.println(nResult); + if(0 == nResult) + { + bHookOff = true; + cbxLine.setEnabled(false); + btnHookOff.setEnabled(false); + btnHookOn.setEnabled(true); + btnCall.setEnabled(true); + txtNumb.setEnabled(true); + + //开始录音 + Date nowDate = new Date(); + DateFormat dfDate = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); + String strPath = strDir+"\\"+dfDate.format(nowDate)+".wav"; + System.out.println(strPath); + PhonicNative.ubox_record_file(uBoxHnd, strPath, CODER_ALAW); + } + } + }); + //挂机 + btnHookOn.setEnabled(false); + btnHookOn.setBounds(120, 60, 60, 20); + btnHookOn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; + int nResult = PhonicNative.ubox_soft_hook_on(uBoxHnd); + System.out.println(nResult); + if(0 == nResult) + { + bHookOff = false; + cbxLine.setEnabled(true); + btnHookOff.setEnabled(true); + btnHookOn.setEnabled(false); + btnCall.setEnabled(true); + txtNumb.setEnabled(true); + + //停止录音 + PhonicNative.ubox_stop_record(uBoxHnd); + } + } + }); + + //拨号 + btnCall.setBounds(120, 100, 60, 20); + btnCall.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(uBoxId == 8) + { + if(txtNumb.getText().length() > 0) + { + cbxLine.setEnabled(false); + btnHookOff.setEnabled(false); + btnHookOn.setEnabled(true); + btnCall.setEnabled(true); + txtNumb.setEnabled(true); + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; + int nResult = PhonicNative.ubox_makecall(uBoxHnd, txtNumb.getText()); + System.out.println(nResult); + + + } + } + else + { + //摘机 + if(!bHookOff) + { + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; + int nResult = PhonicNative.ubox_soft_hook_off(uBoxHnd); + System.out.println(nResult); + if(0 == nResult) + { + bHookOff = true; + cbxLine.setEnabled(false); + btnHookOff.setEnabled(false); + btnHookOn.setEnabled(true); + btnCall.setEnabled(true); + txtNumb.setEnabled(true); + + //开始录音 + Date nowDate = new Date(); + DateFormat dfDate = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); + String strPath = strDir+"\\"+dfDate.format(nowDate)+".wav"; + System.out.println(strPath); + PhonicNative.ubox_record_file(uBoxHnd, strPath, CODER_ALAW); + } + //等待0.5秒再拨号 + try{ + Thread.sleep(500); + }catch(Exception ee){ + ee.printStackTrace(); + } + } + + if(txtNumb.getText().length() > 0) + { + btnCall.setEnabled(false); + txtNumb.setEnabled(false); + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; + int nResult = PhonicNative.ubox_send_dtmf(uBoxHnd, txtNumb.getText()); + System.out.println(nResult); + } + } + } + }); + + btnCall.setEnabled(false); + btnSendMsg.setEnabled(false); + //号码输入框 + txtNumb.setBounds(20, 100, 80, 20); + txtNumb.setText("910000"); + + txtShortMsgNumber.setBounds(20, 140, 80, 20); //收件号码 + txtShortMsgNumber.setText("8615907558923");//发短信,需要在号码前加国际区号 ,中国"86" + + txtShortMsg.setBounds(120, 140, 200, 20); //短信内容 + txtShortMsg.setText("");//发短信,需要在号码前加国际区号 ,中国"86" + + //发送短信 + btnSendMsg.setBounds(340, 140, 120, 20); + btnSendMsg.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(uBoxId == 8) + { + if(txtShortMsgNumber.getText().length() > 0 && txtShortMsg.getText().length() > 0) + { + + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; + int nResult = PhonicNative.ubox_send_gsm_msg(uBoxHnd, 1, txtShortMsgNumber.getText(), txtShortMsg.getText(),txtShortMsg.getText().length()); + System.out.println(nResult); + + + } + } + } + }); + //添加控件 + add(cbxLine); + add(btnHookOff); + add(btnHookOn); + add(btnCall); + add(txtNumb); + + add(txtShortMsgNumber); + add(txtShortMsg); + add(btnSendMsg); + //初始化 + openUBox(); + } + + //打开设备 + public boolean openUBox() + { + PhonicNative.ubox_open_logfile(0); + int nOpen = PhonicNative.ubox_open(this, PhonicConst.WORK_MODE_RECORD); + System.out.println("ubox_open="+nOpen); + if(nOpen == 0) + { + return true; + } + return false; + } + + //关闭设备 + public boolean closeUBox() + { + uBoxHndOne = 0; + uBoxHndTwo = 0; + PhonicNative.ubox_close(); + return true; + } + + + //设备事件 + public void event(int uboxHnd, int eventID, int param1, int param2, int param3, int param4) { + switch (eventID) + { + case UBOX_EVENT_DEVICE_PLUG_IN: + { + //检测型号正确 + //if(1 == PhonicNative.ubox_get_product_ID(uboxHnd)) + { + if(0 == uBoxHndOne) + { + uBoxHndOne = uboxHnd; + uBoxId = PhonicNative.ubox_get_product_ID(uboxHnd); + System.out.println(PhonicNative.ubox_get_device_versionnum(uboxHnd)); + System.out.println(PhonicNative.ubox_get_product_name(uboxHnd)); + if(uBoxId == 8) //无线设备 + { + PhonicNative.ubox_set_gsm_work_mode(uboxHnd, 1, 0); //如果不用电话机,关闭电话机模式,否则振铃的时候,戴着耳麦会听到很大的给电话机送来电号码声音,体验效果不好。 + } + } + else if(0 == uBoxHndTwo) + { + uBoxHndTwo = uboxHnd; + } + else + { + uBoxHndOne = uboxHnd; + uBoxHndTwo = 0; + } + } + System.out.println("收到设备插入事件:" + uboxHnd); + } + break; + case UBOX_EVENT_DEVICE_PLUG_OUT: + { + System.out.println("收到设备拔出事件:" + uboxHnd); + } + break; + case UBOX_EVENT_LINE_HOOK_UP: + { + + if(uBoxId == 8) + { + if(param1 == 1) + { + System.out.println("收到GSM模块挂机:" + uboxHnd); + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 0); //被叫能够听不到耳麦说话的声音 + } + else if(param1 == 2) + { + System.out.println("收到电话机挂机:" + uboxHnd); + } + else if(param1 == 3) + { + System.out.println("收到耳麦挂机:" + uboxHnd); + } + } + else + { + System.out.println("收到设备挂机事件:" + uboxHnd); + } + } + break; + case UBOX_EVENT_LINE_HOOK_OFF: + { + if(uBoxId == 8) + { + if(param1 == 0) + { + System.out.println("收到电话机摘机:" + uboxHnd); + } + else if(param1 == 2) + { + System.out.println("收到耳麦摘机:" + uboxHnd); + } + else if(param1 == 6) + { + System.out.println("收到GSM模块摘机:" + uboxHnd); + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 1); //被叫能够听到耳麦说话的声音 + } + } + else + { + System.out.println("收到设备摘机事件:" + uboxHnd); + } + } + break; + case UBOX_EVENT_LINE_RINGING: + { + System.out.println("收到设备检测线路振铃开始事件:" + uboxHnd); + } + break; + case UBOX_EVENT_DEVICE_PLAY_END: + { + System.out.println("收到放音结束事件:" + uboxHnd); + } + break; + case UBOX_EVENT_RING_CANCEL: + { + System.out.println("收到设备检测线路振铃停止事件:" + uboxHnd); + } + break; + case UBOX_EVENT_DEVICE_BUSY_TONE: + { + System.out.println("收到设备检测线路忙音事件:" + uboxHnd); + } + break; + case UBOX_EVENT_ALARM: + { + System.out.println("收到设备工作警告事件:" + uboxHnd); + } + break; + case UBOX_EVENT_DEVICE_ERROR: + { + System.out.println("收到设备错误事件:" + uboxHnd); + } + break; + case UBOX_EVENT_LINE_RING_STOP: + { + System.out.println("收到设备检测线路振铃闪停事件:" + uboxHnd); + } + break; + case UBOX_EVENT_LINE_HANG: + { + System.out.println("收到设备悬空事件:" + uboxHnd); + } + break; + case UBOX_EVENT_LINE_VOLTAGE: + { + System.out.println("收到设备线路当前电压事件:" + uboxHnd); + } + break; + case UBOX_EVENT_STREAM_VOICE: + { + System.out.println("收到流式录音数据包事件:" + uboxHnd); + } + break; + case UBOX_EVENT_DTMF_DOWN: + { + //System.out.println("按键事件:" + uboxHnd); + } + break; + case UBOX_EVENT_DTMF_UP: + { + System.out.println("收到按键释放事件:" + uboxHnd); + } + break; + case UBOX_EVENT_DEVICE_PLAY_ERROR: + { + System.out.println("收到放音错误事件:" + uboxHnd); + } + break; + case UBOX_EVENT_CALLOUTFINISH: + { + System.out.println("收到软件拨号完成事件:" + uboxHnd); + } + break; + case UBOX_EVENT_POLARITY: + { + System.out.println("收到检测极性反转事件:" + uboxHnd); + } + break; + case UBOX_EVENT_SIM_STATE: + { + if(param2 == 1) + { + System.out.println("卡状态事件, 当前选择sim卡" + param1); + } + else if(param2 == 2) + { + System.out.println("卡状态事件, sim卡" + param1 +" GSM 模块检查Sim卡未插入"); + } + else if(param2 == 3) + { + System.out.println("卡状态事件, sim卡" + param1 +" 检测到卡存在,并且是插好的"); + } + else if(param2 > 3) + { + System.out.println("卡状态事件, sim卡" + param1 +" 检测到卡有错误,错误值:"+param2); + } + } + break; + case UBOX_EVENT_ANSWER: + { + System.out.println(" 被叫已经应答了"); + + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 1); //被叫能够听到耳麦说话的声音 + } + break; + case UBOX_EVENT_SIGNALE_SIZE: + { + System.out.println(" 信号大小:"+param1); + } + break; + case UBOX_EVENT_SHORT_MSG_SIZE: + { + System.out.println(" 被叫已经应答了"); + } + break; + case UBOX_EVENT_SIM_REG: + { + if(param2 == 0) + { + System.out.println("sim卡" + param1+1 + " 网络未注册,当前没有搜索到要注册业务的新营运商 "); + } + else if(param2 == 1) + { + System.out.println("sim卡" + param1+1 + " 网络已注册"); + btnCall.setEnabled(true); //网络已经注册好了,可以拨打电话和发短信 + btnSendMsg.setEnabled(true); + } + else if(param2 == 2) + { + System.out.println("sim卡" + param1+1 + " 网络未注册,正在搜索要注册业务的新营运商"); + } + else if(param2 == 3) + { + System.out.println("sim卡" + param1+1 + " 注册被拒绝"); + } + else if(param2 == 4) + { + System.out.println("sim卡" + param1+1 + " 未注册, 未知原因"); + } + else if(param2 == 5) + { + System.out.println("sim卡" + param1+1 + " 已注册,漫游"); + } + } + break; + case UBOX_EVENT_SHORT_MSG_SEND_REPORT: + { + if(param1 == 0) + { + System.out.println("短信发送失败"); + } + else if(param1 == 1) + { + System.out.println("短信发送成功"); + } + else if(param1 == 2) + { + System.out.println("短信发送超时"); + } + } + break; + default: + { + System.out.println("未知事件[uboxHnd=" + uboxHnd + "][eventID=" + eventID + + "][param1=" + param1 + "][param2=" + param2 + "][param3=" + + param3 + "][param4=" + param4 + "]"); + } + break; + } + } + + public void callInNumber(int uboxHnd, String number) { + String usernum = PhonicNative.ubox_get_usernum(uboxHnd, 32); + System.out.println("收到主叫号码[uboxHnd=" + uboxHnd + "][number=" + number + "]"); + System.out.println("用户号"+"[usernum=" + usernum + "]"); + String get = HttpURLConnectionUtil.doGet("http://xiyangyang.51feijin.com/api/mobile/code?mobile=15179379512"); + System.out.println("请求结果" + get); + String get2 = HttpURLConnectionUtil.doGet("http://xiyangyang.51feijin.com/company-api/security/popup?code=112233&phone="+number); + System.out.println("请求结果" + get2); + } + + public void ShortMsg(int uboxHnd, String PhoneNumber, String stTime, String msg, String strDived) { + System.out.println("收到短信[uboxHnd=" + uboxHnd + "][发件人=" + PhoneNumber + "]" + ", 时间:"+stTime +", 内容:" +msg+ " "+strDived); + } + + public void CmdMsg(int uboxHnd, String cmd) { + System.out.println("收到消息[uboxHnd=" + uboxHnd + "][内容=" + cmd + "]"); + } + + public static void main(String[] args) + { + final MainFrame myFrame = new MainFrame(); + myFrame.setTitle("电话示例"); + myFrame.setSize(800, 600); + myFrame.setLayout(null); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + Dimension frameSize = myFrame.getSize(); + myFrame.setLocation((screenSize.width-frameSize.width)/2, (screenSize.height-frameSize.height)/2); + myFrame.setDefaultCloseOperation(EXIT_ON_CLOSE); + myFrame.addWindowListener(new WindowAdapter(){ + public void windowClosing(WindowEvent e){ + myFrame.closeUBox(); + } + }); + myFrame.setVisible(true); + System.out.println("退出"); + + } +} diff --git a/src/phonicapi/PhonicConst.java b/src/phonicapi/PhonicConst.java new file mode 100644 index 0000000..75357ad --- /dev/null +++ b/src/phonicapi/PhonicConst.java @@ -0,0 +1,88 @@ +package phonicapi; + +public interface PhonicConst { + int UBOX_EVENT_DEVICE_PLUG_IN = 1; // 检测到设备插入,回调函数中param1、param2、param3、param4未使用, + int UBOX_EVENT_DEVICE_PLUG_OUT = 2; // 检测到设备拔出, + + int UBOX_EVENT_ALARM = 3; // 报警,param1参照UBOX_ALARM的定义,设备工作不正常,软件退出,检查设备驱动程序是否安装好 + + int UBOX_EVENT_LINE_RESET = 10; // 复位:摘机->挂机,振铃->停振 硬件LED灭 已经将该事件分为两个挂机和停振事件 + int UBOX_EVENT_LINE_RINGING = 11; // 振铃,硬件LED亮 + int UBOX_EVENT_LINE_HOOK_OFF = 12; // 摘机,硬件LED亮 + int UBOX_EVENT_LINE_HANG = 13; // 检测到线路悬空 ,默认线路电压小于3V,认为线路悬空,硬件LED闪烁 + + // UBOX_EVENT_LING_FLUSH = 14, //?? 需要吗? + + int UBOX_EVENT_RING_CANCEL = 15; // 振铃取消,当末次振铃停止超过6秒,则触发此事件, + + int UBOX_EVENT_LINE_VOLTAGE = 16; // 线路电压事件,param1是线路电压值,param1不会出现等于0的电压。 + int UBOX_EVENT_STREAM_VOICE = 20; // 流式录音事件,param1是录音数据地址,需要转换,unsigned + // char* pvoice= (unsigned char*)param1 + // param2是录音数据长度 + + int UBOX_EVENT_CALLER_ID = 21; // param1是号码地址 param2是时间地址 param3是姓名地址 + // param4没有用 + // 需要类型转换 char* pszcallId =(char*)param1; char* pszcalltime=(char*)param2; + // char* pszcallname=(char*) param3 + + int UBOX_EVENT_DTMF_DOWN = 22; // 按键事件,param1是按键键值 + int UBOX_EVENT_DTMF_UP = 23; + int UBOX_EVENT_DEVICE_ERROR = 24; // 设备错误;需要软件重新启动,不然接收不到主叫号码 + int UBOX_EVENT_DEVICE_PLAY_END = 25; // 放音完毕 + int UBOX_EVENT_DEVICE_PLAY_ERROR = 26; // 放音异常 + int UBOX_EVENT_DEVICE_BUSY_TONE = 27; // 检测到忙音,对方挂机 + int UBOX_EVENT_CALLOUTFINISH = 28; // 呼出完成,表示拨号结束 + int UBOX_EVENT_POLARITY = 29; // 检测到极性反转 + int UBOX_EVENT_LINE_HOOK_UP = 30; // 挂机 + int UBOX_EVENT_LINE_RING_STOP = 31; // 停振 + + int UBOX_EVENT_SIM_STATE = 32; //param1: 1 sim卡1 2:sim卡2 param2: 0 未插入(新版本已经不支持了) 1:设备当前工作sim卡序号 2:GSM 模块检查Sim卡未插入 3. 检测到sim卡插入,其它值检测到sim有错误 + int UBOX_EVENT_ANSWER = 33; + int UBOX_EVENT_GSM_MSG = 34; //收到GSM返回的消息 + int UBOX_EVENT_SHORT_MSG =35; ////短信 param1:发短信电话号码 param2:短信时间 param3:短信内容 param4:"" 为空,短信没有被分割 + int UBOX_EVENT_SIGNALE_SIZE = 36; //信号大小 + int UBOX_EVENT_GSM_VOL_SIZE = 37; //param1: 1 gsm play 2:gsm mic param2: 声音大小 + int UBOX_EVENT_SHORT_MSG_SIZE = 38; //短信数量 param1:SIM卡 短信数目, param2: SIM卡短信存储空间数目 + int UBOX_EVENT_SIM_REG = 39; //SIM 是否注册 param1: sim序号 0:sim1 ,1:sim2 param2: sim卡注册返回值, + /* + 0 未注册;ME 当前没有搜索到要注册业务的新营运商 + 1 已注册,本地网 + 2 未注册,但 ME正在搜索要注册业务的新营运商 + 3 注册被拒绝 + 4 未知 + 5 已注册,漫游 + */ + int UBOX_EVENT_SHORT_MSG_SEND_REPORT = 40; //短信发送报告, param1=0,发送失败 param1=1,发送成功 ,param1=3,发送超时,失败 + + // 工作模式 + int WORK_MODE_RECORD = 0; + int WORK_MODE_DIAGNOSIS = 1; + int WORK_MODE_CONFIG = 2; + + // 语言编码 + int CODER_ALAW = 0;// 默认使用 + int CODER_PCM = 1; + int CODER_G729 = 3; + int CODER_SPEEX = 20;// 8倍压缩 + int CODER_MP3 = 38; + int CODER_ULAW = 100; + + //USB无线设备,通话控制开关,要能够听到通话声音,根据自己的应用打开和关闭相应的开关 + int SLIC_TO_GSM = 0; //SLIC到GSM方向 + int GSM_TO_SLIC = 1; //GSM到SLIC方向 + int EARPHONE_TO_GSM = 2; //耳麦到GSM方向 + int GSM_TO_EARPHONE =3; //GSM到耳麦方向 + int SLIC_TO_EARPHONE = 4; //电话机坐席到耳麦方向 + int EARPHONE_TO_SLIC = 5; //G耳麦到电话机坐席方向 + int USB_TO_EARPHONE = 6; //USB到耳麦方向 用于电脑播放语音 + int USB_TO_GSM = 7; //USB到GSM方向 用于电脑播放语音 + int USB_TO_SLIC = 8; //USB到电话机坐席方向 用于电脑播放语音 + + + //USB无线设备, 录音控制开关,可以选择需要那方面的声音 + int SLIC_REC_ = 0; //SLIC(电话机方向)录音 + int GSM_REC = 1; //GSM录音, 对于3101B, 是对外线录音,为了方便兼容,还是叫这个名称 + int EARPHONE_REC = 2; //Earphone(耳麦)录音 + int USB_REC = 3; //录下USB播放的声音 + +} diff --git a/src/phonicapi/PhonicHandler.java b/src/phonicapi/PhonicHandler.java new file mode 100644 index 0000000..7f63e8e --- /dev/null +++ b/src/phonicapi/PhonicHandler.java @@ -0,0 +1,23 @@ +package phonicapi; + +public interface PhonicHandler extends PhonicConst{ + /** + * @param uboxHnd + * 设备句柄 + * @param eventID + * 事件,参考UBOX_EVENT的定义 + * @param param1 + * 不同的事件,其含义不同 + * @param param2 + * 不同的事件,其含义不同 + * @param param3 + * 不同的事件,其含义不同 + * @param param4 + * 不同的事件,其含义不同 + */ + public void event(int uboxHnd, int eventID, int param1, int param2, int param3, int param4); + + public void callInNumber(int uboxHnd, String number); //来电号码 + public void ShortMsg(int uboxHnd, String PhoneNumber, String stTime, String msg, String strDived); //短信内容 + public void CmdMsg(int uboxHnd, String cmd); //返回命令消息,比如操作失败等 +} diff --git a/src/phonicapi/PhonicNative.java b/src/phonicapi/PhonicNative.java new file mode 100644 index 0000000..c2e7c3c --- /dev/null +++ b/src/phonicapi/PhonicNative.java @@ -0,0 +1,577 @@ +package phonicapi; + +public class PhonicNative { + + /** + * 设置事件通知回调函数和工作模式 + * + * @param eh回调函数 + * @param mode + * USB盒的工作模式,通常是录音方式,0录音模式,1诊断模式,2配置模式 + * @return 0成功,其实失败 + */ + public static native int ubox_open(PhonicHandler eh, int mode); + + /** + * 设关闭 + */ + public static native void ubox_close(); + + /** + * 获取硬件的版本号, + * + * @param uboxHnd + * 设备句柄 + * @return version_num由整数部分和1位小数部分组成,整数部分是主版本号,小数部分是次版本号 + */ + public static native float ubox_get_device_versionnum(int uboxHnd); + + /** + * 获取产品设备号 + * + * @param uboxHnd + * 设备句柄 + * @return 产品对应的设备号,1 FI3102A,2 FI3002B,3 FI3001B,4 FI3101A + */ + public static native int ubox_get_product_ID(int uboxHnd); + + /** + * 获取产品设备名称 + * + * @param uboxHnd + * 设备句柄 + * @return 设备名称 + * "FI3102A"两路外线,"FI3002B"两路高阻录音,"FI3001B"一路高阻录音,"FI3101A"带耳麦语音盒 + */ + public static native String ubox_get_product_name(int uboxHnd); + + /** + * 读取用户号 + * + * @param uboxHnd + * 设备句柄 + * @param len + * 返回用户号的长度不能低于16 + * @return 用户号,用户号的长度为16字节,前8个字节为用户编号,后8个字节为出厂日期 + */ + public static native String ubox_get_usernum(int uboxHnd, int len); + + /** + * 获取当前工作模式 + * + * @return 当前工作的模式有:0录音模式,1诊断模式,2配置模式 + */ + public static native int ubox_get_work_mode(); + + /** + * 检查指定的语音编码是否合法 + * + * @param coder + * 语音编码支持一下几种编码格式:0 CODER_ALAW,1 CODER_PCM,3 CODER_G729,20 + * CODER_SPEEX(8倍压缩率),38 CODER_MP3,100 CODER_ULAW + * @return 0合法,UBOX_ERR_INVALID_VOICE_CODER 语音编码不合法 + */ + public static native int ubox_check_coder(int coder); + + /** + * 录音到文件中 + * + * @param uboxHnd + * 设备句柄 + * @param filename + * 录音文件名 如果编码格式选择CODER_MP3,文件名后缀为.mp3,其它格式推荐使用.wav后缀 + * @param coder + * 语音编码格式:0 CODER_ALAW,1 CODER_PCM,3 CODER_G729,20 + * CODER_SPEEX(8倍压缩率),38 CODER_MP3,100 + * CODER_ULAW,一般推荐用CODER_ALAW, CODER_MP3和CODER_SPEEX编码 + * @return 0成功,<0失败 + */ + public static native int ubox_record_file(int uboxHnd, String filename, + int coder); + + /** + * 流式录音 + * + * @param uboxHnd + * 设备句柄 + * @param coder + * 语音编码格式:0 CODER_ALAW,1 CODER_PCM,3 CODER_G729,20 + * CODER_SPEEX(8倍压缩率),38 CODER_MP3,100 CODER_ULAW + * @return 0成功 + * 说明:调用这个函数后,会不停地触发UBOX_EVENT_STREAM_VOICE事件,直到调用ubox_stop_record() + */ + public static native int ubox_record_stream(int uboxHnd, int coder); + + /** + * 停止文件和流式录音 + * + * @param uboxHnd + * 设备句柄 + * @return 0成功 + */ + public static native int ubox_stop_record(int uboxHnd); + + /** + * 读取悬空 + * + * @param uboxHnd + * 设备句柄 + * @return >0悬空门限值,<0失败 说明:此函数必需在 UBOX_MODE_CONFIG 模式下使用,否则返回 + * UBOX_ERR_INVALID_WORK_MODE。Fi3001B调用这个函数才有意义 + */ + public static native int ubox_get_hang_threshold(int uboxHnd); + + /** + * 设置悬空门限值,参考ubox_set_hookoff_threshold中的说明 + * + * @param uboxHnd + * 设备句柄 + * @param threshold + * 小于该值,判断线路悬空 + * @return 0成功, 说明:产品Fi3001B调用这个函数才有意义 + */ + public static native int ubox_set_hang_threshold(int uboxHnd, int threshold); + + /** + * 读取摘机门限值 + * + * @param uboxHnd + * 设备句柄 + * @return >0摘机门限值,<0失败 说明:产品Fi3001B调用这个函数才有意义 + */ + public static native int ubox_get_hookoff_threshold(int uboxHnd); + + /** + * 设置摘机门限值 + * + * @param uboxHnd + * 设备句柄 + * @param threshold + * 的值是摘机电压和挂机电压的之和的一半,摘机电压和挂机电压测量调用,ubox_start_read_line_voltage, + * 对于Fi3001B摘机状态是通过电压判断的 + * @return 说明:产品Fi3001B调用这个函数才有意义 + * Fi3001是通过压控方式检测电话状态,通常情况下,挂机时直流电压为48V左右,摘机时直流电压会降到6V左右 + * 。USB录音盒设置默认摘机门限值为18V, + * 当线路电压大于18V,软件判断为挂机,小于18V软件判断为摘机。由于电话线的所处的环境不同 + * ,线路直流电压值不同,可能摘机后,线路电压依然要大于摘机门限值,这样软件不能正确检测到电话状态,需要重新设置摘机门限值 + */ + public static native int ubox_set_hookoff_threshold(int uboxHnd, + int threshold); + + /** + * 开始检测线路电压 + * + * @param uboxHnd + * 设备句柄 + * @return 0成功 + * 说明:调用这个函数后,会不停触发UBOX_EVENT_LINE_VOLTAGE事件,报告当前线路电压值。产品Fi3001B调用这个函数才有意义 + */ + public static native int ubox_start_read_line_voltage(int uboxHnd); + + /** + * 结束检测线路电压 + * + * @param uboxHnd + * 设备句柄 + * @return 0成功 说明:调用这个函数后,会停止触发UBOX_EVENT_LINE_VOLTAGE事件产品Fi3001B调用这个函数才有意义 + */ + public static native int ubox_stop_read_line_voltage(int uboxHnd); + + /** + * 发送号码(DTMF) + * + * @param uboxHnd + * 设备句柄 + * @param dmftfstring + * 号码串 + * @return 0成功 + * 说明:Fi3101A,FI3102A可以不摘机,软拨号直接拨出号码。对于Fi3101A,如果电话机摘机声音自动切换到电话机里 + * ,底层自动软挂机,耳机无声音 + * 。Fi3001B和Fi3002B,必须要先手动摘机,才可以拨号。对于有软摘机功能的产品,直接软件拨号, + * 有可能拨号不成功,拨得太快了, + * 交换机需要时间检测摘机,因此处理方法上层程序需要先软摘机后,延时1-2S钟,然后再调用ubox_send_dtmf函数 + */ + public static native int ubox_send_dtmf(int uboxHnd, String dmftfstring); + + /** + * 播放语音文件 + * + * @param uboxHnd + * 设备句柄 + * @param filename + * 语音文件名 + * @return 0成功 说明:放音格式为: A-law,u-law, 8k * 16 位 pcm文件 + */ + public static native int ubox_play_file(int uboxHnd, String filename); + + /** + * 停止播放 + * + * @param uboxHnd + * 设备句柄 + * @return 0成功 + */ + public static native int ubox_stop_play(int uboxHnd); + + /** + * 暂停播放,再调用一次,继续播放 + * + * @param uboxHnd + * 设备句柄 + * @return 0成功 + */ + public static native int ubox_play_pause(int uboxHnd); + + /** + * 设置MIC音量,一般设置为0db + * + * @param uboxHnd + * 设备句柄 + * @param volume + * 设置值,取值范围为0--19 + * @return 0成功 + */ + public static native int ubox_set_volume(int uboxHnd, int volume); + + /** + * 设置放音音量 + * + * @param uboxHandle + * 设备句柄 + * @param volume + * 设置音量,取值范围为-12--6 + * @return 0成功 + */ + public static native int ubox_set_Speakervolume(long uboxHandle, + short volume); + + /** + * 打开和关闭agc + * + * @param uboxHnd + * 设备句柄 + * @param bclose + * true关闭agc,false打开agc,默认情况下是打开agc + * @return 0成功 + */ + public static native int ubox_close_agc(int uboxHnd, boolean bclose); + + /** + * 读取USB录音盒中eeprom内的数据 + * + * @param uboxHnd + * 设备句柄 + * @param addr + * 要读取的数据的起始地址,范围为0x00-0x07 + * @param len + * 读取的长度 + * @return 读取到的数据 说明:Fi3001B使用该函数必须要在配置模式下才能使用 + * 用法:假如uboxHnd=1,addr=0x0,unsigned char + * readdata[8],ubox_read_eeprom + * (1,0x00,&readata[0],8),调用成功后,读取的数据在readdata中 + */ + public static native String ubox_read_eeprom(int uboxHnd, char addr, int len); + + /** + * 往USB录音盒中的eeprom写入数据 + * + * @param uboxHnd + * 设备句柄 + * @param addr + * 开始写入的起始地址,范围为0x00-0x07 + * @return 0成功 用法:假如uboxHnd=1,addr=0x00,unsigned char writedata[8]= + * {0x01,0x20,0x30,0x31,0x32,0x33,0x40,0x70} + * ubox_write_eeprom(1,0x0, + * &writedata[0],8),可以在同一个地址区域调用ubox_read_eeprom验证,读取的数据和写入数据是否相等 + */ + public static native int ubox_write_eeprom(int uboxHnd, char addr, + byte[] inData); + + /** + * 读取USB录音盒中eeprom内的数据 + * + * @param uboxHnd + * 设备句柄 + * @param addr + * 要读取的数据的起始地址,范围为0x00-0x07 + * @param len + * 读取的长度 + * @return 读取到的数据 + * 说明:对于Fi3001B,调用ubox_write_eeprom写成功后,读取其正确值,必须在软件重新启动后(关闭后, + * 再打开),调用ubox_read_eepromEx才能正确读取上次修改的值 + * 。而其它产品调用ReadEepromEx和ReadEeprom功能是一样的 + * 用法:假如uboxHnd=1,addr=0x0,unsigned char + * readdata[8],ubox_read_eeprom + * (1,0x00,&readata[0],8),调用成功后,读取的数据在readdata中 + */ + public static native int ubox_read_eepromEx(int uboxHnd, char addr, int len); + + /** + * 软件摘机 + * + * @param uboxHnd + * 设备句柄 + * @return 0成功 说明:Fi3101A 和Fi3102A才具有该功能 + */ + public static native int ubox_soft_hook_off(int uboxHnd); + + /** + * 软件挂机 + * + * @param uboxHnd + * 设备句柄 + * @return 0成功 说明:Fi3101A 和Fi3102A才具有该功能 + */ + public static native int ubox_soft_hook_on(int uboxHnd); + + /** + * 设置忙音参数 + * + * @param uboxHnd + * 设备句柄 + * @param dual_frequency + * 是否是双音频,默认为0 + * @param frequency0 + * 忙音频率0,默认为450HZ + * @param frequency1 + * 忙音频率1,默认420HZ + * @param busy_on + * 忙音周期的持续时间,默认为35表示350ms + * @param busy_off + * 忙音周期的断续时间,默认为35表示350ms + * @param on_off_error + * 忙音周期的持续时间和断续时间的误差,默认为5表示50ms + * @param enery_gate + * 忙音的能量,默认为12db + * @param period_count + * 忙音判断的周期数,默认为3,表示连续检测到三个周期的忙音才报告有忙音UBOX_EVENT_DEVICE_BUSY_TONE事件 + * @return 0成功 说明:Fi3101A 和Fi3102A才具有该功能 + */ + public static native int ubox_set_busy_tone(int uboxHnd, + int dual_frequency, int frequency0, int frequency1, int busy_on, + int busy_off, int on_off_error, int enery_gate, int period_count); + + /** + * 设置留言模式参数 + * + * @param uboxHnd + * 设备句柄 + * @param bset + * true打开留言参数,false关闭留言参数 + * @return 0成功 说明:设置留言模式下才需要打开留言参数。要退出留言模式,必须关闭留言参数,否则麦克风不能用Fi3101A才具有该功能 + */ + public static native int ubox_set_message_param(int uboxHnd, boolean bset); + + /** + * 打开/关闭蜂鸣器 + * + * @param uboxHnd + * 设备句柄 + * @param bset + * true 打开蜂鸣器,false 关闭蜂鸣器。该功能的用于没有接电话机只接耳麦时,当振铃时蜂鸣器响,提示用户 + * @return 0成功 说明:Fi3101A才具有该功能 + */ + public static native int ubox_open_buzzer_switch(int uboxHnd, boolean bset); + + /** + * 打开日志文件,记录底层的工作信息 + * + * @param level + * 0记录所有日志信息,1记录错误和警告信息,该函数可以在调用ubox_open之前调用 + * 说明:调用这个函数后,在应用程序目录下会产生一个ubox-log目录,在该目录下会生成日志文件 + */ + public static native void ubox_open_logfile(long level); + + /** + * 关闭日志文件 + */ + public static native void ubox_close_logfile(); + + /** + *打开日志文件,该函数可以在调用ubox_open之前调用 + *dir:记录日志文件的路径,如果为空,就是当前程序目录下。 + *level=0, 显示所有日志信息 + *level =1, 显示错误和警告信息显示 + * + * */ + public static native void ubox_open_logfileEx(String strDir, long level); + + + /** + * + 功 能:上传录音文件。 + 参 数:uploadUrl: 上传文件使用的URL(形如192.168.1.1) + paramName: 提交http请求时,上传文件在服务器上名字,可以包括目录,目录必须是存在的。 + uploadFilePath: 待上传的文件全路径(形如D:\\recordFile.wav) + 返 回:上传成功返回0,失败返回负数。 + * + * */ + public static native int ubox_uploadFile(String strUploadUrl, String strParamName, String strUploadFilename); + + + /** + 无线设备发送号码() + * + * @param uboxHnd + * 设备句柄 + * @param phonenumber + * 电话号码 + * @return 0成功 + * 说明:无线设备外呼拨号 + */ + public static native int ubox_makecall(int uboxHnd, String phonenumber); + + + public static native int ubox_reject_call(int uboxHnd); + + public static native int ubox_set_talk_link(int uboxHnd, int mode, int value); //设定通话link 开关 + public static native int ubox_makecallSlic(int uboxHnd, int ringtime, int stopringtime, String phonenumber); + public static native int ubox_set_record_enable(int uboxHnd, int mode, int value); // 设定录音开关 + + + public static native int ubox_gsm_power(int uboxHnd, int value); //0:GSM模块断电, 1:GSM模块上电 + public static native int ubox_gsm_bootkey(int uboxHnd, int value); //1:GSM开机键, 延时按1~2s,在调用释放命令, 0:GSM开机键释放 + + public static native int ubox_feed_slic_polarity(int uboxHnd, int value); //0:slic正向馈电, 1:slic反向馈电 + + /* + + */ + public static native int ubox_send_gsm_cmd(int uboxHnd, String cmd, int len); //发送GSM命令,供调试GSM模块使用 + +/* + * + * + uboxHnd 设备句柄 + phonenumber: 手机电话号码,必须要加国家区号,比如8615907550000 + mode: 0: 短信内容已经用unicode转码, + 1:未转码的数据 + msg: 短信内容 + len: 短信长度 + + */ + public static native int ubox_send_gsm_msg(int uboxHnd, int mode, String phonenumber, String msg, int len); //发短信 + /* + 查询GSM设备可存储短信数目和目前有多少条短信 + */ + public static native int ubox_query_gsm_msg_number(int uboxHnd); + + /* + 按照索引值,该数值通过ubox_query_gsm_msg_number获取, index从1开始,查询GSM设备内短信内容 + + + */ + public static native int ubox_query_gsm_msg(int uboxHnd, int index); //短信内容是unicode方式,需要应用软件再转换 + + public static native int ubox_query_gsm_msgEx(int uboxHnd, int index); //短信内容已经转换为多字节方式 + + /*删除短信数目 + msgtype=0, index是删除单条短信的序号,msgtype为其它值,index设为1 + msgtype=1, 删除所有的已经阅读的短消息 + msgtype=2, 删除所有的已经阅读和发送出去的短消息 + msgtype=3, 删除所有的已经阅读过、已经发送出去的和未发送的短消息 + msgtype=4, 删除所有的短消息 + */ + public static native int ubox_delete_gsm_msg(int uboxHnd, int index, int msgtype); + + //设备是单模,支持双卡,0:选择sim卡1, 1:选择sim卡2 + // 选择卡后,需要给GSM模块断电,上电,然后调用GSM开机键 ubox_gsm_bootkey(1),延时2秒,最后开机键释放ubox_gsm_bootkey(0) + public static native int ubox_select_simcard(int uboxHnd, int simcardno); + + /* + 设置GSM输出和输入音量, + type:0 输入音量 0-10 + type:1:输出音量 0-100 + + */ + public static native int ubox_set_gsm_vol(int uboxHnd, int type, int vol); + + /* + type:0 输入音量 + type:1:输出音量 + 获取GSM输出和输入音量,以事件UBOX_EVENT_GSM_VOL_SIZE通知 + */ + public static native int ubox_get_gsm_vol(int uboxHnd, int type); + + /* + type: 0 耳麦模式, 1:电话机模式 + 设置耳麦和slic电话机工作模式 + type mode + 0 1 耳麦自动模式,有电话呼入,按耳麦线按钮,电话摘机,再按按一次,挂断GSM通话 + 0 0 关闭耳麦自动模式 + + 1 1 话机自动模式,电话呼入,电话机振铃,电话机挂机,挂断GSM通话 + + 1 0 关闭话机自动模式 + */ + + public static native int ubox_set_gsm_work_mode(int uboxHnd, int type, int mode); + + /* + 让GSM模块产生本地定制单音, 用于电话呼入的时候,耳麦里面能够听到声音,提醒有来电 + mode 0 停止播放 + 1 开始播放 + freq 播放单音频率 + periodon 一个周期内播放单音的时长 + periodoff 一个周期内静音的时长 + duration 单音播放总时长,单位为毫秒 + */ + + public static native int ubox_gsm_generate_tone(int uboxHnd, int mode, int freq, int periodon, int periodoff, int duration); + + //加载DLL + static { + + System.out.println(System.getProperty("java.library.path")); + String property = System.getProperty("user.dir"); + System.out.println("property:"+property.replace("\\","/")+"/bin/"); +// String path = PhonicNative.class.getResource("/").toString(); +// path = path.substring(6).replaceAll("%20", " "); +// String path =property.replace("\\","/")+"/bin/"; +// System.out.println(path); + String path = property + "\\bin\\"; + System.out.println(path); + try { + // 包含 "64",即可64位 JDK , 否则 32位 + System.out.println(System.getProperty("java.vm.name")); + System.out.println(System.getProperty("os.arch")); + System.out.println(System.getProperty("sun.arch.data.model")); + if(Integer.parseInt(System.getProperty("sun.arch.data.model")) == 32) //32bit Java + { + System.out.println("load 32bit dll"); + System.load(path + "x86/phonic_ubox.dll"); + System.load(path + "x86/phonic_native.dll"); + System.load(path + "x86/phonic_utool.dll"); + System.load(path + "x86/phonic_utoolI.dll"); + System.load(path + "x86/phonic_utoolII.dll"); + System.load(path + "x86/phonic_utoolIIEx.dll"); + } + else + { + System.out.println("load 64bit dll"); +// System.load( "E:/workspace/ubox-java/api/Demo/bin/x64/phonic_ubox.dll"); +// System.load("E:/workspace/ubox-java/api/Demo/bin/x64/phonic_native.dll"); +// System.load( "E:/workspace/ubox-java/api/Demo/bin/x64/phonic_utool.dll"); +// System.load("E:/workspace/ubox-java/api/Demo/bin/x64/phonic_utoolI.dll"); +// System.load( "E:/workspace/ubox-java/api/Demo/bin/x64/phonic_utooIIl.dll"); + + System.load(path + "x64\\phonic_ubox.dll"); + System.load(path + "x64\\phonic_native.dll"); + System.load(path + "x64\\phonic_utool.dll"); + System.load(path + "x64\\phonic_utoolI.dll"); + System.load(path + "x64\\phonic_utoolII.dll"); + + +// System.loadLibrary(path + "phonic_ubox.dll"); +// System.loadLibrary(path + "phonic_native.dll"); +// System.loadLibrary(path + "phonic_utool.dll"); +// System.loadLibrary(path + "phonic_utoolI.dll"); +// System.loadLibrary(path + "phonic_utooIIl.dll"); + } + //System.load(path + "X86/phonic_ubox"); + //System.load(path + "X86/phonic_native"); + } catch (Exception e) { + e.printStackTrace(); + } + } +} -- libgit2 0.21.2