Переглянути джерело

Merge branch 'master' of http://git.ds-bay.com/project/idcard_reader_web

csk 5 роки тому
батько
коміт
5b444a8186

+ 2 - 1
README.md

@@ -2,7 +2,8 @@
 
 ## 技术
 * python + django + vue + element-ui
-
+* python3.6.8-32位
+* djingo2.2
 ## 配置文件
 * 配置商户信息,与额度查询API通讯密钥、API url配置等
 ```

+ 1 - 1
appfront/src/utils/request-axios.js

@@ -94,7 +94,7 @@ class AxiosService {
 
       // `timeout` 指定请求超时的毫秒数(0 表示无超时时间)
       // 如果请求话费了超过 `timeout` 的时间,请求将被中断
-      timeout: 5000,
+      timeout: 10000,
 
       // `withCredentials` 表示跨域请求时是否需要使用凭证,// 默认的false
       withCredentials: true,

+ 138 - 36
appfront/src/views/limit/index.vue

@@ -1,6 +1,6 @@
 <template>
-  <div class="contains">
-    <h1>年度个人额度</h1>
+  <div class="contains" v-loading="listLoading" element-loading-text="查询中,请稍等...">
+    <h1>e码头供应链-海关跨境电子商务年度个人额度查询</h1>
     <div class="step-contains">
       <el-steps simple space="20%">
         <el-step title="放置身份证" status="finish" icon="el-icon-postcard"></el-step>
@@ -9,14 +9,40 @@
       </el-steps>
     </div>
     <div id="result">
-      <h1>查询结果</h1>
-      <div>{{ name }}</div>
-      <div>{{ idNo }}</div>
-      <div>{{ totalAmount }}</div>
-      <div>{{ innerbalance }}</div>
-      <el-button type="primary" @click="limit_query()">
-        发起服务请求
-      </el-button>
+      <h3>自{{ inceptionDate }}00:00起,至{{ currentDate }}24:00,您的个人额度如下:</h3>
+      <table>
+        <tbody>
+          <tr>
+            <td class="title">姓名:</td>
+            <td class="value">
+              <div>{{ name }}</div>
+            </td>
+            <td rowspan="4">
+              <el-button id="button" type="primary" @click="limit_query()">
+                查&nbsp;&nbsp;&nbsp;&nbsp;询
+              </el-button>
+            </td>
+          </tr>
+          <tr>
+            <td class="title">身份证号:</td>
+            <td class="value">
+              <div>{{ idNo }}</div>
+            </td>
+          </tr>
+          <tr>
+            <td class="title">本年已用金额:</td>
+            <td class="value">
+              <div id="red">{{ totalAmount }}</div>
+            </td>
+          </tr>
+          <tr>
+            <td class="title">本年可用金额:</td>
+            <td class="value">
+              <div id="green">{{ innerBalance }}</div>
+            </td>
+          </tr>
+        </tbody>
+      </table>
     </div>
   </div>
 </template>
@@ -28,11 +54,13 @@ export default {
   name: 'YearLimit',
   data() {
     return {
-      listLoading: true,
+      listLoading: false,
       name: null,
       idNo: null,
       totalAmount: null,
-      innerbalance: null,
+      innerBalance: null,
+      inceptionDate: null,
+      currentDate: null,
       listQuery: {
         page: 1,
         limit: 20,
@@ -42,32 +70,49 @@ export default {
       }
     }
   },
+  mounted() {
+    this.inception_date()
+    this.current_date()
+    this.create_interval()
+  },
   methods: {
     limit_query() {
-      this.listLoading = true
-      getLimit().then(response => {
-        console.log('str' + JSON.stringify(response))
-        // do something
-        if (!response.code) {
-          this.$message.error('[10]查询失败')
-          this.listLoading = false
-          return
-        }
-        if (response.code !== '0') {
-          this.$message.error(response.msg)
+      if (!this.listLoading) {
+        this.listLoading = true
+        getLimit().then(response => {
+          console.log('str' + JSON.stringify(response))
+          // do something
           this.listLoading = false
-          return
-        }
+          if (!response.code) {
+            this.$message.error('[10]查询失败')
+            return
+          }
+          if (response.code !== '0') {
+            this.$message.error(response.msg)
+            return
+          }
 
-        this.name = response.rows[0].data.name
-        this.idNo = response.rows[0].data.id_no
-        this.totalAmount = response.rows[0].data.total_amount
-        this.innerbalance = response.rows[0].data.innerbalance
-        this.listLoading = false
-      }).catch(error => {
-        this.$message.error(error || '数据加载失败')
-        this.listLoading = false
-      })
+          this.name = response.rows[0].data.name
+          this.idNo = response.rows[0].data.id_no
+          this.totalAmount = response.rows[0].data.total_amount + '元'
+          this.innerBalance = response.rows[0].data.innerbalance + '元'
+        }).catch(error => {
+          this.$message.error(error || '数据加载失败')
+          this.listLoading = false
+        })
+      }
+    },
+    inception_date() {
+      var date = new Date()
+      var year = date.getFullYear()
+      this.inceptionDate = year + '年1月1日'
+    },
+    current_date() {
+      var date = new Date()
+      var year = date.getFullYear()
+      var month = date.getMonth() + 1
+      var strDate = date.getDate()
+      this.currentDate = year + '年' + month + '月' + strDate + '日'
     }
   }
 }
@@ -75,9 +120,66 @@ export default {
 
 <style scoped>
   .contains {
-    text-align:center
+    text-align: center;
+  }
+
+  h1 {
+    color: #1890ff;
   }
   .step-contains {
-    width: 60%;margin:0 auto;border:0px solid #000;
+    width: 60%;
+    margin: 0 auto;
+    padding: 3% 0;
+    border: 0px solid #000;
+  }
+  #result {
+    width: 50%;
+    margin: 0 auto;
+  }
+  h3 {
+    font-weight: normal;
+  }
+  table {
+    font-size: 18px;
+    width: 90%;
+    margin: 5% auto;
+  }
+  table td {
+    height: 50px;
+    position: relative;
+    display: table-cell;
+    padding: 0.2% 0;
+  }
+  table td.title {
+    text-align: right;
+    padding: 0 2% 0 0;
+    width: 25%;
+  }
+  table td.value {
+    width: 30%;
+  }
+  table td div {
+    width: 100%;
+    height: 30px;
+    font-family: inherit;
+    font-size: inherit;
+    line-height: inherit;
+    border: solid 1px silver;
+    padding-top: 9px;
+  }
+  table td.value #red {
+    color: red;
+  }
+  table td.value #green {
+    color: green;
+  }
+  table td.value {
+    width: 30%;
+  }
+  #button {
+    width: 100px;
+    height: 120px;
+    margin: 0 50% 0 0;
+    font-size: 16px;
   }
 </style>

+ 6 - 6
apps/limit/biz/config.json

@@ -1,9 +1,9 @@
 {
-  "merchId": "111",
-  "merchName": "商户",
-  "thirdPartyMerchCode": "222",
-  "thirdPartyMerchName": "三方商户",
+  "merchId": "mhbs990053989883052032",
+  "merchName": "中网科技",
+  "thirdPartyMerchCode": "",
+  "thirdPartyMerchName": "",
   "isCheckIdCard": "0",
-  "secret_key": "abc789",
-  "year_limit_url": "http://127.0.0.1:2001/al/cus/yearLimit"
+  "secret_key": "IxyIvP0sJqlUZinx",
+  "year_limit_url": "http://ws.ds-bay.com/al/cus/yearLimit"
 }

+ 16 - 5
apps/limit/biz/id_card_reader.py

@@ -154,16 +154,27 @@ class IdCarReader:
             print("文件内容解码错误,文本长度异常")
             return None
 
-        self.__id_car_info['name'] = content[0:14].strip()
+        # print('身体份证信息:{}'.format(content))
+        # print('name:{}'.format(content[0:15].strip()))
+        # print('sex:{}'.format(content[15]))
+        # print('nation:{}'.format(content[16:18]))
+        # print('born_date:{}'.format(content[18:26]))
+        # print('address:{}'.format(content[26:61].strip()))
+        # print('id_no:{}'.format(content[61:79]))
+        # print('sign_gov:{}'.format(content[79:93].strip()))
+        # print('start_date:{}'.format(content[93:102].strip()))
+        # print('end_date:{}'.format(content[102:128].strip()))
+
+        self.__id_car_info['name'] = content[0:15].strip()
         self.__id_car_info['sex'] = self.__sex_dict[content[15]]
         # 数字要往后多取一位
         self.__id_car_info['nation'] = self.__nation_dict[content[16:18]]
         self.__id_car_info['born_date'] = content[18:26]
-        self.__id_car_info['address'] = content[26:60].strip()
-        self.__id_car_info['id_no'] = content[61:78]
+        self.__id_car_info['address'] = content[26:61].strip()
+        self.__id_car_info['id_no'] = content[61:79]
         self.__id_car_info['sign_gov'] = content[79:93].strip()
-        self.__id_car_info['start_date'] = content[94:102]
-        self.__id_car_info['end_date'] = content[102:127].strip()
+        self.__id_car_info['start_date'] = content[93:102]
+        self.__id_car_info['end_date'] = content[102:128].strip()
         return self.__id_car_info
 
     def __error_print(self, txt):

+ 4 - 3
apps/limit/biz/year_limit_query.py

@@ -38,7 +38,7 @@ class YearLimitQuery:
         merch_param = self.__build_merch_info()
         req_params = {
             "merchId": merch_param["merchId"],
-            "data": str(merch_param),
+            "data": str(json.dumps(merch_param)),
             "timestamp": str(int(time.time()))
         }
         return req_params
@@ -56,7 +56,8 @@ class YearLimitQuery:
             req_url = config_json["year_limit_url"]
             # GET方法,必须是params=str(dict or list or tuple or bytes)
             # POST方法,必须是data=dict or list or tuple or bytes or file
-            response = requests.request("POST", req_url, data=req_params, timeout=20)
+            headers = { "Content-Type": "application/json;charset=UTF-8" }
+            response = requests.request("POST", req_url, headers=headers, data=json.dumps(req_params), timeout=20)
             if response.text:
                 result = json.loads(response.text)
                 print("API返回数据:{}".format(result))
@@ -78,7 +79,7 @@ class YearLimitQuery:
         # 处理返回数据
         if data["code"] == '0':
             limit_data = data["data"]["rows"][0]
-            if limit_data["success"] == "true":
+            if str(limit_data["success"]).lower() == "true":
                 result["totalAmount"] = limit_data["result"]["totalAmount"]
                 result["innerbalance"] = limit_data["result"]["innerbalance"]
                 print("【{},{}】查询额度为:{}".format(self.__name, self.__id_no, data))

+ 7 - 2
apps/limit/views.py

@@ -5,6 +5,7 @@
 # author: Scott Chen
 # date: 2019-12-23
 
+import datetime
 from django.views.decorators.http import require_http_methods
 from django.http import JsonResponse
 
@@ -28,7 +29,8 @@ def limit(request):
 
     response = {}
     data = {}
-
+    start = datetime.datetime.now()
+    print(str(start))
     # 身份证信息读取
     reader = IdCarReader()
     id_car_info = reader.recognize()
@@ -50,12 +52,15 @@ def limit(request):
         return JsonResponse(response)
 
     data['name'] = name
-    data['id_no'] = id_no
+    data['id_no'] = "{0}***********{1}".format(id_no[:4], id_no[-3:])
     data['total_amount'] = year_limit_map['totalAmount']
     data['innerbalance'] = year_limit_map['innerbalance']
 
     response['code'] = '0'
     response['msg'] = '成功'
     response['rows'] = [{'total': 1, 'data': data}]
+    end = datetime.datetime.now()
+    print(str(end))
+    print(end - start)
     return JsonResponse(response)