| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- /* eslint-disable */
- const formatTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
- }
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : '0' + n
- }
- module.exports = {
- formatTime: formatTime,
- initProduct: initProduct,
- uploadImage: uploadImage,
- uploadBase64Image: uploadBase64Image,
- livedetect: livedetect,
- idcardOCR: idcardOCR,
- realNameAuth: realNameAuth,
- compare: compare
- }
- function initProduct(membershipKey, callback) {
- wx.request({
- url: 'https://www.chinadatapay.com/MyAccount/checkMembership', // 初始化产品
- dataType: 'json',
- method: 'POST',
- data: {
- membershipKey: membershipKey
- },
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success(res) {
- //执行回调
- return typeof callback == "function" && callback(res.data);
- }
- })
- }
- function uploadImage(appkey, tempFilePath, callback) {
- wx.uploadFile({
- url: 'https://file.chinadatapay.com/img/upload', // 图片上传
- filePath: tempFilePath,
- name: 'file',
- dataType: 'json',
- formData: {
- appkey: appkey
- },
- success(res) {
- const data = JSON.parse(res.data);
- //执行回调
- return typeof callback == "function" && callback(data);
- }
- })
- }
- function uploadBase64Image(appkey, base64Image, callback) {
- wx.request({
- url: 'https://file.chinadatapay.com/img/uploadByBase64',
- dataType: 'json',
- method: 'POST',
- data: {
- appkey: appkey,
- base64Image: base64Image
- },
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success(res) {
- const data = res.data;
- //执行回调
- return typeof callback == "function" && callback(data);
- }
- })
- }
- function livedetect(membershipKey, key, tempFilePath, apiKey, apiSecret, callback) {
- this.uploadImage(key, tempFilePath, function (result) {
- var imageId = result.data;
- wx.request({
- url: 'https://api.chinadatapay.com/trade/user/2104', // 活体检测
- dataType: 'json',
- method: 'POST',
- data: {
- imageId: imageId,
- key: key,
- apiSecret: apiSecret,
- return_image: true,
- apiKey: apiKey,
- membershipkey: membershipKey
- },
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success(res) {
- const data = res.data
- //执行回调
- return typeof callback == "function" && callback(data);
- }
- })
- });
- }
- function compare(membershipKey, key, base64Image, name, idcard, callback) {
- this.uploadBase64Image(key, base64Image, function (result) {
- var imageId = result.data;
- wx.request({
- url: 'https://api.chinadatapay.com/communication/personal/2061', // 人像比对
- dataType: 'json',
- method: 'POST',
- data: {
- imageId: imageId,
- key: key,
- name: name,
- idcard: idcard,
- membershipkey: membershipKey
- },
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success(res) {
- const data = res.data
- //执行回调
- return typeof callback == "function" && callback(data);
- }
- })
- });
- }
- function realNameAuth(membershipKey, key, name, idcard, callback) {
- wx.request({
- url: 'https://api.chinadatapay.com/communication/personal/1882', // 实名认证
- dataType: 'json',
- method: 'POST',
- data: {
- key: key,
- name: name,
- idcard: idcard,
- membershipkey: membershipKey
- },
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success(res) {
- const data = res.data
- //执行回调
- return typeof callback == "function" && callback(data);
- }
- })
- }
- function idcardOCR(membershipKey, key, tempFilePath, callback) {
- this.uploadImage(key, tempFilePath, function (result) {
- var imageId = result.data;
- wx.request({
- url: 'https://api.chinadatapay.com/trade/user/1985', // 身份证OCR识别
- dataType: 'json',
- method: 'POST',
- data: {
- imageId: imageId,
- key: key,
- membershipkey: membershipKey
- },
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success(res) {
- const data = res.data;
- //执行回调
- return typeof callback == "function" && callback(data);
- }
- })
- })
- }
|