|
|
@@ -0,0 +1,175 @@
|
|
|
+/* 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);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|