扫描银行卡迭代
parent
cb60060e51
commit
fd7f5f0b22
|
@ -35,7 +35,7 @@ public class BankConfig {
|
|||
/**
|
||||
* 银行ID
|
||||
*/
|
||||
private Integer bankId;
|
||||
private Integer bankId;
|
||||
/**
|
||||
* 银行代码
|
||||
*/
|
||||
|
|
|
@ -1,23 +1,11 @@
|
|||
package com.ruoyi.mybasic.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.mybasic.common.domain.BankConfig;
|
||||
import com.ruoyi.mybasic.service.MessageService;
|
||||
import com.ruoyi.mybasic.util.HttpUtils;
|
||||
import com.ruoyi.mybasic.util.UploadUtil;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 银行卡上传
|
||||
|
@ -31,8 +19,6 @@ public class MessageController {
|
|||
private MessageService messageService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private UploadUtil uploadUtil;
|
||||
|
||||
|
||||
|
||||
|
@ -41,75 +27,10 @@ public class MessageController {
|
|||
*/
|
||||
@PostMapping("/upload")
|
||||
public void upload(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
//上传文件方法
|
||||
if (null == file){
|
||||
throw new ServiceException("银行卡照片为空");
|
||||
}
|
||||
String upload = uploadUtil.upload(file);
|
||||
|
||||
String host = "https://vbkocr.market.alicloudapi.com";
|
||||
String path = "/lundear/bkocr";
|
||||
String method = "POST";
|
||||
String appcode = "ded4e72aaf8f48499dcd2ef13f8eaae9";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
//根据API的要求,定义相对应的Content-Type
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
Map<String, String> bodys = new HashMap<String, String>();
|
||||
bodys.put("url", upload);
|
||||
// querys.put("image", upload);
|
||||
System.out.println(bodys);
|
||||
|
||||
BankConfig bankConfig = new BankConfig();
|
||||
|
||||
try {
|
||||
/**
|
||||
* 重要提示如下:
|
||||
* HttpUtils请从
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
||||
* 下载
|
||||
*
|
||||
* 相应的依赖请参照
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
||||
*/
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||
System.out.println(response.toString());
|
||||
|
||||
//获取response的body
|
||||
JSONObject jsonObject = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
|
||||
System.out.println("jsonObject数据为:" + jsonObject);
|
||||
|
||||
//查询当前人银行卡的当前银行卡 根据银行卡号进行循环查询 是否已经绑定
|
||||
List<Integer> bankCardNo = messageService.listBankCardNo(SecurityUtils.getUserId());
|
||||
boolean hasNullElement = false;
|
||||
for (Integer integer : bankCardNo) {
|
||||
if (integer != null && integer != 0){
|
||||
hasNullElement = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasNullElement){
|
||||
throw new ServiceException("已经添加过此银行卡!换一张");
|
||||
}else{
|
||||
|
||||
bankConfig.setBankCode(jsonObject.getString("bank_code"));
|
||||
bankConfig.setBankId(jsonObject.getInteger("bank_id"));
|
||||
bankConfig.setBankName(jsonObject.getString("bank_name"));
|
||||
bankConfig.setCardNo(jsonObject.getString("card_no"));
|
||||
bankConfig.setBankCode(jsonObject.getString("bank_code"));
|
||||
bankConfig.setCardType(jsonObject.getString("card_type"));
|
||||
bankConfig.setUserId(SecurityUtils.getUserId());
|
||||
|
||||
BankConfig bankConfig1 = JSONObject.parseObject(jsonObject.getString("bankConfig"), BankConfig.class);
|
||||
//绑定银行卡 添加到银行卡表中
|
||||
messageService.addBank(bankConfig1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
messageService.upload(file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 识别银行卡信息
|
||||
* @param
|
||||
|
@ -156,20 +77,6 @@ public class MessageController {
|
|||
// return responseCard;
|
||||
// }
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// Config config = new Config()
|
||||
// .setAccessKeyId("你的AccessKeyId")
|
||||
// .setAccessKeySecret("你的AccessKeySecret");
|
||||
// OcrBankCard ocrBankCard = new OcrBankCard(config);
|
||||
// try {
|
||||
// CommonResponse response = ocrBankCard.ocrBankCard("要识别的银行卡图片的URL");
|
||||
// System.out.println(response.getData());
|
||||
// } catch (TeaException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// @Override
|
||||
// public Boolean bindUserBank(MultipartFile bankImage) throws IOException {
|
||||
// Long userId = SecurityUtils.getUserId();
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 银行卡验证
|
||||
|
@ -12,6 +13,7 @@ import java.util.List;
|
|||
public interface MessageMapper {
|
||||
void addBank(BankConfig bankConfig);
|
||||
|
||||
|
||||
//查询当前人银行卡的当前银行卡 根据银行卡号进行循环查询 是否已经绑定
|
||||
List<Integer> listBankCardNo(@Param("userId") Long userId);
|
||||
BankConfig selectBankId(@Param("bankId") Integer bankId);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package com.ruoyi.mybasic.service.Impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.mybasic.common.domain.BankConfig;
|
||||
import com.ruoyi.mybasic.mapper.MessageMapper;
|
||||
import com.ruoyi.mybasic.service.MessageService;
|
||||
import com.ruoyi.mybasic.util.BankScan;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
@ -17,27 +21,21 @@ import java.util.List;
|
|||
@Service
|
||||
public class MessageServiceImpl implements MessageService {
|
||||
|
||||
|
||||
/** @noinspection SpringJavaInjectionPointsAutowiringInspection*/
|
||||
@Autowired
|
||||
private MessageMapper messageMapper;
|
||||
|
||||
/**
|
||||
* 绑定银行卡 添加到银行卡表中
|
||||
* @param bankConfig
|
||||
*/
|
||||
@Override
|
||||
public void addBank(BankConfig bankConfig) {
|
||||
messageMapper.addBank(bankConfig);
|
||||
}
|
||||
@Autowired
|
||||
private BankScan bankScan;
|
||||
|
||||
|
||||
/**
|
||||
* 查询当前人银行卡的当前银行卡 根据银行卡号进行循环查询 是否已经绑定
|
||||
* @param userId
|
||||
* @return
|
||||
* 银行卡扫描
|
||||
* @param file
|
||||
*/
|
||||
@Override
|
||||
public List<Integer> listBankCardNo(Long userId) {
|
||||
|
||||
return messageMapper.listBankCardNo(userId);
|
||||
public void upload(MultipartFile file) {
|
||||
bankScan.BankScan(file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,6 @@ import java.util.List;
|
|||
*/
|
||||
public interface MessageService {
|
||||
|
||||
//绑定银行卡 添加信息到 数据库中
|
||||
void addBank(BankConfig bankConfig);
|
||||
|
||||
//查询当前人银行卡的当前银行卡 根据银行卡号进行循环查询 是否已经绑定
|
||||
List<Integer> listBankCardNo(@Param("userId") Long userId);
|
||||
//银行扫描加添加数据库
|
||||
void upload(MultipartFile file);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
package com.ruoyi.mybasic.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.JSONPObject;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.mybasic.common.domain.BankConfig;
|
||||
import com.ruoyi.mybasic.mapper.MessageMapper;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 银行扫描工具类
|
||||
*/
|
||||
@Component
|
||||
public class BankScan {
|
||||
|
||||
/** @noinspection SpringJavaInjectionPointsAutowiringInspection*/
|
||||
@Autowired
|
||||
private MessageMapper messageMapper;
|
||||
|
||||
@Autowired
|
||||
private UploadUtil uploadUtil;
|
||||
|
||||
public String BankScan(MultipartFile file){
|
||||
OutputStream outputStream = null;
|
||||
//上传文件方法
|
||||
if (null == file){
|
||||
throw new ServiceException("银行卡照片为空");
|
||||
}
|
||||
String upload = uploadUtil.upload(file);
|
||||
|
||||
String host = "https://vbkocr.market.alicloudapi.com";
|
||||
String path = "/lundear/bkocr";
|
||||
String method = "POST";
|
||||
String appcode = "ded4e72aaf8f48499dcd2ef13f8eaae9";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
//根据API的要求,定义相对应的Content-Type
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
Map<String, String> bodys = new HashMap<String, String>();
|
||||
bodys.put("url", upload);
|
||||
System.out.println(bodys);
|
||||
|
||||
try {
|
||||
/**
|
||||
* 重要提示如下:
|
||||
* HttpUtils请从
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
||||
* 下载
|
||||
*
|
||||
* 相应的依赖请参照
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
||||
*/
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||
System.out.println("response:"+response.toString());
|
||||
|
||||
String string = EntityUtils.toString(response.getEntity());
|
||||
JSONObject jsonObject = JSONObject.parseObject(string);
|
||||
//获取response的body
|
||||
// JSONObject jsonObject = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
|
||||
System.out.println("jsonObject数据为:" + jsonObject);
|
||||
|
||||
bodys.clear();//用于清空bodys路径数据
|
||||
System.out.println("上一个路径 数据清空");
|
||||
|
||||
BankConfig bankConfig = new BankConfig();
|
||||
//查询当前人银行卡的当前银行卡 根据银行卡号进行循环查询 是否已经绑定
|
||||
|
||||
//转成字符串
|
||||
BankConfig bankConfig1 = JSONObject.parseObject(jsonObject.getString("data"), BankConfig.class);
|
||||
|
||||
//判断银行卡的bankId 是不是唯一
|
||||
BankConfig bankConfig2 = messageMapper.selectBankId(bankConfig1.getBankId());
|
||||
if (bankConfig2 != null){
|
||||
return "已经添加过此银行卡!换一张";
|
||||
// throw new ServiceException("已经添加过此银行卡!换一张");
|
||||
}
|
||||
//存值
|
||||
bankConfig.setBankCode(bankConfig1.getBankCode());
|
||||
bankConfig.setCardType(bankConfig1.getCardType());
|
||||
bankConfig.setCardNo(bankConfig1.getCardNo());
|
||||
bankConfig.setBankName(bankConfig1.getBankName());
|
||||
bankConfig.setBankId(bankConfig1.getBankId());
|
||||
bankConfig.setUserId(SecurityUtils.getUserId());
|
||||
|
||||
//绑定银行卡 添加到银行卡表中
|
||||
messageMapper.addBank(bankConfig);
|
||||
|
||||
System.out.println("添加成功");
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "成功";
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 阿里云扫描银行卡工具类
|
||||
*/
|
||||
public class HttpUtils {
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<!-- 绑定银行卡 添加到银行卡表中-->
|
||||
<insert id="addBank">
|
||||
insert into t_bank
|
||||
insert into t_bankTwo
|
||||
(
|
||||
<if test="userId != null ">
|
||||
user_id,
|
||||
|
@ -50,8 +50,10 @@
|
|||
now()
|
||||
)
|
||||
</insert>
|
||||
<!-- 查询当前人银行卡的当前银行卡 根据银行卡号进行循环查询 是否已经绑定-->
|
||||
<select id="listBankCardNo" resultType="java.lang.Integer">
|
||||
SELECT t_bankTwo.card_no from t_bankTwo where user_id = #{userId}
|
||||
|
||||
<!-- 查询当前人银行卡的当前银行卡 根据银行卡号进行循环查询 是否已经绑定-->
|
||||
|
||||
<select id="selectBankId" resultType="com.ruoyi.mybasic.common.domain.BankConfig">
|
||||
select * from t_bankTwo where bank_id = #{bankId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue