face_verify.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. // import { iotVspInit, iotVspUniqueId } from '/utils/ioTVsp/index'
  12. // const getPhone = require("../../utils/getPhone/wx_getPhone");
  13. var verify = require("../../utils/util/util");
  14. const util = require("../../utils/func/request");
  15. const {
  16. isCardID,
  17. isPhone,
  18. isChineseWord,
  19. desensitization,
  20. isCornet
  21. } = require("../../utils/util/util");
  22. const app = getApp();
  23. Component({
  24. options: {
  25. observers: true,
  26. lifetimes: false
  27. },
  28. /**
  29. * 组件的属性列表
  30. */
  31. properties: {
  32. title: {
  33. type: String,
  34. value: "人员信息"
  35. },
  36. language: {
  37. type: String,
  38. value: "ch"
  39. },
  40. isDisabled: {
  41. type: Boolean,
  42. value: false
  43. },
  44. userInfo: {
  45. type: Object
  46. },
  47. companyName: {
  48. value: null
  49. },
  50. type: {
  51. value: null
  52. }
  53. },
  54. /**
  55. * 组件的初始数据
  56. */
  57. data: {
  58. international: international,
  59. //国际化语言包
  60. username: "",
  61. idNumber: "",
  62. phone: "",
  63. userId: null,
  64. avatar: null
  65. },
  66. /**
  67. * 组件的方法列表
  68. */
  69. methods: {
  70. authResult(e) {
  71. if (app.data.language === "ch") {
  72. this.setData({
  73. username: e.detail.username,
  74. idNumber: e.detail.idNumber,
  75. phone: e.detail.phone,
  76. avatar: e.detail.avatar,
  77. userId: e.detail.userId
  78. })
  79. } else {
  80. this.setData({
  81. phone: e.detail.phone
  82. })
  83. }
  84. setTimeout(() => {
  85. this.Certification()
  86. }, 800)
  87. },
  88. goOCR() {
  89. let {
  90. username,
  91. idNumber,
  92. phone
  93. } = this.data;
  94. if (phone) {
  95. this.data.flag = 2;
  96. app.data.phone = phone;
  97. wx.navigateTo({
  98. url: "/pages/ocr/ocr"
  99. });
  100. } else {
  101. wx.showToast({
  102. icon: "none",
  103. title: "Please obtain the phone number first"
  104. });
  105. }
  106. },
  107. /// 认证
  108. Certification() {
  109. let {
  110. username,
  111. idNumber,
  112. phone
  113. } = this.data;
  114. if (app.data.language === "en") {
  115. this.goOCR()
  116. } else {
  117. if (username && idNumber && phone) {
  118. //(过审专用,禁止删除)- start
  119. // if (username == "曾英皓" && idNumber == "330821199603150212") {
  120. // app.data.fake = true;
  121. // app.data.userInfo = {
  122. // username: username,
  123. // idNumber: idNumber,
  124. // phone: phone,
  125. // userId: 42553,
  126. // avatar: "../../../static/comment/avator_no.png"
  127. // };
  128. // wx.setStorageSync("userInfo", app.data.userInfo);
  129. // this.triggerEvent("certificationState", true);
  130. // return;
  131. // }
  132. //(过审专用,禁止删除)- end
  133. this.submit();
  134. } else {
  135. wx.showToast({
  136. icon: "none",
  137. title: "请将个人信息填写完整!"
  138. });
  139. }
  140. }
  141. },
  142. //实名认证
  143. submit: throttle(function () {
  144. const that = this
  145. wx.requestSubscribeMessage({
  146. entityIds: ["f72f5029f53e44c6baa45b8a0716ac0c", "9d4ddcd78f66444482ad66c5a262ffed"],
  147. success(res) {
  148. // if(res.behavior === 'subscribe') {
  149. // that.doZFBFaceCheck()
  150. // }
  151. },
  152. complete: res => {
  153. that.doZFBFaceCheck()
  154. }
  155. })
  156. // const that = this;
  157. // let {
  158. // username,
  159. // idNumber,
  160. // phone
  161. // } = this.data;
  162. // let orgId = app.data.adminId;
  163. // face.intoFace_wxrlxf(username, idNumber, phone, orgId = "00").then(() => {
  164. // that.data.flag = 1;
  165. // }).catch(err => {});
  166. // wx.requestSubscribeMessage({
  167. // entityIds: ["f72f5029f53e44c6baa45b8a0716ac0c", "9d4ddcd78f66444482ad66c5a262ffed"],
  168. // success(res) {
  169. // if(res.behavior === 'subscribe') {
  170. // face.intoFace_wxrlxf(username, idNumber, phone, orgId = "00").then(() => {
  171. // that.data.flag = 1;
  172. // }).catch(err => {});
  173. // }
  174. // }
  175. // });
  176. }, 5000),
  177. // 微信验证人脸
  178. async doFaceCheck() {
  179. let taskId = wx.getStorageSync("wx_dateCode");
  180. // taskId = '00-883306131355291200';//本地
  181. if (!taskId) return;
  182. let res = await face.getFace_wxrlxf("/api/next/doQueryFaceSuccess", "get", {
  183. taskId: taskId
  184. });
  185. if (res.data.status === true) {
  186. let userInfo = res.data;
  187. wx.setStorageSync("userInfo", userInfo);
  188. app.data.userInfo = userInfo;
  189. this.triggerEvent("certificationState", true);
  190. } else {
  191. this.triggerEvent("certificationState", false);
  192. }
  193. },
  194. // 支付宝验证人脸
  195. async doZFBFaceCheck() {
  196. let {
  197. username,
  198. idNumber,
  199. phone,
  200. userId
  201. } = this.data;
  202. let res = await face.getFace_wxrlxf("/api/next/ZFBConfirmFace", "post", {
  203. idNumber,
  204. phone,
  205. username,
  206. userId
  207. });
  208. if (res.data.status === true) {
  209. let userInfo = res.data;
  210. userInfo.avatar = this.data.avatar || null
  211. app.data.userInfo = userInfo
  212. // iotVspUniqueId(userInfo.idNumber, userInfo.username, userInfo.phone, userInfo.avatar).then((res) => {
  213. // if(res) {
  214. // this.setCertificationState(true)
  215. // }
  216. // })
  217. this.setCertificationState(true)
  218. } else {
  219. this.setCertificationState(false)
  220. }
  221. },
  222. // 设置授权状态
  223. setCertificationState(isSuccess) {
  224. if(isSuccess) {
  225. wx.setStorageSync("userInfo", app.data.userInfo)
  226. this.triggerEvent("certificationState", true)
  227. } else {
  228. app.data.userInfo = null
  229. this.triggerEvent("certificationState", false)
  230. }
  231. },
  232. // 外宾确认或修改
  233. update() {
  234. let data = {
  235. username: this.data.username,
  236. idNumber: this.data.idNumber,
  237. phone: this.data.phone || app.data.phone,
  238. avatar: this.data.userInfo.avatar,
  239. userId: this.data.userInfo.userId
  240. };
  241. if (data.idNumber && data.phone && data.username) {
  242. foreignAuthentication(data).then(res => {
  243. if (res.code === 200) {
  244. wx.setStorageSync("userInfo", res.data);
  245. app.data.userInfo = res.data;
  246. wx.setStorageSync("language", "cn");
  247. this.triggerEvent("certificationState", true);
  248. } else {
  249. wx.showToast({
  250. icon: "none",
  251. title: res.msg
  252. });
  253. }
  254. });
  255. } else {
  256. wx.showToast({
  257. icon: "none",
  258. title: "Please complete your personal information!"
  259. });
  260. }
  261. },
  262. getAuthCode: function () {
  263. const that = this
  264. // getThree((userInfo) => {
  265. // if (app.data.language === "ch") {
  266. // this.setData({
  267. // username: userInfo.data.username,
  268. // idNumber: userInfo.data.idNumber,
  269. // phone: userInfo.data.phone,
  270. // avatar: userInfo.data.avatar,
  271. // userId: userInfo.data.userId
  272. // })
  273. // } else {
  274. // this.setData({
  275. // phone: userInfo.data.phone
  276. // })
  277. // }
  278. // this.Certification()
  279. // })
  280. },
  281. //获取手机号
  282. // getPhoneNumber(e) {
  283. // const that = this
  284. // my.getPhoneNumber({
  285. // success: function(res) {
  286. // console.info('getPhoneNumber--->', res)
  287. // // 测试用
  288. // const phone = '13173661471'
  289. // that.setData({
  290. // "warnPhone.status": true,
  291. // phone: phone
  292. // });
  293. // app.data.phone = phone;
  294. // // let encryptedData = res.response
  295. // // getPhone(encryptedData).then(phone => {
  296. // // if (phone) {
  297. // // this.setData({
  298. // // "warnPhone.status": true,
  299. // // phone: phone
  300. // // });
  301. // // app.data.phone = phone;
  302. // // } else {
  303. // // wx.showToast({
  304. // // icon: "none",
  305. // // title: "网络异常请重新获取哦~"
  306. // // });
  307. // // }
  308. // // }).catch(err => {
  309. // // console.log(err);
  310. // // })
  311. // }
  312. // })
  313. // },
  314. antmoveAction: function () {
  315. //执行时动态赋值,请勿删除
  316. }
  317. },
  318. observers: {
  319. userInfo: function (userInfo) {
  320. if (userInfo) {
  321. this.setData({
  322. username: userInfo.username,
  323. idNumber: userInfo.idNumber,
  324. phone: userInfo.phone,
  325. userId: userInfo.userId,
  326. avatar: userInfo.avatar
  327. });
  328. }
  329. }
  330. },
  331. lifetimes: {
  332. attached: function () {
  333. let userInfo = this.data.userInfo;
  334. if (userInfo) {
  335. this.setData({
  336. username: userInfo.username,
  337. idNumber: userInfo.idNumber,
  338. phone: userInfo.phone,
  339. userId: userInfo.userId
  340. });
  341. }
  342. }
  343. },
  344. pageLifetimes: {
  345. show() {
  346. if (this.data.flag === 1) {
  347. this.data.flag = null;
  348. // this.doFaceCheck();
  349. } else if (this.data.flag === 2) {
  350. this.data.flag = null;
  351. this.triggerEvent("updateState", app.data.temporary_userInfo ? true : false);
  352. }
  353. }
  354. }
  355. // rootEvents: {
  356. // onReady() {
  357. // const that = this
  358. // iotVspInit((res) => {
  359. // that.setCertificationState(res.success)
  360. // my.navigateBack()
  361. // })
  362. // }
  363. // }
  364. })