Selaa lähdekoodia

增加读卡插件,优化取缓存处理

guohh 3 vuotta sitten
vanhempi
commit
5dbfaeb5a4
3 muutettua tiedostoa jossa 205 lisäystä ja 42 poistoa
  1. 135 39
      2021/nm-zsyt/ipu/android-webview.js
  2. 47 2
      2021/nm-zsyt/ipu/ipu-mobile.js
  3. 23 1
      2021/nm-zsyt/project.html

+ 135 - 39
2021/nm-zsyt/ipu/android-webview.js

@ -2,16 +2,102 @@
2 2
(function () {
3 3
  // 依赖IPU框架js:需要先引入ipu-mobile.js
4 4
5
  // 全局缓存key
6
  var cacheDeviceTypeKey = 'cardreader_type';
7
  var cacheConnectTypeKey = 'cardreader_connection';
5
  // 身份证设备连接配置缓存key
6
  var cardDeviceTypeKey = 'cardreader_type';  // 身份证读取设备类型缓存key
7
  var cardConnectTypeKey = 'cardreader_type'; // 身份证读取设备连接方式缓存key
8 8
9
  // 全局缓存数据
10
  var cacheDeviceType = null;
11
  var cacheConnectType = null;
9
  // SIM设备连接配置缓存key
10
  var simDeviceTypeKey = 'simreader_type';     // sim读取设备类型缓存key
11
  var simConnectTypeKey = 'simreader_connection';  // sim读取设备连接类型缓存key
12
  var simBtAddress = 'simreader_btn_address';      // sim读取蓝牙设备地址缓存key
12 13
13 14
  window.AndroidWebView = {
14 15
    /**
16
     * 设置读卡器类型
17
     * @param {string} type 读卡器类型,SR/SYD/ZYZX分别代表森锐/三元达/中移在线
18
     */
19
    setCardReaderType: function (type) {
20
      IpuMobile.setOfflineCache(cardDeviceTypeKey, type);
21
    },
22
23
    /**
24
     * 设置读卡器连接方式
25
     * @param {string} connection 连接方式 bt\otg\nfc
26
     */
27
    setCardReaderConnection: function (connection) {
28
      IpuMobile.setOfflineCache(cardConnectTypeKey, connection);
29
    },
30
31
    /**
32
     * 设置sim读卡器设备类型
33
     * @param {string} deviceType 设备类型
34
     */
35
    setSIMReaderDeviceType: function (deviceType) {
36
      IpuMobile.setOfflineCache(simDeviceTypeKey, deviceType);
37
    },
38
39
    /**
40
     * 设置sim读卡器连接方式
41
     * @param {string} connectType 设备连接方式
42
     */
43
    setSimReaderConnection: function (connectType) {
44
      IpuMobile.setOfflineCache(simConnectTypeKey, connectType);
45
    },
46
47
    /**
48
     * 设置sim读卡器蓝牙地址,可通过 AndroidWebView.btDeviceList()获取
49
     * @param {string} btnAddress 蓝牙设备地址
50
     */
51
    setSimReaderBtnAddress: function (btnAddress) {
52
      IpuMobile.setOfflineCache(simBtAddress, btnAddress);
53
    },
54
55
    /**
56
     * 读取身份证读卡器设备连接配置,蓝牙参数在设备驱动中配置不用传参
57
     *
58
     * @param {function} callback 回调函数
59
     * @param {string} callback.deviceType 设备类型
60
     * @param {string} callback.connectType 连接类型
61
     */
62
    getCardReaderConfig: function (callback) {
63
      IpuMobile.getOfflineCache(function (cacheResult) {  // deviceType, connectType存储在缓存,不直接通过调用传递参数
64
        cacheResult = JSON.parse(cacheResult);
65
        var deviceType = cacheResult[cardDeviceTypeKey];
66
        var connectType = cacheResult[cardConnectTypeKey];
67
        callback(deviceType, connectType);
68
      }, [cardDeviceTypeKey, cardConnectTypeKey]);
69
    },
70
71
    /**
72
     * 读取SIm蓝牙设备连接配置
73
     *
74
     * @param {function} callback 回调函数
75
     * @param {string} callback.deviceType 设备类型
76
     * @param {string} callback.connectType 连接类型
77
     * @param {string} callback.btnAddress 设备蓝牙地址
78
     */
79
    getSimReaderConfig: function (callback) {
80
      // 如需使用js内存缓存,可修改此方法,不用每次读取App缓存
81
      IpuMobile.getOfflineCache(function (cacheResult) {  // deviceType, connectType存储在缓存,不直接通过调用传递参数
82
        cacheResult = JSON.parse(cacheResult);
83
        var deviceType = cacheResult[simDeviceTypeKey];
84
        var connectType = cacheResult[simConnectTypeKey];
85
        var btnAddress = cacheResult[simBtAddress];
86
        callback(deviceType, connectType, btnAddress);
87
      }, [simDeviceTypeKey, simConnectTypeKey, simBtAddress]);
88
    },
89
90
    /**
91
     * 获取蓝牙设备地址
92
     *
93
     * @param {function} callback 获取蓝牙回调函数
94
     * @param {string} callback.result 蓝牙设备地址信息
95
     */
96
    btDeviceList: function (callback) {
97
      IpuMobile.btDeviceList(callback);
98
    },
99
100
    /**
15 101
     * 获取客户端版本信息
16 102
     *
17 103
     * @param {function} callback 回调函数
@ -72,7 +158,7 @@
72 158
     */
73 159
    getLocation: function (callback) {  //
74 160
      IpuMobile.location(function (result) {
75
        result = JSON.parse(result)
161
        result = JSON.parse(result);
76 162
        var info = {
77 163
          address: result.Address,
78 164
          lon: result.Longitude,
@ -109,22 +195,6 @@
109 195
    },
110 196
111 197
    /**
112
     * 设置读卡器类型
113
     * @param {string} type 读卡器类型,SR/SYD/ZYZX分别代表森锐/三元达/中移在线
114
     */
115
    setCardReaderType: function (type) {
116
      IpuMobile.setOfflineCache(cacheDeviceTypeKey, type);
117
    },
118
119
    /**
120
     * 设置读卡器连接方式
121
     * @param {string} connection 连接方式 bt\otg\nfc
122
     */
123
    setCardReaderConnection: function (connection) {
124
      IpuMobile.setOfflineCache(cacheConnectTypeKey, connection);
125
    },
126
127
    /**
128 198
     * 拍照上传身份证?
129 199
     * 回调方法 getCardAndUpResultList(result)?,参数参考 https://docs.qq.com/sheet/DQXl1Q2JDYW53SHBr?tab=BB08J2
130 200
     *
@ -134,7 +204,7 @@
134 204
     * @param {string} timeStamp 时间戳
135 205
     */
136 206
    getCardAndUp: function (callbackKey, isTakePicture, opId, timeStamp) {
137
      function doFun() {
207
      this.getCardReaderConfig(function (deviceType, connectType) {
138 208
        IpuMobile.getCardAndUp(function (result) { // IPU插件不直接返回json对象,只返回json字符串
139 209
          result = JSON.parse(result);
140 210
          if (result.code && !result.errorCode) { // 客户端返回的字段是code,项目使用字段是errorCode
@ -142,20 +212,8 @@
142 212
          }
143 213
          result.CallBackMethod = callbackKey;
144 214
          window.getCardAndUpResultList && window.getCardAndUpResultList(result);
145
        }, cacheDeviceType, cacheConnectType, isTakePicture, opId, timeStamp);
146
      }
147
148
      // 注释代码后,每次deviceType, connectType都重新从缓存获取,不在内存中缓存
149
      // if (!cacheDeviceType) { // 有缓存数据
150
      IpuMobile.getOfflineCache(function (cacheResult) {  // deviceType, connectType存储在缓存,不直接通过调用传递参数
151
        cacheResult = JSON.parse(cacheResult);
152
        cacheDeviceType = cacheResult[cacheDeviceTypeKey];
153
        cacheConnectType = cacheResult[cacheConnectTypeKey];
154
        doFun()
155
      }, [cacheDeviceTypeKey, cacheConnectTypeKey]);
156
      // } else {
157
      //   doFun();
158
      // }
215
        }, deviceType, connectType, isTakePicture, opId, timeStamp);
216
      });
159 217
    },
160 218
161 219
    /**
@ -192,8 +250,9 @@
192 250
        window.getAizhiResult && window.getAizhiResult(result);
193 251
      });
194 252
    },
253
195 254
    /**
196
     * 读卡
255
     * 读卡(好像变动了)
197 256
     * 回调方法 getCardInfoResult,参数参考 https://docs.qq.com/sheet/DQXl1Q2JDYW53SHBr?tab=BB08J2
198 257
     *
199 258
     */
@ -210,7 +269,44 @@
210 269
     */
211 270
    openFile: function (path, sid) {
212 271
272
    },
273
274
    /**
275
     * 读取SIM卡空卡序列号
276
     *
277
     * @param {function} callback 回调函数
278
     * @param {string} callback.result 空卡序列号
279
     */
280
    getCardSN: function (callback) {
281
      this.getSimReaderConfig(function (deviceType, connectType, btnAddress) {
282
        IpuMobile.getCardSN(callback, deviceType, connectType, {btnAddress: btnAddress});
283
      });
284
    },
285
286
    /**
287
     * 读取SIM卡ICCID信息
288
     *
289
     * @param {function} callback 回调函数
290
     * @param {string} callback.result ICCID信息
291
     */
292
    getICCID: function (callback) {
293
      this.getSimReaderConfig(function (deviceType, connectType, btnAddress) {
294
        IpuMobile.getICCID(callback, deviceType, connectType, {btnAddress: btnAddress});
295
      });
296
    },
297
298
    /**
299
     * 读取SIM卡IMSI信息
300
     *
301
     * @param {function} callback 回调函数
302
     * @param {string} callback.result IMSI信息
303
     */
304
    getIMSI: function (callback) {
305
      this.getSimReaderConfig(function (deviceType, connectType, btnAddress) {
306
        IpuMobile.getIMSI(callback, deviceType, connectType, {btnAddress: btnAddress});
307
      });
213 308
    }
309
214 310
  };
215 311
216 312
})();

+ 47 - 2
2021/nm-zsyt/ipu/ipu-mobile.js

@ -232,7 +232,8 @@
232 232
      /**
233 233
       * 获取蓝牙设备地址
234 234
       *
235
       * @param callback
235
       * @param {function} callback 获取蓝牙回调函数
236
       * @param {string} callback.result 蓝牙设备地址信息
236 237
       */
237 238
      btDeviceList: function (callback) {
238 239
        storageCallback("btDeviceList", callback);
@ -261,8 +262,52 @@
261 262
       * @param {function} callback 回调函数
262 263
       */
263 264
      upAizhiInfo: function (jsonStr, callback) {
264
        if (typeof callback === "function") storageCallback("upAizhiInfo", callback);
265
        if (typeof callback === "function"){
266
          storageCallback("upAizhiInfo", callback);
267
        }
265 268
        execute("upAizhiInfo", [jsonStr]);
269
      },
270
271
      /**
272
       * 读取SIM卡空卡序列号
273
       *
274
       * @param {function} callback 回调函数
275
       * @param {string} callback.result 空卡序列号
276
       * @param {string} deviceType
277
       * @param {string} connectType
278
       * @param {string} extraParams json字符串,其它参数
279
       */
280
      getCardSN: function (callback, deviceType, connectType, extraParams) {
281
        storageCallback("getCardSN", callback);
282
        execute("getCardSN", [deviceType, connectType, extraParams]);
283
      },
284
285
      /**
286
       * 读取SIM卡ICCID
287
       *
288
       * @param {function} callback 回调函数
289
       * @param {string} callback.result ICCID
290
       * @param {string} deviceType
291
       * @param {string} connectType
292
       * @param {string} extraParams json字符串,其它参数
293
       */
294
      getICCID: function (callback, deviceType, connectType, extraParams) {
295
        storageCallback("getICCID", callback);
296
        execute("getICCID", [deviceType, connectType, extraParams]);
297
      },
298
299
      /**
300
       * 读取SIM卡IMSI
301
       *
302
       * @param {function} callback 回调函数
303
       * @param {string} callback.result IMSI
304
       * @param {string} deviceType
305
       * @param {string} connectType
306
       * @param {string} extraParams json字符串,其它参数
307
       */
308
      getIMSI: function (callback, deviceType, connectType, extraParams) {
309
        storageCallback("getIMSI", callback);
310
        execute("getIMSI", [deviceType, connectType, extraParams]);
266 311
      }
267 312
    };
268 313
  })();

