提交 1fcbfed8dad5e702deb9bf8e10069ea8dac8a8e8

作者 wangyu
1 个父辈 96b89da4

实现实名认证相关页面及逻辑

17.6 KB | 宽: | 高:

26.2 KB | 宽: | 高:

  • 两方对比
  • 交换覆盖
  • 透明覆盖

21.8 KB | 宽: | 高:

27.3 KB | 宽: | 高:

  • 两方对比
  • 交换覆盖
  • 透明覆盖
1   -<!--
2   -info_steps:[
3   - {
4   - label:'',
5   - status:'success'
6   - },
7   - {
8   - label:'',
9   - status:'circle'
10   - }
11   -] 在要引用的文件定义info_steps,并在其wxss中引入ins_info_head.wxss
12   --->
13   -
14   -<template name="ins_info_head">
15   -
16   - <view class="ins_info_head">
17   - <view class="line_s" ></view>
18   - <block wx:if="{{info_steps.length==3 || info_steps.length==2}}" wx:for="{{info_steps}}" >
19   - <view wx:if="{{index==0}}" class="info_steps info_steps_left" >
20   - {{item.label}}
21   - <view class="progress_icon_wrap">
22   - <icon wx:if="{{item.status=='success'}}" type="{{item.status}}" class="progress_icon" size="20" color="#4E8FE7"/>
23   - <icon wx:else type="{{item.status}}" class="progress_icon" size="21" color="#ccc"/>
24   - </view>
25   - </view>
26   - <view wx:elif="{{index==info_steps.length-1}}" class="info_steps info_steps_right" >
27   - {{item.label}}
28   - <view class="progress_icon_wrap">
29   - <icon wx:if="{{item.status=='success'}}" type="{{item.status}}" class="progress_icon" size="20" color="#4E8FE7"/>
30   - <icon wx:else type="{{item.status}}" class="progress_icon" size="21" color="#ccc"/>
31   - </view>
32   - </view>
33   - <view wx:else class="info_steps " >
34   - {{item.label}}
35   - <view class="progress_icon_wrap">
36   - <icon wx:if="{{item.status=='success'}}" type="{{item.status}}" class="progress_icon" size="20" color="#4E8FE7"/>
37   - <icon wx:else type="{{item.status}}" class="progress_icon" size="21" color="#ccc"/>
38   - </view>
39   - </view>
40   - </block>
41   - </view>
42   -</template>
1   -@import "../../lib/weui.wxss";
2   -
3   -
4   -.ins_info_head{
5   - height: 160rpx;
6   - width: 100%;
7   - background-color: #fff;
8   - font-size: 30rpx;
9   - line-height: 32rpx;
10   - display: inline-flex;
11   -}
12   -
13   -.info_steps{
14   - position:relative;
15   - margin: 0 auto;
16   - margin-top: 34rpx;
17   - text-align: center;
18   - width:202rpx; /* ((750-30*2)/4)+30; */
19   -}
20   - .info_steps_left{
21   - margin-left: 0rpx;
22   -}
23   -.info_steps_right{
24   - margin-right: 0rpx;
25   -}
26   -
27   -.progress_icon_wrap{
28   - width: 20px; /* 控件大小固定 */
29   - margin: 16rpx auto;
30   - background: #fff;
31   -}
32   -
33   -.line_s{
34   - position: absolute;
35   - height: 2rpx;
36   - width: 580rpx;
37   - background: #EFEFEF;
38   - left: 85rpx;
39   - top: 80rpx;
40   - margin-top: 10px;
41   -}
42   -
43   -.container {
44   - height: 100%;
45   - display: flex;
46   - flex-direction: column;
47   - align-items: center;
48   - justify-content: space-between;
49   - padding: 200rpx 0;
50   - box-sizing: border-box;
51   -}
\ No newline at end of file
1 1 // pages/main/verify/verify_idcard/verify_idcard.js
  2 +var OSSInit;
  3 +var baseUrl = getApp().globalData.baseUrl;
