test 7 hónapja
szülő
commit
f7b1d17753

+ 28 - 0
src/modules/dj/service/channels/sunpay.ts

@@ -19,6 +19,7 @@ const PREMINUM_KEY_URL = HOST + '/api/v3-2/Fiat/Kyc/CreatePremiumUser';
 const COUNTRIES_URL = HOST + '/api/v3-2/Fiat/Countries';
 const REFUND_URL = HOST + '/api/v3-2/Fiat/Direct/Refund';
 const QUERY_REFUND_URL = HOST + '/api/v3-2/Fiat/x/Refund'
+const KYC_QUERY = HOST + '/api/v3-2/Fiat/Kyc/GetCustomer'
 
 // const API_KEY = '08dcd396-a91a-486a-8ca5-02150819d7ae';
 const API_KEY = '08dd0477-8676-4f68-83c1-215dceeffa2e';
@@ -335,4 +336,31 @@ export class SunPayService extends BaseService {
       throw new Error(msg);
     }
   }
+
+  async queryKyc(outUserId) {
+    const timestamp = +moment();
+    const nonce = md5(timestamp);
+    const data = timestamp + nonce;
+    const sign = this.utils.signBySha256(data, API_SERECT).toUpperCase();
+    const URL = KYC_QUERY + '?out_user_id=' + outUserId;
+    console.log(URL)
+    const res = await this.httpService.get(URL, {
+      headers: {
+        'SunPay-Key': API_KEY,
+        'SunPay-Timestamp': timestamp,
+        'SunPay-Nonce': nonce,
+        'SunPay-Sign': sign
+      }
+    });
+    const { is_success, msg } = res.data;
+    if (is_success && res.data && res.data.data && res.data.data.customer_id) {
+      return {
+        customerId: res.data.data.customer_id,
+        kycUserId: res.data.data.out_user_id,
+        countryCode: res.data.data.country_code
+      };
+    } else {
+      throw new Error(msg);
+    }
+  }
 }

+ 27 - 9
src/modules/dj/service/openKyc.ts

@@ -39,23 +39,41 @@ export class KycOpenService extends BaseService {
       await this.validGetCustomer(payload);
       const merchant = await this.payService.validMerchant(payload.mchId);
       await this.payService.validSign(payload, merchant);
-      const kyc = await this.kycEntity.findOneBy({
+      let kyc = await this.kycEntity.findOneBy({
         mchId: payload.mchId,
         userId: payload.userId,
         code: 'SUN_CARD',
       })
-      if (!kyc || !kyc.customerId) {
-        return {};
+      if (kyc && kyc.customerId) {
+        return {
+          mchId: kyc.mchId,
+          userId: kyc.mchId,
+          kycUserId: kyc.userId,
+          country: kyc.country,
+          level: kyc.level
+        }
+      }
+      const outUserId = md5(payload.mchId + '_' + payload.userId + 'v2');
+      const data = await this.sunPayService.queryKyc(outUserId);
+      const newKyc = {
+        userId: payload.userId,
+        mchId: payload.mchId,
+        code: 'SUN_CARD',
+        kycUserId: data.kycUserId,
+        customerId: data.customerId,
+        level: '1',
+        country: data.countryCode
       }
+      await this.kycEntity.insert(kyc)
       return {
-        mchId: kyc.mchId,
-        userId: kyc.mchId,
-        kycUserId: kyc.userId,
-        country: kyc.country,
-        level: kyc.level
+        mchId: newKyc.mchId,
+        userId: newKyc.mchId,
+        kycUserId: newKyc.userId,
+        country: newKyc.country,
+        level: newKyc.level
       }
     } catch (err) {
-      this.logger.error('KYC高级认证提交失败', JSON.stringify(payload), err.message);
+      this.logger.error('获取客户信息', JSON.stringify(payload), err.message);
       throw new CoolCommException(err.message);
     }
   }