+ 23 - 1
2021/nm-zsyt/project.html

@ -93,6 +93,7 @@
93 93
        });
94 94
      });
95 95
96
96 97
      $(".card").click(function () {    // 读身份证
97 98
        AndroidWebView.getIdCardInfo('getIdCardInfoBack');
98 99
      });
@ -105,11 +106,28 @@
105 106
        AndroidWebView.getCardAndUp('getCardAndUpBack', 1, '111', Date.now() + '');
106 107
      });
107 108
108
109 109
      $(".aizhi").click(function () {    // AiZhi无纸化订单上传
110 110
        AndroidWebView.upAizhiInfo(aizhiStr);
111 111
      });
112 112
113
      $(".sim-sn").click(function () {    // 读sim卡序列号
114
        AndroidWebView.getCardSN(function (result) {
115
          $(".result").html("sim卡sn:" + JSON.stringify(result));
116
        });
117
      });
118
119
      $(".sim-iccid").click(function () {    // 读sim卡iccid
120
        AndroidWebView.getICCID(function (result) {
121
          $(".result").html("sim卡iccid:" + JSON.stringify(result));
122
        });
123
      });
124
125
      $(".sim-imsi").click(function () {    // 读sim卡imsi
126
        AndroidWebView.getIMSI(function (result) {
127
          $(".result").html("sim卡imsi:" + JSON.stringify(result));
128
        });
129
      });
130
113 131
    });
114 132
  </script>
115 133
</head>
@ -123,6 +141,10 @@
123 141
  <button class="phone isok">拍照</button>
124 142
  <button class="phoneupload isok">拍照上传</button>
125 143
  <button class="aizhi isok">AiZhi无纸化</button>
144
  <button class="sim-sn isok">sim卡序列号</button>
145
  <button class="sim-iccid isok">sim卡ICCID</button>
146
  <button class="sim-imsi isok">sim卡IMSI</button>
147
  <br>
126 148
  <button class="down">下载</button>
127 149
  <button class="sim">SIM卡写卡</button>
128 150
  <button class="card-write">携转写卡</button>