新增 绑定身份证 和银行卡接口
parent
be25972178
commit
8565a9ac98
|
@ -26,5 +26,15 @@ public class BankCard {
|
|||
/*
|
||||
用户id
|
||||
*/
|
||||
private String userId;
|
||||
private Long userId;
|
||||
|
||||
/*
|
||||
银行卡类型
|
||||
*/
|
||||
private String bankType;
|
||||
|
||||
/*
|
||||
银行卡名称
|
||||
*/
|
||||
private String cardName;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.health.system.server.controller;
|
||||
|
||||
import com.health.common.core.domain.Result;
|
||||
import com.health.system.common.domain.BankCard;
|
||||
import com.health.system.server.config.ForestClientInterface;
|
||||
import com.health.system.server.service.SysBankCardService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
@ -8,6 +10,10 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
* @version 1.0
|
||||
|
@ -16,6 +22,11 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
*/
|
||||
@RestController("/bankCard")
|
||||
public class SysBankCardController {
|
||||
/*
|
||||
注入远程调用第三方接口
|
||||
*/
|
||||
@Autowired
|
||||
private ForestClientInterface forestClientInterface;
|
||||
/*
|
||||
用户银行卡业务逻辑层接口
|
||||
*/
|
||||
|
@ -23,7 +34,9 @@ public class SysBankCardController {
|
|||
private SysBankCardService sysBankCardService;
|
||||
|
||||
@PostMapping("/bindUserBank")
|
||||
public Result bindUserBank(@RequestParam("bankImage") MultipartFile bankImage){
|
||||
return Result.success();
|
||||
public Result bindUserBank(@RequestParam("bankImage") MultipartFile bankImage) throws IOException {
|
||||
//获取银行卡照片的字节流
|
||||
Boolean flag=sysBankCardService.bindUserBank(bankImage);
|
||||
return flag==true?Result.success("","银行卡绑定成功"):Result.error("","银行卡绑定失败");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,42 +41,7 @@ public class SysIdCardController {
|
|||
|
||||
@PostMapping("/bindIdCard")
|
||||
public Result bindIdCard(@RequestParam("faceImage")MultipartFile faceImage,@RequestParam("backImage") MultipartFile backImage) throws IOException {
|
||||
//获取正面头像照片的字节流
|
||||
System.out.println(SecurityUtils.getLoginUser());
|
||||
String username = SecurityUtils.getUsername();
|
||||
System.out.println("当前登录人是"+username);
|
||||
byte[] faceImageBytes = faceImage.getBytes();
|
||||
//获取反面国徽面的字节流
|
||||
byte[] backImageBytes = backImage.getBytes();
|
||||
String face = Base64.getEncoder().encodeToString(faceImageBytes);
|
||||
Map faceMap = forestClientInterface.helloForestFace(face);
|
||||
System.out.println(faceMap);
|
||||
String address = (String) faceMap.get("address");
|
||||
String birthday = (String) faceMap.get("birth");
|
||||
String name = (String) faceMap.get("name");
|
||||
String sex = (String) faceMap.get("sex");
|
||||
String nation = (String) faceMap.get("nationality");
|
||||
String num = (String) faceMap.get("num");
|
||||
if (!name.equals(username)){
|
||||
throw new ServerException("请选择自己的身份证进行绑定");
|
||||
}
|
||||
String back = Base64.getEncoder().encodeToString(backImageBytes);
|
||||
Configure configure = new Configure();
|
||||
configure.setSide(IdCardConfigureType.Back.getType());
|
||||
Map backMap = forestClientInterface.helloForestBack(back, configure);
|
||||
System.out.println(backMap);
|
||||
String issueOffice = (String) backMap.get("issue");
|
||||
IdCard idCard = new IdCard();
|
||||
idCard.setName(name);
|
||||
idCard.setBirthday(birthday);
|
||||
idCard.setName(name);
|
||||
idCard.setSex(sex);
|
||||
idCard.setNation(nation);
|
||||
idCard.setIdNumber(num);
|
||||
idCard.setIssueOffice(issueOffice);
|
||||
idCard.setAddress(address);
|
||||
idCard.setUserId(SecurityUtils.getUserId());
|
||||
Boolean flag= sysIdCardService.insertIdCard(idCard);
|
||||
return flag==true?Result.success("","绑定成功"):Result.error("","绑定失败");
|
||||
Boolean flag= sysIdCardService.bindIdCard(faceImage,backImage);
|
||||
return flag==true?Result.success("","身份证绑定成功"):Result.error("","身份证绑定失败");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.health.system.server.mapper;
|
||||
|
||||
import com.health.system.common.domain.BankCard;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
|
@ -10,4 +11,5 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
*/
|
||||
@Mapper
|
||||
public interface SysBankCardMapper {
|
||||
int insertBankCard(BankCard bankCard);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package com.health.system.server.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
* @version 1.0
|
||||
|
@ -7,4 +11,5 @@ package com.health.system.server.service;
|
|||
* @date 2023/10/28 15:11
|
||||
*/
|
||||
public interface SysBankCardService {
|
||||
Boolean bindUserBank(MultipartFile bankImage) throws IOException;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.health.system.server.service;
|
||||
|
||||
import com.health.system.common.domain.IdCard;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
|
@ -10,4 +13,6 @@ import com.health.system.common.domain.IdCard;
|
|||
*/
|
||||
public interface SysIdCardService {
|
||||
Boolean insertIdCard(IdCard idCard);
|
||||
|
||||
Boolean bindIdCard(MultipartFile faceImage, MultipartFile backImage) throws IOException;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
package com.health.system.server.service.impl;
|
||||
|
||||
import com.health.common.security.utils.SecurityUtils;
|
||||
import com.health.system.common.domain.BankCard;
|
||||
import com.health.system.server.config.ForestClientInterface;
|
||||
import com.health.system.server.mapper.SysBankCardMapper;
|
||||
import com.health.system.server.service.SysBankCardService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
|
@ -14,9 +22,31 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
public class SysBankCardServiceImpl implements SysBankCardService {
|
||||
|
||||
@Autowired
|
||||
private ForestClientInterface forestClientInterface;
|
||||
/*
|
||||
用户银行卡持久层接口
|
||||
*/
|
||||
@Autowired
|
||||
private SysBankCardMapper sysBankCardMapper;
|
||||
|
||||
@Override
|
||||
public Boolean bindUserBank(MultipartFile bankImage) throws IOException {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
byte[] bytes = bankImage.getBytes();
|
||||
String bank = Base64.getEncoder().encodeToString(bytes);
|
||||
Map map = forestClientInterface.helloForestBank(bank);
|
||||
String cardNumber = (String) map.get("card_number");
|
||||
String bankName = (String) map.get("bank_name");
|
||||
String bankIdentificationNumber = (String) map.get("bank_identification_number");
|
||||
String cardName = (String) map.get("card_name");
|
||||
String cardType = (String) map.get("card_type");
|
||||
BankCard bankCard = new BankCard();
|
||||
bankCard.setUserId(userId);
|
||||
bankCard.setBankNumber(cardNumber);
|
||||
bankCard.setBankName(bankName);
|
||||
bankCard.setBankType(cardType);
|
||||
bankCard.setCardName(cardName);
|
||||
return sysBankCardMapper.insertBankCard(bankCard)>0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
package com.health.system.server.service.impl;
|
||||
|
||||
import com.health.common.core.domain.Configure;
|
||||
import com.health.common.security.utils.SecurityUtils;
|
||||
import com.health.system.common.domain.IdCard;
|
||||
import com.health.system.common.domain.util.IdCardConfigureType;
|
||||
import com.health.system.server.config.ForestClientInterface;
|
||||
import com.health.system.server.mapper.SysIdCardMapper;
|
||||
import com.health.system.server.service.SysIdCardService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.rmi.ServerException;
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
|
@ -15,6 +25,8 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
public class SysIdCardServiceImpl implements SysIdCardService {
|
||||
|
||||
@Autowired
|
||||
private ForestClientInterface forestClientInterface;
|
||||
/*
|
||||
注入用户身份证持久层接口
|
||||
*/
|
||||
|
@ -25,4 +37,45 @@ public class SysIdCardServiceImpl implements SysIdCardService {
|
|||
public Boolean insertIdCard(IdCard idCard) {
|
||||
return sysIdCardMapper.insertIdCard(idCard)>0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean bindIdCard(MultipartFile faceImage, MultipartFile backImage) throws IOException {
|
||||
|
||||
//获取正面头像照片的字节流
|
||||
System.out.println(SecurityUtils.getLoginUser());
|
||||
String username = SecurityUtils.getUsername();
|
||||
System.out.println("当前登录人是"+username);
|
||||
byte[] faceImageBytes = faceImage.getBytes();
|
||||
//获取反面国徽面的字节流
|
||||
byte[] backImageBytes = backImage.getBytes();
|
||||
String face = Base64.getEncoder().encodeToString(faceImageBytes);
|
||||
Map faceMap = forestClientInterface.helloForestFace(face);
|
||||
System.out.println(faceMap);
|
||||
String address = (String) faceMap.get("address");
|
||||
String birthday = (String) faceMap.get("birth");
|
||||
String name = (String) faceMap.get("name");
|
||||
String sex = (String) faceMap.get("sex");
|
||||
String nation = (String) faceMap.get("nationality");
|
||||
String num = (String) faceMap.get("num");
|
||||
if (!name.equals(username)){
|
||||
throw new ServerException("请选择自己的身份证进行绑定");
|
||||
}
|
||||
String back = Base64.getEncoder().encodeToString(backImageBytes);
|
||||
Configure configure = new Configure();
|
||||
configure.setSide(IdCardConfigureType.Back.getType());
|
||||
Map backMap = forestClientInterface.helloForestBack(back, configure);
|
||||
System.out.println(backMap);
|
||||
String issueOffice = (String) backMap.get("issue");
|
||||
IdCard idCard = new IdCard();
|
||||
idCard.setName(name);
|
||||
idCard.setBirthday(birthday);
|
||||
idCard.setName(name);
|
||||
idCard.setSex(sex);
|
||||
idCard.setNation(nation);
|
||||
idCard.setIdNumber(num);
|
||||
idCard.setIssueOffice(issueOffice);
|
||||
idCard.setAddress(address);
|
||||
idCard.setUserId(SecurityUtils.getUserId());
|
||||
return sysIdCardMapper.insertIdCard(idCard)>0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,4 +3,42 @@
|
|||
<mapper namespace="com.health.system.server.mapper.SysBankCardMapper">
|
||||
|
||||
|
||||
<insert id="insertBankCard">
|
||||
insert into tb_bank
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="userId!=null">
|
||||
user_id,
|
||||
</if>
|
||||
<if test="bankNumber!=null and bankNumber!=''" >
|
||||
bank_number,
|
||||
</if>
|
||||
<if test="bankName!=null and bankName!=''" >
|
||||
bank_name,
|
||||
</if>
|
||||
<if test="bankType!=null and bankType!=''" >
|
||||
bank_type,
|
||||
</if>
|
||||
<if test="cardName!=null and cardName!=''" >
|
||||
card_name,
|
||||
</if>
|
||||
</trim>
|
||||
values
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="userId!=null">
|
||||
#{userId},
|
||||
</if>
|
||||
<if test="bankNumber!=null and bankNumber!=''" >
|
||||
#{bankNumber},
|
||||
</if>
|
||||
<if test="bankName!=null and bankName!=''" >
|
||||
#{bankName},
|
||||
</if>
|
||||
<if test="bankType!=null and bankType!=''" >
|
||||
#{bankType},
|
||||
</if>
|
||||
<if test="cardName!=null and cardName!=''" >
|
||||
#{cardName},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue