face_verify.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. // components/face_verify/face_verify.js
  4. import international from "../../international/appointment_scence/index";
  5. import { foreignAuthentication } from "../../utils/api/make_appointment";
  6. const face = require("../../utils/faceCheck/faceCheck");
  7. const {
  8. throttle
  9. } = require("/utils/throttle/throttle")
  10. // const getThree = require("/utils/getThree/zfb_getThree")
  11. // const getPhone = require("../../utils/getPhone/wx_getPhone");
  12. var verify = require("../../utils/util/util");
  13. const util = require("../../utils/func/request");
  14. const {
  15. isCardID,
  16. isPhone,
  17. isChineseWord,
  18. desensitization,
  19. isCornet
  20. } = require("../../utils/util/util");
  21. const app = getApp();
  22. Component({
  23. options: {
  24. observers: true,
  25. lifetimes: false
  26. },
  27. /**
  28. * 组件的属性列表
  29. */
  30. properties: {
  31. title: {
  32. type: String,
  33. value: "人员信息"
  34. },
  35. language: {
  36. type: String,
  37. value: "ch"
  38. },
  39. isDisabled: {
  40. type: Boolean,
  41. value: false
  42. },
  43. userInfo: {
  44. type: Object
  45. },
  46. companyName: {
  47. value: null
  48. },
  49. type: {
  50. value: null
  51. }
  52. },
  53. /**
  54. * 组件的初始数据
  55. */
  56. data: {
  57. international: international,
  58. //国际化语言包
  59. username: "",
  60. idNumber: "",
  61. phone: "",
  62. userId: null,
  63. avatar: null
  64. },
  65. /**
  66. * 组件的方法列表
  67. */
  68. methods: {
  69. authResult(e) {
  70. if (app.data.language === "ch") {
  71. this.setData({
  72. username: e.detail.username,
  73. idNumber: e.detail.idNumber,
  74. phone: e.detail.phone,
  75. avatar: e.detail.avatar,
  76. userId: e.detail.userId
  77. })
  78. } else {
  79. this.setData({
  80. phone: e.detail.phone
  81. })
  82. }
  83. setTimeout(() => {
  84. this.Certification()
  85. }, 800)
  86. },
  87. goOCR() {
  88. let {
  89. username,
  90. idNumber,
  91. phone
  92. } = this.data;
  93. if (phone) {
  94. this.data.flag = 2;
  95. app.data.phone = phone;
  96. wx.navigateTo({
  97. url: "/pages/ocr/ocr"
  98. });
  99. } else {
  100. wx.showToast({
  101. icon: "none",
  102. title: "Please obtain the phone number first"
  103. });
  104. }
  105. },
  106. /// 认证
  107. Certification() {
  108. let {
  109. username,
  110. idNumber,
  111. phone
  112. } = this.data;
  113. if (app.data.language === "en") {
  114. this.goOCR()
  115. } else {
  116. if (username && idNumber && phone) {
  117. this.submit();
  118. } else {
  119. wx.showToast({
  120. icon: "none",
  121. title: "请将个人信息填写完整!"
  122. });
  123. }
  124. }
  125. },
  126. //实名认证
  127. submit: throttle(function () {
  128. this.doZFBFaceCheck()
  129. }, 5000),
  130. // 微信验证人脸
  131. async doFaceCheck() {
  132. let taskId = wx.getStorageSync("wx_dateCode");
  133. // taskId = '00-883306131355291200';//本地
  134. if (!taskId) return;
  135. let res = await face.getFace_wxrlxf("/api/next/doQueryFaceSuccess", "get", {
  136. taskId: taskId
  137. });
  138. if (res.data.status === true) {
  139. let userInfo = res.data;
  140. wx.setStorageSync("userInfo", userInfo);
  141. app.data.userInfo = userInfo;
  142. this.triggerEvent("certificationState", true);
  143. } else {
  144. this.triggerEvent("certificationState", false);
  145. }
  146. },
  147. //获得姓名
  148. getInputName(e) {
  149. this.setData({
  150. username: e.detail
  151. })
  152. },
  153. //获得身份证号
  154. getInputIdcard(e) {
  155. this.setData({
  156. idNumber: e.detail
  157. })
  158. },
  159. // 输入短号
  160. getInputPhone(e) {
  161. this.setData({
  162. phone: e.detail
  163. })
  164. },
  165. // 支付宝验证人脸
  166. async doZFBFaceCheck() {
  167. let {
  168. username,
  169. idNumber,
  170. phone,
  171. userId
  172. } = this.data;
  173. let res = await face.getFace_wxrlxf("/api/next/ZFBConfirmFace", "post", {
  174. idNumber,
  175. phone,
  176. username,
  177. userId
  178. });
  179. if (res.data.status === true) {
  180. let userInfo = res.data;
  181. userInfo.avatar = this.data.avatar || null
  182. app.data.userInfo = userInfo
  183. // iotVspUniqueId(userInfo.idNumber, userInfo.username, userInfo.phone, userInfo.avatar).then((res) => {
  184. // if(res) {
  185. // this.setCertificationState(true)
  186. // }
  187. // })
  188. this.setCertificationState(true)
  189. } else {
  190. this.setCertificationState(false)
  191. }
  192. },
  193. // 设置授权状态
  194. setCertificationState(isSuccess) {
  195. if(isSuccess) {
  196. wx.setStorageSync("userInfo", app.data.userInfo)
  197. this.triggerEvent("certificationState", true)
  198. } else {
  199. app.data.userInfo = null
  200. this.triggerEvent("certificationState", false)
  201. }
  202. },
  203. // 外宾确认或修改
  204. update() {
  205. let data = {
  206. username: this.data.username,
  207. idNumber: this.data.idNumber,
  208. phone: this.data.phone || app.data.phone,
  209. avatar: this.data.userInfo.avatar,
  210. userId: this.data.userInfo.userId
  211. };
  212. if (data.idNumber && data.phone && data.username) {
  213. foreignAuthentication(data).then(res => {
  214. if (res.code === 200) {
  215. wx.setStorageSync("userInfo", res.data);
  216. app.data.userInfo = res.data;
  217. wx.setStorageSync("language", "cn");
  218. this.triggerEvent("certificationState", true);
  219. } else {
  220. wx.showToast({
  221. icon: "none",
  222. title: res.msg
  223. });
  224. }
  225. });
  226. } else {
  227. wx.showToast({
  228. icon: "none",
  229. title: "Please complete your personal information!"
  230. });
  231. }
  232. },
  233. getAuthCode: function () {
  234. const that = this
  235. getThree((userInfo) => {
  236. if (app.data.language === "ch") {
  237. this.setData({
  238. username: userInfo.data.username,
  239. idNumber: userInfo.data.idNumber,
  240. phone: userInfo.data.phone,
  241. avatar: userInfo.data.avatar,
  242. userId: userInfo.data.userId
  243. })
  244. } else {
  245. this.setData({
  246. phone: userInfo.data.phone
  247. })
  248. }
  249. this.Certification()
  250. })
  251. },
  252. antmoveAction: function () {
  253. //执行时动态赋值,请勿删除
  254. }
  255. },
  256. observers: {
  257. userInfo: function (userInfo) {
  258. if (userInfo) {
  259. this.setData({
  260. username: userInfo.username,
  261. idNumber: userInfo.idNumber,
  262. phone: userInfo.phone,
  263. userId: userInfo.userId,
  264. avatar: userInfo.avatar
  265. });
  266. }
  267. }
  268. },
  269. lifetimes: {
  270. attached: function () {
  271. let userInfo = this.data.userInfo;
  272. if (userInfo) {
  273. this.setData({
  274. username: userInfo.username,
  275. idNumber: userInfo.idNumber,
  276. phone: userInfo.phone,
  277. userId: userInfo.userId
  278. });
  279. }
  280. }
  281. },
  282. pageLifetimes: {
  283. show() {
  284. if (this.data.flag === 1) {
  285. this.data.flag = null;
  286. // this.doFaceCheck();
  287. } else if (this.data.flag === 2) {
  288. this.data.flag = null;
  289. this.triggerEvent("updateState", app.data.temporary_userInfo ? true : false);
  290. }
  291. }
  292. }
  293. // rootEvents: {
  294. // onReady() {
  295. // const that = this
  296. // iotVspInit((res) => {
  297. // that.setCertificationState(res.success)
  298. // my.navigateBack()
  299. // })
  300. // }
  301. // }
  302. })