1
0

checkVideo.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. const util = require('../../utils/util.js');
  2. const api = require('../../config/api.js');
  3. const user = require('../../services/user.js');
  4. //获取应用实例
  5. const app = getApp();
  6. Page({
  7. data: {
  8. // text:"这是一个页面"
  9. videoSource: '',
  10. videoHidden: true,
  11. cameraCtx: null,
  12. src: null,
  13. videoSrc: null,
  14. isStartDisable: null,
  15. isEndDisable: null
  16. },
  17. /**
  18. * 生命周期函数--监听页面初次渲染完成
  19. */
  20. onReady: function (res) {
  21. if (wx.createCameraContext()) {
  22. // this.cameraContext = wx.createCameraContext('myCamera')
  23. // this.takePhoto();
  24. this.cameraContext = wx.createCameraContext()
  25. } else {
  26. // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
  27. wx.showModal({
  28. title: '提示',
  29. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  30. })
  31. }
  32. },
  33. takePhoto() {
  34. var that = this;
  35. const ctx = wx.createCameraContext()
  36. console.log(ctx)
  37. ctx.takePhoto({
  38. quality: 'high',
  39. success: (res) => {
  40. that.setData({
  41. src: res.tempImagePath
  42. })
  43. },
  44. fail: (res) => {
  45. console.log('拍摄失败')
  46. console.log(res)
  47. },
  48. complete: (res) => {
  49. console.log('接口调用结束的回调函数(调用成功、失败都会执行)')
  50. console.log(res)
  51. }
  52. })
  53. },
  54. takeVideo() {
  55. wx.showLoading({
  56. title: '视频录制开始...',
  57. });
  58. var that = this;
  59. // const ctx = wx.createCameraContext()
  60. console.log(that.cameraContext)
  61. that.cameraContext.startRecord({
  62. timeoutCallback: (res) => {
  63. console.log('摄影开始中1')
  64. console.log(res)
  65. that.setData({
  66. isStartDisable: true,
  67. isEndDisable: false
  68. })
  69. },
  70. success: (res) => {
  71. console.log('摄影开始成功2')
  72. console.log(res)
  73. that.setData({
  74. isStartDisable: true,
  75. isEndDisable: false
  76. })
  77. },
  78. fail: (res) => {
  79. console.log('摄影开始失败')
  80. console.log(res)
  81. that.setData({
  82. isStartDisable: false,
  83. isEndDisable: false
  84. })
  85. },
  86. complete: (res) => {
  87. console.log('摄影开始,接口调用结束的回调函数(调用成功、失败都会执行)')
  88. console.log(res)
  89. }
  90. })
  91. },
  92. stopVideo: function () {
  93. wx.hideLoading();
  94. var that = this;
  95. that.cameraContext.stopRecord({
  96. success: (videoRes) => {
  97. console.log('摄影成功2')
  98. console.log(videoRes.tempVideoPath)
  99. that.setData({
  100. isStartDisable: true,
  101. isEndDisable: true,
  102. videoSrc: videoRes.tempVideoPath
  103. })
  104. that.getBase64(videoRes.tempVideoPath);
  105. // util.request(api.CheckLivenessRecognition, {
  106. // storeId: wx.getStorageSync('storeId'),
  107. // merchId: wx.getStorageSync('merchSn'),
  108. // idCard: '',
  109. // name: '',
  110. // videoBase64: 'base64',
  111. // livenessType: 'SILENT'
  112. // }, 'POST').then(function (urlRes) {
  113. // console.log(urlRes);
  114. // // wx.showToast({
  115. // // title: '成功',
  116. // // icon: 'success',
  117. // // duration: 2000
  118. // // })
  119. // wx.showToast({
  120. // title: urlRes.msg,
  121. // icon: 'success'
  122. // })
  123. // });
  124. },
  125. fail: (videoFailRes) => {
  126. console.log('摄影失败')
  127. console.log(videoFailRes)
  128. that.setData({
  129. isStartDisable: false,
  130. isEndDisable: false
  131. })
  132. },
  133. complete: (videoComRes) => {
  134. console.log('接口调用结束的回调函数(调用成功、失败都会执行)')
  135. console.log(videoComRes)
  136. }
  137. });
  138. },
  139. getBase64(path) {
  140. wx.showLoading({
  141. title: '人脸身份核验中...',
  142. });
  143. var that = this;
  144. wx.getFileSystemManager().readFile({
  145. filePath: path,
  146. encoding: "base64",
  147. complete: res => {
  148. // var baseRes = wx.getFileSystemManager().readFileSync(videoRes.tempVideoPath, 'base64')
  149. console.log('base64码');
  150. // console.log(res);
  151. var base64 = res.data;
  152. util.request(api.CheckLivenessRecognition, {
  153. storeId: wx.getStorageSync('storeId'),
  154. merchId: wx.getStorageSync('merchSn'),
  155. idCard: '',
  156. name: '',
  157. videoBase64: base64,
  158. livenessType: 'SILENT'
  159. }, 'POST').then(function (urlRes) {
  160. console.log(urlRes);
  161. if(urlRes.errno!=undefined){
  162. if(urlRes.errno===0){
  163. wx.showToast({
  164. title: '人脸核验成功',
  165. icon: 'success',
  166. duration: 2000
  167. })
  168. }else{
  169. wx.showToast({
  170. title: urlRes.errmsg,
  171. icon: 'none'
  172. });
  173. }
  174. } else {
  175. if (urlRes.code != 0) {
  176. wx.showToast({
  177. title: urlRes.msg,
  178. icon: 'none'
  179. });
  180. that.setData({
  181. isStartDisable: false,
  182. isEndDisable: false
  183. })
  184. }
  185. }
  186. });
  187. },
  188. fail: function (baseFailRes) {
  189. console.log(baseFailRes);
  190. }
  191. });
  192. },
  193. error(e) {
  194. console.log(e.detail)
  195. },
  196. onLoad: function (options) {
  197. // 页面初始化 options为页面跳转所带来的参数
  198. },
  199. onShow: function () {
  200. // 页面显示
  201. },
  202. onHide: function () {
  203. // 页面隐藏
  204. },
  205. onUnload: function () {
  206. // 页面关闭
  207. }
  208. })