2 4 Page({
3 5
4 6 /**
5 7 * Page initial data
6 8 */
7 9 data: {
8   -
  10 + facepath: '',
  11 + already_getdata: false,
  12 + front_card_info: {},
  13 + backpath: '',
  14 + back_card_info: {},
  15 + idInfo: {},
9 16 },
10 17
11   - /**
12   - * Lifecycle function--Called when page load
13   - */
14 18 onLoad: function (options) {
  19 + this.initOSS()
  20 + },
  21 +
  22 + initOSS: function () {
  23 + var that = this
  24 + var Authorization = getApp().globalData.Authorization;
  25 + //OSS 上传前init
  26 + wx.showLoading()
  27 + wx.request({
  28 + url: baseUrl + "filemeta/v1/inits",
  29 + header: {
  30 + 'Authorization': Authorization
  31 + },
  32 + method: 'POST',
  33 + data: {
  34 + "access_type": "web_upload",
  35 + "action ": "put_object",
  36 + "instance_id": "",
  37 + "object_type": "wx_image"
  38 + },
  39 + success: function (result) {
15 40
  41 + OSSInit = result.data
  42 + console.log(' OSS init 成功', OSSInit)
  43 + },
  44 + fail: function (res) {
  45 + console.log('OSS init 失败', res)
  46 + },
  47 + complete: function () {
  48 + wx.hideLoading()
  49 + }
  50 + })
16 51 },
17 52
18 53 /**
19   - * Lifecycle function--Called when page is initially rendered
  54 + * 生命周期函数--监听页面初次渲染完成
20 55 */
21 56 onReady: function () {
22 57
23 58 },
24 59
25 60 /**
26   - * Lifecycle function--Called when page show
  61 + * 生命周期函数--监听页面显示
27 62 */
28 63 onShow: function () {
  64 + console.log('onShow')
  65 + },
  66 +
  67 + chooseImage: function (e) {
  68 + console.log(e)
  69 + var that = this
  70 + wx.chooseImage({
  71 + sourceType: ['camera', 'album'],
  72 + // sizeType: ['original'],
  73 + count: 1,
  74 + success: function (res) {
  75 + console.log('success', res)
  76 + if ("id_face" == e.currentTarget.id) {
  77 + that.setData({
  78 + facepath: res.tempFilePaths[0]
  79 + })
  80 + that.uploadImage(that.data.facepath, 'id_face')
  81 + } else if ("id_back" == e.currentTarget.id) {
  82 + that.setData({
  83 + backpath: res.tempFilePaths[0]
  84 + })
  85 + that.uploadImage(that.data.backpath, 'id_back')
  86 + }
  87 + }
  88 + })
  89 + },
  90 +
  91 + uploadImage: function (path, str) {
  92 + var that = this
  93 + wx.showLoading({
  94 + title: '上传图片中...',
  95 + })
  96 + console.log('key', 'imagepath_' + path.substring(path.length - 10, path.length))
  97 + wx.uploadFile({
  98 + url: getApp().globalData.OSSUrl,
  99 + filePath: path,
  100 + name: 'file',
  101 + formData: {
  102 + 'key': 'imagepath_' + path.substring(path.length - 15, path.length),
  103 + 'OSSAccessKeyId': OSSInit.access_key_id,
  104 + 'policy': OSSInit.policy,
  105 + 'signature': OSSInit.signature,
  106 + 'callback': OSSInit.callback_body,
  107 + 'x:access_token': OSSInit.callback_token,
  108 + // 'x-oss-security-token': OSSInit.security_token,
  109 + 'success_action_status': '200',
  110 + },
  111 + success: function (res) {
  112 + console.log('uploadFile', res.data)
  113 + if (res.statusCode == 200) {
  114 + var data = JSON.parse(res.data)
  115 + console.log('上传成功', res)
  116 + that.oss_bucket = data.bucket
  117 + if ("id_face" == str) {
  118 + that.setData({
  119 + front_card_info: data
  120 + })
  121 + } else if ("id_back" == str) {
  122 + that.setData({
  123 + back_card_info: data
  124 + })
  125 + }
  126 + that.checkAndupload()
  127 + } else {
  128 + var title = '图片上传失败,请重新上传'
  129 + if (res.statusCode == 413) {
  130 + title = '图片体积过大,请选择较小图片上传'
  131 + }
  132 + wx.showModal({
  133 + title: '上传失败',
  134 + content: title,
  135 + showCancel: false,
  136 + confirmColor: '#4E8FE7'
  137 + })
  138 + }
  139 + wx.hideLoading()
  140 + },
  141 + fail: function (err) {
  142 + console.log('fail', err)
  143 + wx.showModal({
  144 + title: '上传失败',
  145 + content: '图片上传失败,请重新上传',
  146 + showCancel: false,
  147 + confirmColor: '#4E8FE7'
  148 + })
  149 + wx.hideLoading()
  150 + },
  151 + complete(res) {
  152 + console.log('complete', res)
  153 + wx.hideLoading()
  154 + }
  155 + })
  156 + },
  157 +
  158 + checkAndupload: function () {
  159 + var that = this
  160 + var frontdata = that.data.front_card_info
  161 + var backdata = that.data.back_card_info
  162 + console.log('frontdata', frontdata)
  163 + console.log('backdata', backdata)
  164 + if (!frontdata || !frontdata.object_id) {
  165 + return;
  166 + }
  167 + if (!backdata || !backdata.object_id) {
  168 + return;
  169 + }
  170 + wx.showLoading({
  171 + title: '解析图片中...',
  172 + })
  173 + var Authorization = getApp().globalData.Authorization;
  174 + wx.request({
  175 + url: baseUrl + 'common/v1/ocr/id-card-verify',
  176 + method: "POST",
  177 + header: {
  178 + 'content-type': 'application/json', // 默认值
  179 + "Authorization": Authorization
  180 + },
  181 + data: {
  182 + front_card_copy: that.data.front_card_info,
  183 + back_card_copy: backdata
  184 + },
  185 + success: function (res) {
  186 + console.log('suc', res)
  187 + if (res.statusCode == 200) {
  188 + that.setData({
  189 + already_getdata: true,
  190 + idInfo: res.data.item
  191 + })
  192 + console.log('suc', that.data.idInfo)
  193 + } else {
  194 + wx.showModal({
  195 + showCancel: false,
  196 + title: '',
  197 + content: res.data.message ? res.data.message : "数据错误",
  198 + })
  199 + }
  200 + },
  201 + fail(res) {
  202 + console.log('fail', res.data)
  203 + },
  204 + complete(res) {
  205 + console.log('complete', res.data)
  206 + wx.hideLoading()
  207 + }
  208 + })
  209 + },
29 210
  211 + gonext: function () {
  212 + if (this.data.already_getdata) {
  213 + //请求数据
  214 + wx.navigateTo({
  215 + url: 'verify_result/verify_result',
  216 + })
  217 + } else {
  218 + wx.showModal({
  219 + showCancel: false,
  220 + title: '',
  221 + content: "未能获取到信息,不能保存",
  222 + })
  223 + }
30 224 },
31 225
32 226 /**
... ...
  1 +<view class='page'>
  2 +
  3 + <view style='display:flex;flex-direction:row;background:#fff'>
  4 + <!--左边 身份信息 -->
  5 + <view style='margin:40rpx 0 30rpx 130rpx'>
  6 + <view style='display:flex;flex-direction:row;height:48rpx;width:100%;'>
  7 + <image style='margin-left:30rpx; width: 24px;height: 24px' src='/images/step_first_blue.png'></image>
  8 + <view style='background:#357aeb;width:90px;height:4rpx;align-self:center;'></view>
  9 + </view>
  10 + <view style='font-size: 17px;color: #000;margin-top:16rpx'>身份信息</view>
  11 + </view>
  12 + <!--右边 上传证件照 -->
  13 + <view style='margin:40rpx 100rpx 30rpx 0'>
  14 + <view style='display:flex;flex-direction:row;height:48rpx;width:100%;'>
  15 + <view style='background:#357aeb;width:90px;height:4rpx;align-self:center;'></view>
  16 + <image style='margin-right:30rpx; width: 24px;height: 24px' src='/images/step_second_blue.png'></image>
  17 + </view>
  18 + <view style='font-size: 17px;color: #000;margin-top:16rpx;text-align:right'>上传证件照</view>
  19 + </view>
  20 + </view>
  21 +
  22 + <view class='id_background' bindtap="chooseImage" id='id_face'>
  23 + <image class='id_image_wrap' src="{{facepath?facepath:'/images/id_face.png'}}"></image>
  24 + </view>
  25 + <view class='id_background' bindtap="chooseImage" id='id_back'>
  26 + <image class='id_image_wrap' src="{{backpath?backpath:'/images/id_back.png'}}"></image>
  27 + </view>
  28 +
  29 + <view style='background-color:#fff;padding:0 32rpx ;'>
  30 + <view class='item_body'>
  31 + <text class='text_666_28 float_left'>签发机关</text>
  32 + <text class='text_333_28 float_right'>{{idInfo.issued_by}}</text>
  33 + </view>
  34 + <view class="divide_line"></view>
  35 + <view class='item_body'>
  36 + <text class='text_666_28 float_left'>有效期</text>
  37 + <text class='text_333_28 float_right'>{{idInfo.valid_date}}</text>
  38 + </view>
  39 + </view>
  40 +
  41 + <view class='bottom_btn_wrap'>
  42 + <view class='btn_blue_radius' bindtap="gonext">
  43 + <view class='text_white_34'>提交</view>
  44 + </view>
  45 + </view>
  46 +</view>
\ No newline at end of file
... ...
  1 +.page {
  2 + background: #f8f8f8;
  3 +}
  4 +
  5 +.id_background{
  6 + width: 100%;
  7 + height: 380rpx;
  8 + display: flex;
  9 + align-items: center;
  10 + background-color: #fff;
  11 +}
  12 +
  13 +.id_image_wrap{
  14 + width: 540rpx;
  15 + height: 312rpx;
  16 + margin-left: 110rpx;
  17 + margin-right: 110rpx;
  18 +}
  19 +
  20 +
  21 +.item_body {
  22 + width: 100%;
  23 + height: 80rpx;
  24 +}
  25 +
  26 +.text_666_28 {
  27 + font-family: PingFangSC-Regular;
  28 + font-size: 28rpx;
  29 + color: #666;
  30 + line-height: 80rpx;
  31 +}
  32 +
  33 +.text_333_28 {
  34 + font-family: PingFangSC-Regular;
  35 + font-size: 28rpx;
  36 + color: #333;
  37 + text-align: right;
  38 + line-height: 80rpx;
  39 +}
  40 +
  41 +.bottom_btn_wrap{
  42 + background: #FFFFFF;
  43 + box-shadow: 0 -2px 8px 0 rgba(208,208,208,0.30);
  44 + height: 136rpx;
  45 + width: 100%;
  46 + position: fixed;
  47 + bottom: 0;
  48 +}
  49 +.btn_blue_radius{
  50 + margin: 26rpx 30rpx;
  51 + background: #357AEB;
  52 + border-radius: 5px;
  53 + height: 84rpx;
  54 +}
  55 +
  56 +.text_white_34 {
  57 + font-family: PingFangSC-Regular;
  58 + font-size: 17px;
  59 + color: #FFFFFF;
  60 + text-align: center;
  61 + line-height: 42px;
  62 +}
\ No newline at end of file
... ...
1 1 // pages/main/verify/verify_info.js
2   -Page({
3 2
  3 +Page({
4 4 /**
5 5 * Page initial data
6 6 */
7 7 data: {
8   - is_foreigner:false,
9   - btn_text:"下一步",
  8 + is_foreigner: false,
  9 + btn_text: "下一步",
10 10 info_steps: [
11 11 {
12 12 label: '身份信息',
... ... @@ -16,16 +16,19 @@ Page({
16 16 status: 'circle'
17 17 }
18 18 ],
  19 + cardTypeArray: ['中国护照', '港澳居民来往内地通行证', '港澳居民居住证', '台湾居民来往大陆通行证', '台湾居民居住证', '外国护照', '外国人永久居留身份证', '外国人工作许可证(A类)', '外国人工作许可证(B类)', '外国人工作许可证(C类)'],
  20 + cardtype: "",
  21 + card_number:""
19 22 },
20 23
21 24 /**
22 25 * Lifecycle function--Called when page load
23 26 */
24 27 onLoad: function (options) {
25   - console.log("options",options);
  28 + console.log("options", options);
26 29 this.setData({
27   - is_foreigner:options.foreigner,
28   - btn_text:"true"==options.foreigner?"提交":"下一步"
  30 + is_foreigner: options.foreigner,
  31 + btn_text: "true" == options.foreigner ? "提交" : "下一步"
29 32 })
30 33 },
31 34
... ... @@ -43,17 +46,80 @@ Page({
43 46
44 47 },
45 48
46   - gonext:function(){
47   - if(this.data.is_foreigner){
48   - wx.showToast({
49   - title: '提交成功',
50   - icon: "none",
51   - duration: 2000
52   - })
53   - wx.navigateBack({})
54   - }else{
  49 + bindCardtypeChange: function (e) {
  50 + console.log("bindCardtypeChange", e)
  51 + var cardTypeArray = this.data.cardTypeArray
  52 + var new_type = cardTypeArray[e.detail.value] //['name']
  53 + if ((new_type.indexOf('外国人') != -1) && (selected.indexOf('外国人') != -1)) {
  54 + console.log('外国人', new_type, selected)
  55 + } else {
  56 +
  57 + }
  58 + this.setData({
  59 + cardtype: new_type
  60 + })
  61 + },
  62 +
  63 + bindinputcardnum: function (e) {
  64 + var idCardNo = e.detail.value
  65 + this.setData({
  66 + card_number: idCardNo
  67 + })
  68 + if (e.detail.value.length == 18) {
  69 + if (!this.data.is_foreigner && !format.isIDCardNum(idCardNo)) {
  70 + this.showtoast('证照号码有误');
  71 + return;
  72 + }
  73 + if (this.data.cardtypeData.selected.indexOf('居住证') > -1 && !reg_18_Number.test(idCardNo)) {
  74 + this.showtoast('证照号码有误');
  75 + return
  76 + }
  77 + }
  78 + if (e.detail.value.length == 9) {
  79 + if (this.data.cardtypeData.selected.indexOf('中国护照') > -1 && !reg_9_n_a.test(idCardNo)) {
  80 + this.showtoast('证照号码有误');
  81 + return
  82 + }
  83 + }
  84 + if (e.detail.value.length == 15) {
  85 + if (this.data.cardtypeData.selected.indexOf('永久居留') > -1 && !reg_15_n_a.test(idCardNo)) {
  86 + this.showtoast('证照号码有误');
  87 + return
  88 + }
  89 + }
  90 + },
  91 +
  92 + dealCardType: function () {
  93 + //证照类型不一样,对应的姓名证照号码验证规则也不一样
  94 + var type = this.data.cardtype;
  95 + console.log('cardtype', type)
  96 + var idCardNo = this.data.card_number;
  97 + if (type.indexOf('居住证') > -1 && !reg_18_Number.test(idCardNo)) {
  98 + this.showtoast('证照号码有误');
  99 + return
  100 + }
  101 + if (type.indexOf('中国护照') > -1 && !reg_9_n_a.test(idCardNo)) {
  102 + this.showtoast('证照号码有误');
  103 + return
  104 + }
  105 + if (type.indexOf('永久居留') > -1 && !reg_15_n_a.test(idCardNo)) {
  106 + this.showtoast('证照号码有误');
  107 + return
  108 + }
  109 + },
  110 +
  111 + gonext: function () {
  112 + if (this.data.is_foreigner=='true') {
  113 + this.dealCardType()
  114 + wx.showToast({
  115 + title: '提交成功',
  116 + icon: "none",
  117 + duration: 2000
  118 + })
  119 + wx.navigateBack({})
  120 + } else {
55 121 wx.navigateTo({
56   - url: 'verify_result/verify_result',
  122 + url: 'verify_idcard/verify_idcard',
57 123 })
58 124 }
59 125 },
... ...
  1 +
1 2 <view class='page'>
2 3 <view style='background:#FDFBEA;height:96rpx;width:100%;text-align:center'>
3 4 <text style='font-size:30rpx;color:#E47C4A;font-family:PingFang-SC-Medium;line-height:96rpx'>为了您的账户安全,请先完成实名认证</text>
4 5 </view>
5 6
6   - <view hidden="{{is_foreigner}}" style='display:flex;flex-direction:row;'>
7   - <!--左边 身份信息 -->
8   - <view style='margin:40rpx 0 30rpx 130rpx'>
9   - <view style='display:flex;flex-direction:row;height:48rpx;width:100%;'>
10   - <image style='margin-left:30rpx; width: 24px;height: 24px' src='/images/step_first_blue.png'></image>
11   - <view style='background:#357aeb;width:90px;height:4rpx;align-self:center;'></view>
  7 + <view hidden="{{is_foreigner=='true'}}">
  8 + <view style='display:flex;flex-direction:row;'>
  9 + <!--左边 身份信息 -->
  10 + <view style='margin:40rpx 0 30rpx 130rpx'>
  11 + <view style='display:flex;flex-direction:row;height:48rpx;width:100%;'>
  12 + <image style='margin-left:30rpx; width: 24px;height: 24px' src='/images/step_first_blue.png'></image>
  13 + <view style='background:#357aeb;width:90px;height:4rpx;align-self:center;'></view>
  14 + </view>
  15 + <view style='font-size: 17px;color: #000;margin-top:16rpx'>身份信息</view>
12 16 </view>
13   - <view style='font-size: 17px;color: #000;margin-top:16rpx'>身份信息</view>
14   - </view>
15   - <!--右边 上传证件照 -->
16   - <view style='margin:40rpx 100rpx 30rpx 0'>
17   - <view style='display:flex;flex-direction:row;height:48rpx;width:100%;'>
18   - <view style='background:#bcc3c7;width:90px;height:4rpx;align-self:center;'></view>
19   - <image style='margin-right:30rpx; width: 24px;height: 24px' src='/images/step_second_gray.png'></image>
  17 + <!--右边 上传证件照 -->
  18 + <view style='margin:40rpx 100rpx 30rpx 0'>
  19 + <view style='display:flex;flex-direction:row;height:48rpx;width:100%;'>
  20 + <view style='background:#bcc3c7;width:90px;height:4rpx;align-self:center;'></view>
  21 + <image style='margin-right:30rpx; width: 24px;height: 24px' src='/images/step_second_gray.png'></image>
  22 + </view>
  23 + <view style='font-size: 17px;color: #999;margin-top:16rpx;text-align:right'>上传证件照</view>
20 24 </view>
21   - <view style='font-size: 17px;color: #999;margin-top:16rpx;text-align:right'>上传证件照</view>
22 25 </view>
23 26 </view>
24 27
25   -
26 28 <view style='width: 100%;height: auto;flex-direction: column;display: flex;'>
  29 + <view hidden="{{is_foreigner=='false'}}">
  30 + <picker bindchange="bindCardtypeChange" value="{{index}}" range="{{cardTypeArray}}">
  31 + <view style='height:90rpx;padding:0 30rpx '>
  32 + <text style='color:#777;font-size: 30rpx;line-height: 90rpx; float:left'>证照类型</text>
  33 + <image class='arrow_wrap' src='/images/arrow_right.png' style='margin-top:26rpx'></image>
  34 + <text wx:if="{{cardtype.length<1}}" class='text_999_30 float_right' style="line-height: 90rpx;">请选择</text>
  35 + <text wx:else style='color:#333;font-size: 30rpx;line-height: 90rpx; float:right'>{{cardtype}}</text>
  36 + </view>
  37 + </picker>
  38 + <view class="divide_line_30"></view>
  39 + </view>
27 40
28 41 <view style='padding-left: 30rpx;padding-right: 30rpx;'>
29 42 <text class='text_777_30 float_left' style='line-height: 90rpx'>姓名</text>
... ... @@ -34,7 +47,7 @@
34 47 <view style='padding-left: 30rpx;padding-right: 30rpx;'>
35 48 <text class='text_777_30 float_left' style='line-height: 90rpx'>身份证件号码</text>
36 49
37   - <input class='input_wrap' placeholder='请输入您的身份证号码' placeholder-class='text_999_30' name='id_card_no' maxlength='18' bindinput="idChange" type='idcard'></input>
  50 + <input class='input_wrap' placeholder='请输入您的身份证号码' placeholder-class='text_999_30' name='id_card_no' maxlength='18' bindinput = 'bindinputcardnum'type='idcard'></input>
38 51 </view>
39 52 </view>
40 53
... ...
注册登录 后发表评论