"拉卡拉进件支付代码"

This commit is contained in:
hankaikai
2023-05-23 12:55:26 +08:00
parent 52650b7ae0
commit 790920f13e
33 changed files with 2124 additions and 66 deletions

View File

@@ -11,6 +11,7 @@ import cn.pluss.platform.dto.AccountDTO;
import cn.pluss.platform.dto.BankCardDTO;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.klk.vo.CallBackVo;
import cn.pluss.platform.mapper.AccountMapper;
import cn.pluss.platform.mapper.UserAppMapper;
import cn.pluss.platform.mcc.MccReflectService;
@@ -549,6 +550,59 @@ public class YSAuditServiceV3 implements cn.pluss.platform.channel.ys.YSAuditSer
}
}
/**
* 入网申请流水 lkl
* 备注 note
* 客户号id custId
* 入网状态 status
*/
public void lklResultHandle(CallBackVo cust) {
String status = cust.getStatus();
String sysFlowId = cust.getSysFlowId();
MerchantChannelStatus mcs = new MerchantChannelStatus();
mcs.setApplicationId(sysFlowId);
mcs.setChannel(5);
mcs = mcsService.getOne(new QueryWrapper<>(mcs));
mcs.setThirdStatus(status);
mcs.getExtra().putAll((JSONObject) JSON.toJSON(cust));
switch (status) {
case YsConfigV3.STATUS_SUCCESS:
mcs.setAuditSuccessTime(new Date());
mcsService.updateById(mcs);
sign(mcs);
break;
case YsConfigV3.STATUS_REFUSE:
List<String> excludeStatus = Arrays.asList(MerchantChannelStatus.AUDIT_STATUS_REJECT, MerchantChannelStatus.AUDIT_STATUS_SUCCESS);
MerchantChannelStatus finalMcs = mcs;
boolean returnFlag = excludeStatus.stream().anyMatch(s -> s.equals(finalMcs.getStatus()));
if (returnFlag) {
return;
}
MerchantBaseInfo mbi = mbiService.getMerchantBaseInfoByMerchantCode(mcs.getMerchantCode());
String note = cust.getNote();
mcs.setRemark(note);
mcs.setStatus(MerchantChannelStatus.AUDIT_STATUS_REJECT);
mcsService.updateById(mcs);
mercAuditListener.onFail(mbi.getUserId(), mcs, note);
break;
// case YsConfigV3.STATUS_TO_MANUAL:
// List<String> excludeStatus2 = Arrays.asList(MerchantChannelStatus.AUDIT_STATUS_SUCCESS, MerchantChannelStatus.AUDIT_STATUS_ARTIFICIAL_EXAMINING);
// MerchantChannelStatus finalMcs2 = mcs;
// boolean returnFlag2 = excludeStatus2.stream().anyMatch(s -> s.equals(finalMcs2.getStatus()));
// if (returnFlag2) {
// return;
// }
// mcs.setStatus(MerchantChannelStatus.AUDIT_STATUS_ARTIFICIAL_EXAMINING);
// mcsService.updateById(mcs);
// break;
}
}
public void step2(String userId) {
MerchantBaseInfo mbi = mbiService.getMerchantBaseInfoByUserId(userId);
List<MerchantImage> miList = miService.getListOfMerch(userId, Account.CHANNEL_TYPE_D0);

View File

@@ -0,0 +1,56 @@
package cn.pluss.platform.klk;
import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.security.KeyFactory;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
public class LaKaLaUtility {
// static String pubKey ="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp5aV3ZiXG2R8Yd8Nxocv+cF7VAUHBc0TF4MNne7mI8wM2yEP2QgI+rK1qDf6G7\n" +
// "ZFPhutpIHKQchpolbSuC0vgaHpSjO9OUs1fpnK/JjZq9o8DatUsA0n4Fccec9NBbV5dy5yrwro7xmDpsevp1\n" +
// "/IeiIssi1+iD+nBWqqVFx7GVQIDAQAB";
//测试公钥
private static String pubKey="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCvO9EN9W6OG7y72VUWZili4m8DlD+TMofgIl96OPX9fRBS7Icg3oIqxmU20xFbiswJ2cCU6I1gbE7GDM14CihLQd26xW5T/8TmHCaVFFy1b9AWHNK7sW3aNd2KK1PI3h4gS38ND8jqvdr/8YZSCNF2KOoOe3F17FqVecBdq+1VZQIDAQAB";
public static void main(String[] args) throws Exception {
String data="TOykml1JtGtrNL8rS+Aj/FOaq87eERTCUt9uZJk/ObFvuX5TRstQSl9fP3J2UTjSPO0b/p3Sh8Sxi1w9a6YuDQL9rrZ9orpWpEU+vg8H99fVZnvFjozB4HJf7NE5S9z7Mah93zW7TY1TFS55pIDv4go/fOtGTUcReUY0uFpZQote41m9KHvcjv5HiyCKaT/4cOoSMzHrsRiThwsU+rCDTzI4C32obwrXDOiaMd45wU4GL9/YMfHSpPOqgcsRZIWSBi2Pgt4nJX/s4uxVLzzKG00A8Jxa+yo0JZEgWRuHkOgcrV2Mxg8WmnXug8KeZBSeqYyvPXG9hy32q2phEwd1c6AYEOAKRu3QVhXEyDWjXkn86nvPimn8aohxYaAjky4E66LTnNIPNKOkwC5KVG27H9Fv27ZgqpDzRpYvaRExBT3RjJxXssLBRQ/eejOf7uuq0RgDUqFfwqOICqIUb8qbos6qu+QIsY2tvkbsMB1ZmD3s1SviHmvxWisD0VE/ZTDVQwDLUiORTwaMExirkc0s5bcB51FHHs2TFDa1raa/kSQwL/ADS0yAWNctiQGQtymErEmiD9iFdGXMvgjbqJ7KsDTAotKuYh9VzIA/RuAy+lpajvCIG6NOy428VHHin+RcXe/Ztx1UUHVk3xrHWNYG2aI4yyTLcz0EbG7rcOgWFwI=";
// String data ="hplFXwPU1gbHYwraQM/fKEcoIkBfHD07VSH99OnKTZk9HJRFAvZyOm9nsdeSi8t/UdGPn+LXldrjZ7wiY+F5MzGlIdEma7agKZyHJ+UO6CrDJfYFMwlPUOgO+Pq5ljg6QOdZBxBLEHkRMkQnC/CTv9vQnPDqeCv4MvAbHJspADGRRPvmjxtzf0J4OQgP3hj9+ZqH+btsuX+W+YZRXRMYL+uOQkSJhMUv31hc9MAC/1Sp0C9cBcHKxr+idS+0CCjvD8WzLbXv2QuOSQccIKQw+Je8RMeuKs8f64MibCkf+RkilTCVCEd5apL1MkhYJZoUVzqPXmDBLjaJgr987X1wBAzQMS8+F34Vl/BonKPuJ4RRwdE/M3WJ+ZfM2WiLawpU7ZqUQdVY2bwJO801TcmFCswLoz2qxHHsBsjXtQPqMOj3pw3Kvz3WH3oWmcFRZjHKIbDSy9Jh2STEFRbvVWarjksBVjXkcbletDtOtY0T8XCdiiNoQNlVNj5kH5QkAWmt";
String decrypt = LaKaLaUtility.decrypt(data);
System.out.println("解密结果:" + decrypt);
}
/**
* 公钥解密
* @param
* @param data Base64 数据
* @return 解密字符串
* @throws Exception 解密异常
*/
public static String decrypt(String data){
try {
Base64.Decoder decoder = Base64.getDecoder();
byte[] keyBytes = decoder.decode(pubKey.getBytes());
byte[] dataBytes = decoder.decode(data.getBytes());
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE,
KeyFactory.getInstance("RSA").generatePublic(new
X509EncodedKeySpec(keyBytes)));
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] cache;
for (int i = 0, offset = 0, length = dataBytes.length; length -
offset > 0; i++, offset = i * 128) {
if (length - offset > 128) {
cache = cipher.doFinal(dataBytes, offset, 128);
} else {
cache = cipher.doFinal(dataBytes, offset, length - offset);
}
out.write(cache, 0, cache.length);
}
return out.toString();
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}

View File

@@ -1,14 +0,0 @@
package cn.pluss.platform.klk;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties(prefix = "lkl")
public class LklConfig {
@Value("private_key")
private String privateKey;
}

View File

@@ -0,0 +1,196 @@
package cn.pluss.platform.klk.cache;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;
/**
* 暂时用jdk的缓存
* */
public class MemoryCache {
//键值对集合
private final static Map<String, Entity> map = new HashMap<>();
//定时器线程池,用于清除过期缓存
private final static ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
/**
* 添加缓存
* 可用 synchronized 加锁
* @param key 键
* @param data 值
*/
public static void put(String key, Object data) {
MemoryCache.put(key, data, 0);
}
/**
* 添加缓存
* 可用 synchronized 加锁
* @param key 键
* @param data 值
* @param expire 过期时间,单位:毫秒, 0表示无限长
*/
public static void put(String key, Object data, long expire) {
//清除原键值对
MemoryCache.remove(key);
//设置过期时间
if (expire > 0) {
Future future = executor.schedule(new Runnable() {
@Override
public void run() {
//过期后清除该键值对
synchronized (MemoryCache.class) {
map.remove(key);
}
}
}, expire, TimeUnit.MILLISECONDS);
map.put(key, new Entity(data, future));
} else {
//不设置过期时间
map.put(key, new Entity(data, null));
}
}
/**
* 读取缓存
* 可用 synchronized 加锁
* @param key 键
* @return
*/
public static Object get(String key) {
Entity entity = map.get(key);
return entity == null ? null : entity.getValue();
}
/**
* 读取缓存
* 可用 synchronized 加锁
* @param key 键
* @param clazz 值类型
* @return
*/
public static <T> T get(String key, Class<T> clazz) {
return clazz.cast(MemoryCache.get(key));
}
/**
* 清除缓存
* 可用 synchronized 加锁
* @param key
* @return
*/
public static Object remove(String key) {
//清除原缓存数据
Entity entity = map.remove(key);
if (entity == null) {
return null;
}
//清除原键值对定时器
Future future = entity.getFuture();
if (future != null) {
future.cancel(true);
}
return entity.getValue();
}
/**
* 查询当前缓存的键值对数量
* 可用 synchronized 加锁
* @return
*/
public static int size() {
return map.size();
}
/**
* 缓存实体类
*/
private static class Entity {
//键值对的value
private Object value;
//定时器Future
private Future future;
public Entity(Object value, Future future) {
this.value = value;
this.future = future;
}
/**
* 获取值
*
* @return
*/
public Object getValue() {
return value;
}
/**
* 获取Future对象
*
* @return
*/
public Future getFuture() {
return future;
}
}
public static void main(String[] args) throws ExecutionException, InterruptedException {
String key = "id";
//不设置过期时间
System.out.println("***********不设置过期时间**********");
MemoryCache.put(key, 123);
System.out.println("key:" + key + ", value:" + MemoryCache.get(key));
System.out.println("key:" + key + ", value:" + MemoryCache.remove(key));
System.out.println("key:" + key + ", value:" + MemoryCache.get(key));
//设置过期时间
System.out.println("\n***********设置过期时间**********");
MemoryCache.put(key, "123456", 1000);
System.out.println("key:" + key + ", value:" + MemoryCache.get(key));
TimeUnit.MILLISECONDS.sleep(1500);
System.out.println("key:" + key + ", value:" + MemoryCache.get(key));
/******************并发性能测试************/
System.out.println("\n***********并发性能测试************");
//创建有10个线程的线程池将1000000次操作分10次添加到线程池
ExecutorService executorService = Executors.newFixedThreadPool(10);
Future[] futures = new Future[10];
/********添加********/
{
long start = System.currentTimeMillis();
for (int j = 0; j < 10; j++) {
futures[j] = executorService.submit(() -> {
for (int i = 0; i < 100000; i++) {
MemoryCache.put(Thread.currentThread().getId() + key + i, i, 300000);
}
});
}
//等待全部线程执行完成,打印执行时间
for (Future future : futures) {
future.get();
}
System.out.printf("添加耗时:%dms\n", System.currentTimeMillis() - start);
}
/********查询********/
{
long start = System.currentTimeMillis();
for (int j = 0; j < 10; j++) {
futures[j] = executorService.submit(() -> {
for (int i = 0; i < 100000; i++) {
Object obj = MemoryCache.get(Thread.currentThread().getId() + key + i);
System.out.println("cacheObj:" + obj);
}
});
}
//等待全部线程执行完成,打印执行时间
for (Future future : futures) {
future.get();
}
System.out.printf("查询耗时:%dms\n", System.currentTimeMillis() - start);
}
System.out.println("当前缓存容量:" + MemoryCache.size());
}
}

View File

@@ -0,0 +1,19 @@
package cn.pluss.platform.klk.controller;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.ResponseErrorHandler;
import java.io.IOException;
public class FacePlusThrowErrorHandler implements ResponseErrorHandler {
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return false;
}
@Override
public void handleError(ClientHttpResponse response) throws IOException {
}
}

View File

@@ -0,0 +1,49 @@
package cn.pluss.platform.klk.controller;
import cn.pluss.platform.klk.service.impl.LaKalaInterfaceImpl;
import cn.pluss.platform.klk.vo.TuoKeVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.Map;
@RestController
@RequestMapping("/lkl")
public class LaKaLaController {
@Resource
LaKalaInterfaceImpl laKalaInterface;
@PostMapping("/lkl")
public void aa(@RequestBody TuoKeVo tuoKeVo){
laKalaInterface.tuoKeAddMer(tuoKeVo);
}
@PostMapping("/jjkl")
public void jjkl(MultipartFile file){
// try {
// laKalaInterface.laKaLaFileUpload();
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
}
@PostMapping("/jjkls")
public void jjkls(){
laKalaInterface.ff();
}
@PostMapping("/tuoke")
public void jjklss(){
laKalaInterface.createTuoKeInfo("244");
}
@PostMapping("/callBackToke")
public void callBackToke(@RequestBody Map<String,Object> map){
laKalaInterface.tuoKeCallBack(map);
}
}

View File

@@ -1,51 +0,0 @@
package cn.pluss.platform.klk.service;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.klk.LklConfig;
import cn.pluss.platform.klk.entity.ReqKlkEntity;
import cn.pluss.platform.klk.entity.RespKlkEntity;
import cn.pluss.platform.util.RSAUtils;
import cn.pluss.platform.util.SM4Util;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
/**
* @author lyf
*/
@Slf4j
@Service("KlkService")
public class KlkService {
@Autowired
private LklConfig lklConfig;
public void reqKlk()throws Exception{
String data = "req_data\": {\n" +
" \"member_id\": \"AAA200154561278\",\n" +
" \"mer_order_id\": \"202112030923011\"\n" +
" }\n";
String key = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDvDBZyHUDndAGxrIcsCV2njhNO3vCEZotTaWYSYwtDvkcAb1EjsBFabXZaKigpqFXk5XXNI3NIHP9M8XKzIgGvc65NpLAfRjVql8JiTvLyYd1gIUcOXMInabu+oX7dQSI1mS8XzqaoVRhDZQWhXcJW9bxMulgnzvk0Ggw07AjGF7si+hP/Va8SJmN7EJwfQq6TpSxR+WdIHpbWdhZ+NHwitnQwAJTLBFvfk28INM39G7XOsXdVLfsooFdglVTOHpNuRiQAj9gShCCNrpGsNQxDiJIxE43qRsNsRwigyo6DPJk/klgDJa417E2wgP8VrwiXparO4FMzOGK15quuoD7DAgMBAAECggEBANhmWOt1EAx3OBFf3f4/fEjylQgRSiqRqg8Ymw6KGuh4mE4Md6eW/B6geUOmZjVP7nIIR1wte28M0REWgn8nid8LGf+v1sB5DmIwgAf+8G/7qCwd8/VMg3aqgQtRp0ckb5OV2Mv0h2pbnltkWHR8LDIMwymyh5uCApbn/aTrCAZKNXcPOyAn9tM8Bu3FHk3Pf24Er3SN+bnGxgpzDrFjsDSHjDFT9UMIc2WdA3tuMv9X3DDn0bRCsHnsIw3WrwY6HQ8mumdbURk+2Ey3eRFfMYxyS96kOgBC2hqZOlDwVPAKTPtS4hoq+cQ0sRaJQ4T0UALJrBVHa+EESgRaTvrXqAECgYEA+WKmy9hcvp6IWZlk9Q1JZ+dgIVxrO65zylK2FnD1/vcTx2JMn73WKtQb6vdvTuk+Ruv9hY9PEsf7S8gHSTTmzHOUgo5x0F8yCxXFnfji2juoUnDdpkjtQK5KySDcpQb5kcCJWEVi9v+zObM0Zr1Nu5/NreE8EqUl3+7MtHOu1TMCgYEA9WM9P6m4frHPW7h4gs/GISA9LuOdtjLvAtgCK4cW2mhtGNAMttD8zOBQrRuafcbFAyU9de6nhGwetOhkW9YSV+xRNa7HWTeIRgXJuJBrluq5e1QGTIwZU/GujpNaR4Qiu0B8TodM/FME7htsyxjmCwEfT6SDYlkeMzTbMa9Q0DECgYBqsR/2+dvD2YMwAgZFKKgNAdoIq8dcwyfamUQ5mZ5EtGQL2yw48zibHh/LiIxgUD1Kjk/qQgNsX45NP4iOc0mCkrgomtRqdy+rumbPTNmQ0BEVJCBPscd+8pIgNiTvnWpMRvj7gMP0NDTzLI3wnnCRIq8WAtR2jZ0Ejt+ZHBziLQKBgQDibEe/zqNmhDuJrpXEXmO7fTv3YB/OVwEj5p1Z/LSho2nHU3Hn3r7lbLYEhUvwctCnLl2fzC7Wic1rsGOqOcWDS5NDrZpUQGGF+yE/JEOiZcPwgH+vcjaMtp0TAfRzuQEzNzV8YGwxB4mtC7E/ViIuVULHAk4ZGZI8PbFkDxjKgQKBgG8jEuLTI1tsP3kyaF3jAylnw7SkBc4gfe9knsYlw44YlrDSKr8AOp/zSgwvMYvqT+fygaJ3yf9uIBdrIilqCHKXccZ9uA/bT5JfIi6jbg3EoE9YhB0+1aGAS1O2dBvUiD8tJ+BjAT4OB0UDpmM6QsFLQgFyXgvDnzr/o+hQJelW";
ReqKlkEntity reqKlkEntity = ReqKlkEntity.get(data);
System.out.println("signFormat++++++++++++++"+reqKlkEntity.getSign());
String sign = RSAUtils.signSHA256(key, reqKlkEntity.getSign());
System.out.println("sign++++++++++++++++++"+sign);
//设置Authorization
HttpHeaders headers = new HttpHeaders();
headers.setContentType(APPLICATION_JSON);
headers.set("Authorization", "LKLAPI-SHA256withRSA");
String finalSign = "Content-Type: application/json"+"\n"+"Authorization:LKLAPI-SHA256withRSA"+" "+"appid="+reqKlkEntity.getAppid()+","+"serial_no="+reqKlkEntity.getSerialNo()+","+
reqKlkEntity.getTimestamp()+","+"nonce_str="+reqKlkEntity.getNonceStr()+","+
"signature="+sign;
System.out.println(finalSign);
}
// public String signEncrypt(String sign){
// SM4Util
// }
}

View File

@@ -0,0 +1,67 @@
package cn.pluss.platform.klk.service;
import lombok.Data;
import java.util.Set;
@Data
public class LaKaLaVO {
private String version;
private String orderNo;
private String posType;
private String orgCode;
private String merRegName;
private String merBizName;
private String merRegDistCode;
private String merRegAddr;
private String mccCode;
private String merBlisName;
private String merBlis;
private String merBlisStDt;
private String merBlisExpDt;
private String merBusiContent;
private String larName;
private String larIdType;
private String larIdcard;
private String larIdcardStDt;
private String larIdcardExpDt;
private String merContactMobile;
private String merContactName;
private String shopName;
private String shopDistCode;
private String shopAddr;
private String shopContactName;
private String shopContactMobile;
private String openningBankCode;
private String openningBankName;
private String clearingBankCode;
private String acctNo;
private String acctName;
private String acctTypeCode;
private String settlePeriod;
private String clearDt;
private String acctIdType;
private String acctIdcard;
private String acctIdDt;
private String devSerialNo;
private String devTypeName;
private String termVer;
private String salesStaff;
private String termNum;
private String retUrl;
private Set feeData;
private String fileData;
private String contractNo;
private String feeAssumeType;
private String amountOfMonth;
private String serviceFee;
}
@Data
class FeeData{
private String feeRateTypeCode;
private String feeRatePct;
private String feeRateTypeName;
}

View File

@@ -0,0 +1,23 @@
package cn.pluss.platform.klk.service;
import cn.pluss.platform.klk.vo.OrganVo;
import cn.pluss.platform.klk.vo.TuoKeVo;
import java.util.List;
public interface LaKalaInterface {
/**
* 拉卡拉进件
* */
void laKaLaAddMer(LaKaLaVO laVO,String ip);
/**
* 拓客进件
* */
void tuoKeAddMer(TuoKeVo tuoKeVo);
/**
* 获取省市区县
* */
List<OrganVo> getOrganCode(String code);
}

View File

@@ -0,0 +1,87 @@
package cn.pluss.platform.klk.service;
import cn.pluss.platform.dto.MemberScanPayDTO;
import cn.pluss.platform.dto.MerChantOrderDTO;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.pay.PayService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
@Service("lkLPayService")
@Slf4j
public class LkLPayServiceImpl implements PayService {
@Resource
LklPayService lklPayService;
@Override
public JSONObject tradePay(MerchantOrder order, MerchantChannelStatus channel, MerchantBaseInfo merchant) {
return null;
}
@Override
public JSONObject tradePay(MerChantOrderDTO merchantOrderDTO, MerchantOrder order) {
return null;
}
@Override
public Map<String, Object> refundPay(MerchantOrder order, String mchNo) {
return null;
}
@Override
public JSONObject tradeQuery(MerchantOrder order, String mchId) {
return null;
}
@Override
public JSONObject refundQuery(MerchantRefundOrder refundOrder) {
return null;
}
@Override
public Map<String, Object> closeOrder(String orderNumber, String channelNo) {
return null;
}
@Override
public Map<String, Object> getWxOpenId(MemberScanPayDTO memberScanPayDTO, MerchantChannelStatus channel) throws Exception {
return null;
}
@Override
public Map<String, Object> getUnionInfo(String userAuthCode, String paymentApp, String merchantId) throws Exception {
Map<String, Object> result = new HashMap<>();
JSONObject reqData = new JSONObject(2);
Map<String, Object> stringObjectMap=lklPayService.authUserId(userAuthCode, paymentApp);
reqData.put("data",stringObjectMap.get("userId"));
reqData.put("userAuthCode",userAuthCode);
reqData.put("appUpIdentifier",paymentApp);
result.put("data",reqData);
result.put("code","1");
result.put("msg","获取成功");
return result;
}
@Override
public Object payNotifyCallBack(Map<String, String> params) {
return null;
}
@Override
public String tradePayWap(MerchantOrder order, MerchantChannelStatus channel) {
return null;
}
@Override
public JSONObject getUnionAccountUrl(JSONObject reqData) {
return null;
}
@Override
public JSONObject jftPay(JftReceiptOrder order, JftMercBaseInfo jftMerc, JftMercPaymentChannel jftChannel) {
return null;
}
}

View File

@@ -0,0 +1,483 @@
package cn.pluss.platform.klk.service;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.io.IOUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Test;
import org.springframework.stereotype.Service;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.cert.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
@Service
@Slf4j
public class LklPayService {
private static Integer index = 0;
/**
* 字符集固定 utf-8
*/
/**
* API schema ,固定 LKLAPI-SHA256withRSA
*/
public final static String SCHEMA = "LKLAPI-SHA256withRSA";
private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final SecureRandom RANDOM = new SecureRandom();
private String appId = "OP00000354";
// private String appId="OP00000657";
private String mchSerialNo = "00dfba8194c41b84cf";
private String merchantNo = "8221210594300JY";
private String termNo = "A0073841";
// private String privateKeyPath="classpath:lakalaConf/OP00000003_private_key.pem";
private String privateKeyPath = "C:\\Users\\Administrator\\Desktop\\dr\\OP00000003_private_key.pem";
// private String cerPath="C:\\Users\\Administrator\\Desktop\\dr\\lkl-apigw-v1.cer";
private String cerPath = "C:\\Users\\Administrator\\Desktop\\dr\\OP00000003_cert.cer";
private String apiUrl = "https://test.wsmsd.cn/sit";
String apiPath = "/api/v2/saas/query/wx_openid_query";
// private String apiUrl="https://s2.lakala.com";
@Test
public void test1() {
LaKaLaVO laVO = new LaKaLaVO();
createOrder(laVO, "127.0.0.1");
}
public String createOrder(LaKaLaVO laVO, String ip) {
//public String createOrder(String body,String apiPath,String ip) {
// String apiPath = "/api/v2/mms/openApi/addMer";
// String apiPath = "/api/v3/labs/trans/preorder";
// String apiPath = "/api/v3/labs/relation/revoked";
// String apiPath = "/api/v2/mms/openApi/addMer";
//ordCode存在异议
// String body ="{ \n" +
// " \"reqData\":{ \n" +
// " \"version\":\"1.0\", \n" +
// " \"orderNo\":\"2021031215011012345678\", \n" +
// " \"posType\":\"SUPER_POS\", \n" +
// " \"orgCode\":\"1\", \n" +
// " \"merRegName\":\"开放平台商户进件注册名称\", \n" +
// " \"merBizName\":\"开放平台商户进件经营名称\", \n" +
// " \"merRegDistCode\":\"290012\", \n" +
// " \"merRegAddr\":\"五星路102号\", \n" +
// " \"mccCode\":\"7011\", \n" +
// " \"merBusiContent\":\"640\", \n" +
// " \"larName\":\"张三丰\", \n" +
// " \"larIdType\":\"01\", \n" +
// " \"larIdcard\":\"33088119690117459X\", \n" +
// " \"larIdcardExpDt\":\"2051-01-10\", \n" +
// " \"merContactMobile\":\"15878559969\", \n" +
// " \"merContactName\":\"张三丰\", \n" +
// " \"settlePeriod\":\"T+1\", \n" +
// " \"openningBankCode\":\"102100000030\", \n" +
// " \"openningBankName\":\"中国工商银行股份有限公司北京市分行营业部\", \n" +
// " \"clearingBankCode\":\"102100099996\", \n" +
// " \"acctNo\":\"6212260200102400000\", \n" +
// " \"acctName\":\"仲涛飘\", \n" +
// " \"acctTypeCode\":\"58\", \n" +
// " \"acctIdcard\":\"33088119690117459X\", \n" +
// " \"devSerialNo\":\"yp13293921932131\", \n" +
// " \"devTypeName\":\"V8\", \n" +
// " \"termVer\":\"1.0\", \n" +
// " \"salesStaff\":\"销售3356\", \n" +
// " \"retUrl\":\"http://10.177.93.135:8082/notify\", \n" +
// " \"feeData\":[\n" +
// " { \n" +
// " \"feeRateTypeCode\":\"300\", \n" +
// " \"feeRatePct\":\"0.38\", \n" +
// " \"feeUpperAmtPcnt\":\"20\", \n" +
// " \"feeLowerAmtPcnt\":\"10\"\n" +
// " },\n" +
// " { \n" +
// " \"feeRateTypeCode\":\"301\", \n" +
// " \"feeRatePct\":\"0.58\"\n" +
// " },\n" +
// " { \n" +
// " \"feeRateTypeCode\":\"302\", \n" +
// " \"feeRatePct\":\"0.48\"\n" +
// " },\n" +
// " { \n" +
// " \"feeRateTypeCode\":\"303\", \n" +
// " \"feeRatePct\":\"0.48\"\n" +
// " }\n" +
// " ], \n" +
// " \"fileData\":[\n" +
// " { \n" +
// " \"attType\":\"ID_CARD_FRONT\", \n" +
// " \"attFileId\":\"G1/M00/00/61/CrFdEl3IyceAVVd8AAA0ADuZsA0911.jpg\"\n" +
// " }\n" +
// " ]\n" +
// " }, \n" +
// " \"ver\":\"1.0.0\", \n" +
// " \"timestamp\":\"1541589957000\", \n" +
// " \"reqId\":\"baff59de4694438ca9089862253517a5\"\n" +
// "}";
Integer type = null;
String subAppid = "";
String subOpenid = "";
String body = "";
String orderNumber = "";
String consumeFee = "";
HttpServletRequest request = null;
body = "{ \n" +
" \"ver\": \"1.0.0\",\n" +
" \"timestamp\": \"1541589957000\",\n" +
" \"reqId\": \"ca9089862253517a5\",\n" +
" \"reqData\": {\n" +
" \"mercId\": \"" + merchantNo + "\",\n" +
" \"termNo\": \"" + termNo + "\",\n" +
" \"authCode\": \"136519690623734145\",\n" +
" \"tradeCode\":\"030304\"\n" +
" }\n" +
"}";
// if (type==51||type==71){
//
// body="{\n" +
// " \"out_org_code\":\""+appId+"\",\n" +
// " \"req_data\":{\n" +
// " \"acc_busi_fields\":{\n" +
// " \"detail\":\"{\\\"goods_detail\\\":[{\\\\\\\"goods_id\\\\\\\":\\\\\\\"100734033\\\\\\\",\\\\\\\"price\\\\\\\":\\\\\\\"50\\\\\\\",\\\\\\\"quantity\\\\\\\":\\\\\\\"1\\\\\\\"}]}\",\n" +
// " \"goods_tag\":\"ceshi\",\n" +
// " \"sub_appid\":\""+subAppid+"\",\n" +
// " \"user_id\":\""+subOpenid+"\"\n" +
// " },\n" +
// " \"account_type\":\"WECHAT\",\n" +
// " \"location_info\":{\n" +
// " \"request_ip\":\""+IpUtils.getIpAddr(request)+"\"\n" +
// " },\n" +
// " \"merchant_no\":\""+merchantNo+"\",\n" +
// " \"notify_url\":\"https://testca/notify\",\n" +
// " \"out_trade_no\":\""+orderNumber+"\",\n" +
// " \"term_no\":\""+ laVO.getTermNum()+"\",\n" +
// " \"total_amount\":\""+consumeFee+"\",\n" +
// " \"trans_type\":\""+type+"\"\n" +
// " },\n" +
// " \"req_time\":\""+getNowDate()+"\",\n" +
// " \"version\":\"3.0\"\n" +
// "}";
// }else if (type==41){
// body="{\n" +
// " \"out_org_code\":\""+appId+"\",\n" +
// " \"req_data\":{\n" +
// " \"acc_busi_fields\":{\n" +
// " \"detail\":\"{\\\"goods_detail\\\":[{\\\\\\\"goods_id\\\\\\\":\\\\\\\"100734033\\\\\\\",\\\\\\\"price\\\\\\\":\\\\\\\"50\\\\\\\",\\\\\\\"quantity\\\\\\\":\\\\\\\"1\\\\\\\"}]}\",\n" +
// " \"goods_tag\":\"ceshi\",\n" +
// " \"sub_appid\":\""+subAppid+"\",\n" +
// " \"user_id\":\""+subOpenid+"\"\n" +
// " },\n" +
// " \"account_type\":\"WECHAT\",\n" +
// " \"location_info\":{\n" +
// " \"request_ip\":\""+IpUtils.getIpAddr(request)+"\"\n" +
// " },\n" +
// " \"merchant_no\":\""+merchantNo+"\",\n" +
// " \"notify_url\":\"https://testca/notify\",\n" +
// " \"out_trade_no\":\""+orderNumber+"\",\n" +
// " \"term_no\":\""+ laVO.getTermNum()+"\",\n" +
// " \"total_amount\":\""+consumeFee+"\",\n" +
// " \"trans_type\":\""+type+"\"\n" +
// " },\n" +
// " \"req_time\":\""+getNowDate()+"\",\n" +
// " \"version\":\"3.0\"\n" +
// "}";
// }
return "";
}
public Map<String, Object> authUserId(String authCode, String appUpIdentifier) {
String body = "{ \n" +
" \"ver\": \"1.0.0\",\n" +
" \"timestamp\": \"1541589957000\",\n" +
" \"reqId\": \"ca9089862253517a5\",\n" +
" \"reqData\": {\n" +
" \"mercId\": \"" + merchantNo + "\",\n" +
" \"termNo\": \"" + termNo + "\",\n" +
" \"authCode\": \"" + authCode + "\",\n" +
" \"tradeCode\":\"030304\",\n" +
" \"appUpIdentifier\":\"" + appUpIdentifier + "\"\n" +
" }\n" +
"}";
Map map = (Map) JSONArray.parse(req(body));
return (Map<String, Object>) JSONArray.parse(map.get("reqData").toString());
}
public String req(String body) {
String encode = encode("client_id:client_secret".getBytes());
System.out.println("base64:" + encode);
try {
String authorization = getAuthorization(body, appId, mchSerialNo, privateKeyPath);
HttpResponse lakalaResponse = post(apiUrl + apiPath, body, authorization, "utf-8");
if (lakalaResponse.getStatusLine().getStatusCode() != 200) {
log.error("请求失败,statusCode:{},message:{}", lakalaResponse.getStatusLine(), IOUtils.toString(lakalaResponse.getEntity().getContent(), "utf-8"));
}
String appid = getHeadValue(lakalaResponse, "Lklapi-Appid");
String lklapiSerial = getHeadValue(lakalaResponse, "Lklapi-Serial");
String timestamp = getHeadValue(lakalaResponse, "Lklapi-Timestamp");
String nonce = getHeadValue(lakalaResponse, "Lklapi-Nonce");
String signature = getHeadValue(lakalaResponse, "Lklapi-Signature");
String responseStr = IOUtils.toString(lakalaResponse.getEntity().getContent(), "utf-8");
log.info("返回的信息为 responseStr:{}", responseStr);
String source = appid + "\n" + lklapiSerial + "\n" + timestamp + "\n" + nonce + "\n" + responseStr + "\n";
log.info("请求的数据为:{}", source);
// X509Certificate lklCertificate = loadCertificate(new FileInputStream(new File(privateKeyPath)));
X509Certificate lklCertificate = loadCertificate(new FileInputStream(new File(cerPath)));
boolean verify = verify(lklCertificate, source.getBytes("utf-8"), signature);
if (verify) {
log.info("验签通过");
return responseStr;
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static String encode(byte[] content) {
return new sun.misc.BASE64Encoder().encode(content);
}
public static boolean isNumeric(String str) {
//?:0或1个, *:0或多个, +:1或多个
Boolean strResult = str.matches("-?[0-9]+.?[0-9]*");
if (strResult == true) {
return true;
} else {
return false;
}
}
private boolean isNumber(String str) {
for (int i = str.length(); --i >= 0; ) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
public HttpResponse post(String url, String message, String authorization, String ENCODING) throws Exception {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] xcs, String str) {
}
@Override
public void checkServerTrusted(X509Certificate[] xcs, String str) {
}
};
HttpClient http = new DefaultHttpClient();
ClientConnectionManager ccm = http.getConnectionManager();
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
SchemeRegistry registry = ccm.getSchemeRegistry();
registry.register(new Scheme("https", ssf, 443));
HttpPost post = new HttpPost(url);
StringEntity myEntity = new StringEntity(message, ENCODING);
post.setEntity(myEntity);
post.setHeader("Authorization", SCHEMA + " " + authorization);
post.setHeader("Accept", "application/json");
post.setHeader("Content-Type", "application/json");
return http.execute(post);
}
private String getNowDate() {
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
return simpleDateFormat.format(date);
}
private String getRandom() {
String rand = "";
for (int i = 0; i < 8; i++) {
rand = rand + (int) (Math.random() * 10);
}
return rand;
}
public String createOrderCode() {
String OrderCode = getNowDate() + getRandom();
return OrderCode;
}
protected long generateTimestamp() {
return System.currentTimeMillis() / 1000;
}
protected String generateNonceStr() {
char[] nonceChars = new char[32];
for (int index = 0; index < nonceChars.length; ++index) {
nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
}
return new String(nonceChars);
}
public final String getAuthorization(String body, String appid, String mchSerialNo, String merchantPrivateKeyPath) throws IOException {
String nonceStr = generateNonceStr();
long timestamp = generateTimestamp();
String message = appid + "\n" + mchSerialNo + "\n" + timestamp + "\n" + nonceStr + "\n" + body + "\n";
System.out.println("getToken message : " + message);
PrivateKey merchantPrivateKey = loadPrivateKey(new FileInputStream(new File(merchantPrivateKeyPath)));
String signature = this.sign(message.getBytes("utf-8"), merchantPrivateKey);
String authorization = "appid=\"" + appid + "\"," + "serial_no=\"" + mchSerialNo + "\"," + "timestamp=\""
+ timestamp + "\"," + "nonce_str=\"" + nonceStr + "\"," + "signature=\"" + signature + "\"";
System.out.println("authorization message :" + authorization);
return authorization;
}
public String sign(byte[] message, PrivateKey privateKey) {
try {
Signature sign = Signature.getInstance("SHA256withRSA");
sign.initSign(privateKey);
sign.update(message);
return new String(Base64.encodeBase64(sign.sign()));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("当前Java环境不支持SHA256withRSA", e);
} catch (SignatureException e) {
throw new RuntimeException("签名计算失败", e);
} catch (InvalidKeyException e) {
throw new RuntimeException("无效的私钥", e);
}
}
private static String getHeadValue(HttpResponse response, String key) {
return (response.containsHeader(key)) ? response.getFirstHeader(key).getValue() : "";
}
private static boolean verify(X509Certificate certificate, byte[] message, String signature) {
try {
Signature sign = Signature.getInstance("SHA256withRSA");
sign.initVerify(certificate);
sign.update(message);
byte[] signatureB = Base64.decodeBase64(signature);
return sign.verify(signatureB);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("当前Java环境不支持SHA256withRSA", e);
} catch (SignatureException e) {
throw new RuntimeException("签名验证过程发生了错误", e);
} catch (InvalidKeyException e) {
throw new RuntimeException("无效的证书", e);
}
}
public static PrivateKey loadPrivateKey(InputStream inputStream) {
try {
ByteArrayOutputStream array = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
array.write(buffer, 0, length);
}
String privateKey = array.toString("utf-8").replace("-----BEGIN PRIVATE KEY-----", "")
.replace("-----END PRIVATE KEY-----", "").replaceAll("\\s+", "");
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("当前Java环境不支持RSA", e);
} catch (InvalidKeySpecException e) {
throw new RuntimeException("无效的密钥格式");
} catch (IOException e) {
throw new RuntimeException("无效的密钥");
}
}
public static X509Certificate loadCertificate(InputStream inputStream) {
try {
CertificateFactory cf = CertificateFactory.getInstance("X509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(inputStream);
cert.checkValidity();
return cert;
} catch (CertificateExpiredException e) {
throw new RuntimeException("证书已过期", e);
} catch (CertificateNotYetValidException e) {
throw new RuntimeException("证书尚未生效", e);
} catch (CertificateException e) {
throw new RuntimeException("无效的证书", e);
}
}
protected final String getBody(HttpServletRequest request) throws Exception {
InputStreamReader in = null;
try {
in = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuffer bf = new StringBuffer();
int len;
char[] chs = new char[1024];
while ((len = in.read(chs)) != -1) {
bf.append(new String(chs, 0, len));
}
return bf.toString();
} catch (Exception e) {
log.error("请求头部取数据异常:{}", e);
throw new RuntimeException("999999", e.getCause());
} finally {
if (null != in) {
try {
in.close();
} catch (Exception e) {
log.error("流关闭异常:{}", e);
}
}
}
}
}

View File

@@ -0,0 +1,7 @@
package cn.pluss.platform.klk.service;
import cn.pluss.platform.entity.PlussMerchantLklEntity;
import com.baomidou.mybatisplus.extension.service.IService;
public interface PlussMerchantLklService extends IService<PlussMerchantLklEntity> {
}

View File

@@ -0,0 +1,7 @@
package cn.pluss.platform.klk.service;
import cn.pluss.platform.entity.TbLklRegionBankInfoEntity;
import com.baomidou.mybatisplus.extension.service.IService;
public interface TbLklRegionBankInfoService extends IService<TbLklRegionBankInfoEntity> {
}

View File

@@ -0,0 +1,7 @@
package cn.pluss.platform.klk.service;
import cn.pluss.platform.entity.TbPlussBankBranchLklEntity;
import com.baomidou.mybatisplus.extension.service.IService;
public interface TbPlussBankBranchLklService extends IService<TbPlussBankBranchLklEntity> {
}

View File

@@ -0,0 +1,7 @@
package cn.pluss.platform.klk.service;
import cn.pluss.platform.entity.TbPlussBankRegionLklEntity;
import com.baomidou.mybatisplus.extension.service.IService;
public interface TbPlussBankRegionLklService extends IService<TbPlussBankRegionLklEntity> {
}

View File

@@ -0,0 +1,7 @@
package cn.pluss.platform.klk.service;
import cn.pluss.platform.entity.TbPlussBusinessSmallLklEntity;
import com.baomidou.mybatisplus.extension.service.IService;
public interface TbPlussBusinessSmallLklService extends IService<TbPlussBusinessSmallLklEntity> {
}

View File

@@ -0,0 +1,7 @@
package cn.pluss.platform.klk.service;
import cn.pluss.platform.entity.TbPlussRegionLklEntity;
import com.baomidou.mybatisplus.extension.service.IService;
public interface TbPlussRegionLklService extends IService<TbPlussRegionLklEntity> {
}

View File

@@ -0,0 +1,53 @@
package cn.pluss.platform.klk.service.impl;
import org.springframework.core.io.InputStreamResource;
import java.io.InputStream;
public class CommonInputStreamResource extends InputStreamResource {
/***
* 文件長度
*/
private int length;
/***
* 文件名稱
*/
private String fileName;
public CommonInputStreamResource(InputStream inputStream) {
super(inputStream);
}
public CommonInputStreamResource(InputStream inputStream, int length,String fileName) {
super(inputStream);
this.length = length;
this.fileName = fileName;
}
/**
* 覆写父类方法
* 如果不重写这个方法,并且文件有一定大小,那么服务端会出现异常
* {@code The multi-part request contained parameter data (excluding uploaded files) that exceeded}
*
* @return
*/
@Override
public String getFilename() {
return this.fileName;
}
/**
* 覆写父类 contentLength 方法
* 因为 {@link org.springframework.core.io.AbstractResource#contentLength()}方法会重新读取一遍文件,
* 而上传文件时restTemplate 会通过这个方法获取大小。然后当真正需要读取内容的时候,发现已经读完,会报如下错误。
* <code>
* java.lang.IllegalStateException: InputStream has already been read - do not use InputStreamResource if a stream needs to be read multiple times
* at org.springframework.core.io.InputStreamResource.getInputStream(InputStreamResource.java:96)
* </code>
* <p>
* ref:com.amazonaws.services.s3.model.S3ObjectInputStream#available()
*
* @return
*/
@Override
public long contentLength() {
int estimate = length;
return estimate == 0 ? 1 : estimate;
}
}

View File

@@ -0,0 +1,789 @@
package cn.pluss.platform.klk.service.impl;
import cn.pluss.platform.BankCardService;
import cn.pluss.platform.IdCardService;
import cn.pluss.platform.channel.ys.impl.YSAuditServiceV3;
import cn.pluss.platform.dto.AccountDTO;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.klk.LaKaLaUtility;
import cn.pluss.platform.klk.service.*;
import cn.pluss.platform.klk.vo.*;
import cn.pluss.platform.mcc.MccReflectService;
import cn.pluss.platform.merchant.AccountService;
import cn.pluss.platform.merchant.MerchantBaseInfoService;
import cn.pluss.platform.merchantChannelStatus.MerchantChannelStatusService;
import cn.pluss.platform.userApp.UserAppService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.*;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
@Service
public class LaKalaInterfaceImpl implements LaKalaInterface {
@Resource
LklPayService lklPayService;
@Resource
TbLklRegionBankInfoServiceImpl tbLklRegionBankInfoServiceImpl;
@Resource
TbPlussBankBranchLklService tbPlussBankBranchLklService;
@Resource
UserAppService uaService;
@Resource
private MerchantBaseInfoService mbiService;
@Resource
BankCardService bankCardService;
@Resource
private TbPlussRegionLklService tbPlussRegionLklService;
@Resource
private IdCardService idCardService;
@Resource
private TbPlussBankRegionLklService regionLklService;
@Resource
AccountService accountService;
@Lazy
@Resource
private MerchantChannelStatusService mcsService;
@Resource
MerchantBaseInfoService baseInfoService;
@Resource
TbPlussBusinessSmallLklService businessSmallLklService;
@Resource
MccReflectService service;
@Resource
PlussMerchantLklService merchantLklService;
// private static final String client_id = "chaozhanggui";
// private static final String client_secret = "Y54Gqy6aLpxld3dp";
// private static final String grant_type = "client_credentials";
// private static final String userNo = "22241007";
// /**
// * 商户进件
// */
// private static final String tuoKeMerchat = "https://htkactvi.lakala.com/registration/merchant";
// /**
// * 获取地区信息
// */
// private static final String organparentCode = "https://htkactvi.lakala.com/registration/organization/";
// /**
// * 获取银行地区信息
// */
// private static final String organizationBank = "https://htkactvi.lakala.com/registration/organization/bank/";
// /**
// * 文件上传
// */
// private static final String fileUpload = "https://htkactvi.lakala.com/registration/file/upload";
// private static final String tuoKeToken = "https://tkapi.lakala.com/auth/oauth/token";
/************************************************测试信息***************************************************/
private static final String client_id = "testsit";
private static final String client_secret = "EguwEckByf2I6u6z";
private static final String grant_type = "client_credentials";
private static final String userNo = "20000101";
/**
* 商户进件
*/
private static final String tuoKeMerchat = "https://test.wsmsd.cn/sit/htkregistration/merchant";
/**
* 获取地区信息
*/
private static final String organparentCode = "https://test.wsmsd.cn/sit/htkregistration/organization/";
/**
* 获取银行地区信息
*/
private static final String organizationBank = "https://test.wsmsd.cn/sit/htkregistration/organization/bank/";
/**
* 文件上传
*/
private static final String fileUpload = "https://test.wsmsd.cn/sit//htkregistration/file/upload";
private static final String tuoKeToken = "https://test.wsmsd.cn/sit/htkauth/oauth/token";
/**
* 拉卡拉模式进件
*/
@Override
public void laKaLaAddMer(LaKaLaVO laVO, String ip) {
String apiPath = "/api/v2/mms/openApi/addMer";
JSONObject object1 = new JSONObject();
JSONObject object2 = new JSONObject();
object1.put("reqData", object2);
object2.put("version", "1.0"); //接口版本号
object2.put("orderNo", laVO.getOrderNo()); //订单编号(便于后续跟踪排查问题及核对报文)
object2.put("posType", laVO.getPosType()); //进件POS类型 —按接入系统做控制,参见 【POS类型字典表】
object2.put("orgCode", "1"); //机构代码 (合作方在拉卡拉的标识,请联系业务员)
object2.put("merRegName", laVO.getMerRegName()); //商户注册名称
object2.put("merRegDistCode", laVO.getMerRegDistCode()); //地区代码,参看地区文档]
object2.put("merRegAddr", laVO.getMerRegAddr()); //商户详细地址
object2.put("mccCode", laVO.getMccCode()); //商户MCC编号
if (null != laVO.getMerBlisName() || null != laVO.getMerBlis()) { //小微商户可不传,其它必传,为空则小微商户
object2.put("merBlisName", laVO.getMerBlisName()); //营业执照名称
object2.put("merBlis", laVO.getMerBlis()); //营业执照号
object2.put("merBlisStDt", laVO.getMerBlisStDt()); //营业执照开始日期
object2.put("merBlisExpDt", "1.0"); //营业执照有效期
}
object2.put("merBusiContent", laVO.getMerBusiContent()); //参看【经营内容字典表】文档
object2.put("larName", laVO.getLarName()); //商户法人姓名
object2.put("larIdType", laVO.getLarIdType()); //支持其他证件类型,见参【证件类型字典表】
object2.put("larIdcard", laVO.getLarIdcard()); //法人身份证号码
object2.put("larIdcardStDt", laVO.getLarIdcardStDt()); //法人身份证开始日期 yyyy-MM-dd
object2.put("larIdcardExpDt", laVO.getLarIdcardExpDt()); //法人身份证有效期 yyyy-MM-dd
object2.put("merContactMobile", laVO.getMerContactMobile()); //商户联系人手机号码
object2.put("merContactName", laVO.getMerContactName()); //商户联系人
object2.put("openningBankCode", laVO.getOpenningBankCode()); //可根据结算卡信息进行查询仅支持对私结算卡查询参见【卡BIN信息查询】
object2.put("openningBankName", laVO.getOpenningBankName()); //可根据结算卡信息进行查询仅支持对私结算卡查询参见【卡BIN信息查询】
object2.put("clearingBankCode", laVO.getClearingBankCode()); //可根据结算卡信息进行查询仅支持对私结算卡查询参见【卡BIN信息查询】
object2.put("acctNo", laVO.getAcctNo()); //结算账户账号
object2.put("acctName", laVO.getAcctName()); //结算账户名称
object2.put("acctTypeCode", laVO.getAcctTypeCode()); //结算账户性质 57对公 58 对私
object2.put("settlePeriod", laVO.getSettlePeriod()); //结算周期 参见【结算周期表】
object2.put("retUrl", "1.0"); //回调地址url
object2.put("feeData", laVO.getFeeData()); //费率信息集合 参看下方【费率信息】
// orderService.createOrder(object1.toString(),apiPath,"");
}
/**
* 拉卡拉拓客进件
* */
public TuoKeVo createTuoKeInfo(String userId) {
MerchantBaseInfo merchantBaseInfo = mbiService.getMerchantBaseInfoByUserId(userId);
TuoKeVo tuoKeVo = new TuoKeVo();
tuoKeVo.setBusiCode(""); //业务类型
tuoKeVo.setEmail("chaozhanggui2023@163.com");
tuoKeVo.setMerchantCode(merchantBaseInfo.getMerchantCode());
tuoKeVo.setMerRegName(merchantBaseInfo.getMerchantName());//商户注册名称
if (merchantBaseInfo.getMerchantType().equals("1") || merchantBaseInfo.getMerchantType().equals("2")) { //商户类型/营业执照类型 可选值1:小微2:个体3:企业
tuoKeVo.setMerType("TP_PERSONAL");//商户注册类型 TP_MERCHANT:企业 TP_PERSONAL:⼩微个⼈
} else {
tuoKeVo.setMerType("TP_MERCHANT");//商户注册类型
}
tuoKeVo.setMerName(merchantBaseInfo.getMerchantName()); //商户名称(经营名称
tuoKeVo.setMerAddr(merchantBaseInfo.getAddress()); //市区后的详细地址
List<OrganVo> proOrganCode = getOrganCode("1");
System.out.println("proOrganCode :" + proOrganCode);
String cityCode = null;
for (OrganVo organVo : proOrganCode) { //省code
if (organVo.getName().equals(merchantBaseInfo.getProvince())) {
QueryWrapper<TbPlussRegionLklEntity> wrapper = new QueryWrapper<>();
wrapper.eq("name", merchantBaseInfo.getProvince()).last("limit 1");
TbPlussRegionLklEntity one = tbPlussRegionLklService.getOne(wrapper);
tuoKeVo.setProvinceCode(one.getCode());
cityCode = one.getCode();
break;
}
}
List<OrganVo> cityOrganCode = getOrganCode(cityCode); //市code
for (OrganVo organVo : cityOrganCode) {
if (organVo.getName().equals(merchantBaseInfo.getCity())) {
QueryWrapper<TbPlussRegionLklEntity> wrapper = new QueryWrapper<>();
wrapper.eq("name", merchantBaseInfo.getCity()).last("limit 1");
TbPlussRegionLklEntity one = tbPlussRegionLklService.getOne(wrapper);
tuoKeVo.setCityCode(one.getCode());
cityCode = one.getCode();
break;
}
}
List<OrganVo> countyOrganCode = getOrganCode(cityCode); //区code
for (OrganVo organVo : countyOrganCode) {
if (organVo.getName().equals(merchantBaseInfo.getDistrict())) {
QueryWrapper<TbPlussRegionLklEntity> wrapper = new QueryWrapper<>();
wrapper.eq("name", merchantBaseInfo.getDistrict()).last("limit 1");
TbPlussRegionLklEntity one = tbPlussRegionLklService.getOne(wrapper);
tuoKeVo.setCountyCode(one.getCode());
cityCode = one.getCode();
break;
}
}
if (!merchantBaseInfo.getMerchantType().equals("1")) {// 非小微商户类型
tuoKeVo.setLicenseName(merchantBaseInfo.getBussAuthName()); //营业执照名称
tuoKeVo.setLicenseNo(merchantBaseInfo.getBussAuthNum());//营业执照号码 ⼩微商户可不传, 其他必传
tuoKeVo.setLicenseDtStart(merchantBaseInfo.getBussAuthStartTime());//营业执照开始时间⼩微商户可不传, 其他必传格式yyyy-MM-dd
tuoKeVo.setLicenseDtEnd(merchantBaseInfo.getBussAuthEndTime());//⼩微商户可不传, 其他必传格式yyyy-MM-dd
}
tuoKeVo.setLatitude("");//经度 进件所在地址经度
tuoKeVo.setLongtude("");//纬度 进件所在地址纬度
tuoKeVo.setSource("APP"); //进件来源 APP: app H5: h5
tuoKeVo.setBusinessContent(merchantBaseInfo.getMccName()); //商户经营内容
IdCard one = idCardService.getLegalIdCard(userId); //获取法人身份证信息
tuoKeVo.setLarName(one.getCertName());
tuoKeVo.setLarIdType("01");
tuoKeVo.setLarIdCard(one.getCertNo());
tuoKeVo.setLarIdCardStart(birthdayDate(one.getCertStartTime()));
tuoKeVo.setLarIdCardEnd(birthdayDate(one.getCertEndTime()));
tuoKeVo.setContactMobile(merchantBaseInfo.getContactMobile());
tuoKeVo.setContactName(merchantBaseInfo.getContactName());
QueryWrapper<Account> accountQueryWrapper1 = new QueryWrapper<>();
accountQueryWrapper1.eq("userId", userId);
accountQueryWrapper1.eq("channelType", "D1");
Account accountServiceOne1 = accountService.getOne(accountQueryWrapper1);
QueryWrapper<BankCard> bankCardWrapper = new QueryWrapper<>();
bankCardWrapper.eq("id", accountServiceOne1.getBankCardId());
BankCard userBrakCard = bankCardService.getOne(bankCardWrapper);
QueryWrapper<TbPlussBankBranchLklEntity> lklEntityQueryWrapper = new QueryWrapper<>();
lklEntityQueryWrapper.eq("branch_bank_no", userBrakCard.getContactLine());
TbPlussBankBranchLklEntity lakalaBranchInfo = tbPlussBankBranchLklService.getOne(lklEntityQueryWrapper);
tuoKeVo.setOpenningBankCode(lakalaBranchInfo.getBranchBankNo());
tuoKeVo.setOpenningBankName(lakalaBranchInfo.getBranchBankName());
tuoKeVo.setClearingBankCode(lakalaBranchInfo.getClearNo());
QueryWrapper<TbPlussBankRegionLklEntity> regionLklEntityQueryWrapper = new QueryWrapper<>();
regionLklEntityQueryWrapper.eq("code", lakalaBranchInfo.getAreaCode());
TbPlussBankRegionLklEntity bankParentCode = regionLklService.getOne(regionLklEntityQueryWrapper); //市code 和 name
regionLklEntityQueryWrapper.clear();
regionLklEntityQueryWrapper.eq("code", bankParentCode.getParentCode());
TbPlussBankRegionLklEntity parentCode = regionLklService.getOne(regionLklEntityQueryWrapper); //省code 和 名称
tuoKeVo.setSettleProvinceCode(parentCode.getCode());
tuoKeVo.setSettleProvinceName(parentCode.getName());
tuoKeVo.setSettleCityCode(bankParentCode.getCode());
tuoKeVo.setSettleCityName(bankParentCode.getName());
Account account = new Account().setUserId("userId").setChannelType("D1");
AccountDTO accountV4 = getAccountV4(userId, "D1"); //结算人
/**获取结算人**/
BankCard bankCard = accountV4.getBankCard();
tuoKeVo.setAccountNo(bankCard.getBankCardNo());
tuoKeVo.setAccountName(bankCard.getBranchName());
if (bankCard.getAccountType().equals("01")) {
tuoKeVo.setAccountType("58"); //结算账户类型 57 对公 58 对私
} else {
tuoKeVo.setAccountType("57");
}
IdCard idcard = accountV4.getIdcard();
tuoKeVo.setAccountIdCard(idcard.getCertNo());//结算人证件号码
tuoKeVo.setTermNum("1");
tuoKeVo.setFeeCode("SCAN_PAY_SECOND"); //费率类型 参考 附录 费率类型表
tuoKeVo.setFeeValue("0.038"); //费率值 百分比费率
MerchantBaseInfo merchantBaseInfoByUserId = baseInfoService.getMerchantBaseInfoByUserId(userId);
QueryWrapper<MccReflect> userAppQueryWrapper = new QueryWrapper();
userAppQueryWrapper.eq("standard_mcc_code", merchantBaseInfoByUserId.getMcc()).eq("channel_id", "5").last("limit 1");
MccReflect mccReflect = service.getOne(userAppQueryWrapper);
if (null != mccReflect) {
tuoKeVo.setMcc("11010"); //商户MCC编号 通过 【商户类别查询→查询小类】接口获取 对应 code字段
// tuoKeVo.setMcc(mccReflect.getMccCode()); //商户MCC编号 通过 【商户类别查询→查询小类】接口获取 对应 code字段
} else {
tuoKeVo.setMcc("18001");
}
tuoKeVo.setActivityId("12"); //归属活动信息 由拓客SAAS分配
Set<Object> attchmentsVoSet = new HashSet<>();
AttchmentsVo frontLegalPerson = new AttchmentsVo(); //图片set
frontLegalPerson.setId(laKaLaFileUpload(idcard.getImgPositive()));//法人身份证图片地址
frontLegalPerson.setType("ID_CARD_FRONT");//身份证正⾯
AttchmentsVo reverseLegalPerson = new AttchmentsVo();
reverseLegalPerson.setId(idcard.getImgNegative()); //法人身份证图片地址
reverseLegalPerson.setType("ID_CARD_BEHIND");//身份证反⾯
attchmentsVoSet.add(reverseLegalPerson);
tuoKeVo.setSet(attchmentsVoSet);
tuoKeVo.setSettleType("D1"); //结算类型 D0秒到 D1次日结算
tuoKeAddMer(tuoKeVo);
return tuoKeVo;
}
/**
* 参数组装
* */
@Override
public void tuoKeAddMer(TuoKeVo tuoKeVo) {
JSONObject object1 = new JSONObject();
JSONObject object2 = new JSONObject();
object1.put("userNo", userNo); //合作机构信息 由拓客SAAS提供
object1.put("email", tuoKeVo.getEmail()); //商户邮箱
// object1.put("busiCode", "PAPER_CODE");//业务类型 BPOS:传统POS, ZPOS:电签,ZPOS4G4G电签,SUPER_POS:智能pos,B_WIZARD:蓝精灵,PAPER_CODE:码牌,WECHAT_PAY:专业化扫码,KLYX:云音箱,QRCODE:收款王,MONEY_BOX:收钱宝盒根据业务开放取值
object1.put("busiCode", "PAPER_CODE");//业务类型 BPOS:传统POS, ZPOS:电签,ZPOS4G4G电签,SUPER_POS:智能pos,B_WIZARD:蓝精灵,PAPER_CODE:码牌,WECHAT_PAY:专业化扫码,KLYX:云音箱,QRCODE:收款王,MONEY_BOX:收钱宝盒根据业务开放取值
object1.put("merRegName", tuoKeVo.getMerRegName()); //商户注册名称 不能少于七个中文
object1.put("merType", tuoKeVo.getMerType()); //商户注册类型 TP_MERCHANT:企业 TP_PERSONAL:⼩微个⼈
object1.put("merName", tuoKeVo.getMerName()); //商户名称(经营名称) 不能少于七个中文
object1.put("merAddr", tuoKeVo.getMerAddr()); //去掉省,市区后的详细地址
object1.put("provinceCode", tuoKeVo.getProvinceCode()); //省代码 通过【地区信息→获取地区查询】接口获取 对应 code字段
object1.put("cityCode", tuoKeVo.getCityCode()); // 市代码 通过【地区信息→获取地区查询】接口获取 对应 code字段
object1.put("countyCode", tuoKeVo.getCountyCode()); // 区县代码 通过【地区信息→获取地区查询】接口获取 对应 code字段
object1.put("licenseName", tuoKeVo.getLicenseName()); //营业执照名称
object1.put("licenseNo", tuoKeVo.getLicenseNo()); //营业执照号码 ⼩微商户可不传, 其他必传
object1.put("licenseDtStart", tuoKeVo.getLicenseDtStart()); //营业执照开始时间⼩微商户可不传, 其他必传格式yyyy-MM-dd
object1.put("licenseDtEnd", tuoKeVo.getLicenseDtEnd()); //⼩微商户可不传, 其他必传格式yyyy-MM-dd
object1.put("latitude", "108.94647"); //经度 进件所在地址经度error
object1.put("longtude", "34.34727"); //纬度 进件所在地址纬度 error
object1.put("source", tuoKeVo.getSource()); //进件来源 APP: app H5: h5
object1.put("businessContent", tuoKeVo.getBusinessContent()); //商户经营内容
object1.put("larName", tuoKeVo.getLarName()); //法⼈姓名
object1.put("larIdType", tuoKeVo.getLarIdType()); //法⼈证件类型 01 身份证 暂时只支持身份证
object1.put("larIdCard", tuoKeVo.getLarIdCard()); //法⼈证件号码
object1.put("larIdCardStart", tuoKeVo.getLarIdCardStart()); //法⼈证件开始⽇期 格式yyyy-MM-dd
object1.put("larIdCardEnd", tuoKeVo.getLarIdCardEnd()); //法⼈证件过期时间 格式yyyy-MM-dd
object1.put("contactMobile", tuoKeVo.getContactMobile()); //商户联系⼈⼿机号码
object1.put("contactName", tuoKeVo.getContactName()); //商户联系⼈姓名
object1.put("openningBankCode", tuoKeVo.getOpenningBankCode()); //结算账户开户⾏号 通过【银行列表查询】接口获取 对应 branchBankNo字段
object1.put("openningBankName", tuoKeVo.getOpenningBankName()); //结算账户开户⾏名称 通过【银行列表查询】接口获取 对应 branchBankName字段
object1.put("clearingBankCode", tuoKeVo.getClearingBankCode()); //结算账户清算⾏号 通过【银行列表查询】接口获取 对应 clearNo字段
object1.put("settleProvinceCode", tuoKeVo.getSettleProvinceCode()); //结算信息省份名称 通过【地区信息→获取银行地区查询】接口获取 对应 code字段
object1.put("settleProvinceName", tuoKeVo.getSettleProvinceName()); //结算信息省份代码 通过【地区信息→获取银行地区查询】接口获取 对应 name字段
object1.put("settleCityCode", tuoKeVo.getSettleCityCode()); //结算信息城市名称 通过【地区信息→获取银行地区查询】接口获取 对应 code字段
object1.put("settleCityName", tuoKeVo.getSettleCityName()); //结算信息城市代码 通过【地区信息→获取银行地区查询】接口获取 对应 name字段
object1.put("accountNo", tuoKeVo.getAccountNo()); //结算人银行卡号
object1.put("accountName", tuoKeVo.getAccountName()); //结算人账户名称
object1.put("accountType", tuoKeVo.getAccountType()); //结算账户类型 57 对公 58 对私
// object1.put("accountIdType",tuoKeVo.getUserNo()); //结算⼈证件类型 为空同法⼈
object1.put("accountIdCard", tuoKeVo.getAccountIdCard()); //结算⼈证件号码
Set<FeesSetVo> feesSet = new HashSet<>();
FeesSetVo f = new FeesSetVo();
f.setFeeCode(tuoKeVo.getFeeCode());
f.setFeeValue(tuoKeVo.getFeeValue());
feesSet.add(f);
object2.put("termNum", tuoKeVo.getTermNum()); //终端数量 1-5 最⼤ 5个终端
object2.put("fees", feesSet); //费率集合
object2.put("mcc", tuoKeVo.getMcc()); //商户MCC编号 通过 【商户类别查询→查询小类】接口获取 对应 code字段
// object2.put("activityId", tuoKeVo.getActivityId()); //归属活动信息 由拓客SAAS分配
object2.put("activityId","37"); //归属活动信息 由拓客SAAS分配
object1.put("bizContent", object2); //业务扩展信息 参⻅ 业务扩展信息
//
// Set<AttchmentsVo> attchmentsVoSet = new HashSet<>();
// AttchmentsVo attchmentsVo = new AttchmentsVo();
// attchmentsVo.setId(tuoKeVo.getId());
// attchmentsVo.setType(tuoKeVo.getType());
// attchmentsVoSet.add(attchmentsVo);
// object1.put("attchments", attchmentsVoSet); //附件信息集合 参⻅ 附件信息
object1.put("attchments", tuoKeVo.getSet()); //附件信息集合 参⻅ 附件信息
object1.put("settleType", tuoKeVo.getSettleType()); //结算类型 D0秒到 D1次日结算
System.out.println("请求报文: " + object1);
/**获取拓客accessToken**/
Map map = getToken();
String result="";
try{
result = cn.hutool.http.HttpRequest.post(tuoKeMerchat)
.header("Authorization", "bearer " + map.get("access_token")).header("content-type", "application/json")
.body(object1.toString()).execute().body();
Map arry = (Map) JSONArray.parse(result);
if (String.valueOf(arry.get("status")).equals("WAIT_AUDI")){
PlussMerchantLklEntity plussMerchantLklEntity =new PlussMerchantLklEntity();
plussMerchantLklEntity.setMerchantId(tuoKeVo.getMerchantCode());
plussMerchantLklEntity.setMerchantlkl(String.valueOf(arry.get("merchantNo")));
plussMerchantLklEntity.setType("0");
merchantLklService.save(plussMerchantLklEntity);
}else {
}
}catch (Exception e){
Map arry = (Map) JSONArray.parse(result);
new MsgException(String.valueOf(arry.get("message")));
}
}
@Resource
YSAuditServiceV3 auditServiceV3;
/**
* 进件回调
* */
public String tuoKeCallBack(Map<String,Object> map){
String data = LaKaLaUtility.decrypt(map.get("data").toString());
Map arryMap = (Map) JSONArray.parse(data);
System.out.println(arryMap);
if (String.valueOf(arryMap.get("status")).equals("SUCCESS")){
CallBackVo callBackVo =new CallBackVo();
callBackVo.setStatus("00");
callBackVo.setNote(String.valueOf(arryMap.get("remark")));
callBackVo.setSysFlowId(String.valueOf(arryMap.get("customerNo")));
callBackVo.setJsoon(data);
auditServiceV3.lklResultHandle(callBackVo);
} else if (String.valueOf(arryMap.get("status")).equals("FAILURE")) {
CallBackVo callBackVo =new CallBackVo();
callBackVo.setStatus("90");
callBackVo.setNote(String.valueOf(arryMap.get("remark")));
callBackVo.setSysFlowId(String.valueOf(arryMap.get("customerNo")));
callBackVo.setJsoon(data);
auditServiceV3.lklResultHandle(callBackVo);
}
return "200";
}
/**
* 获取拓客accessToken
*/
public static Map getToken() {
RestTemplate client = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
// 表单提交
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.set("Authorization", "Basic " + getBase64());
// 封装参数
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("grant_type", grant_type);
params.add("client_id", client_id);
params.add("client_secret", client_secret);
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(params, headers);
// 执行HTTP请求
ResponseEntity<String> response = client.exchange(tuoKeToken, HttpMethod.POST, requestEntity, String.class);
Map map = (Map) JSONArray.parse(response.getBody());
return map;
}
// 加密
public static String getBase64() {
String encodeBase64String = org.apache.commons.codec.binary.Base64.encodeBase64String((client_id + ":" + client_secret).getBytes());
return encodeBase64String;
}
// 解密
public static String getFromBase64(String s) {
byte[] decodeBase64 = org.apache.commons.codec.binary.Base64.decodeBase64(s);
s = new String(decodeBase64);
return s;
}
/**
* 拼接身份证过期时间
*/
public String birthdayDate(String date) {
String str = new String(date);
String s1 = "";
s1 = str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(6, str.length());
return s1;
}
@Autowired
private UserAppService userAppService;
/**
* 获取结算人信息
*/
public AccountDTO getAccountV4(String userId, String type) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.set("token", "admin");
headers.set("myLoginName", "admin");
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
ResponseEntity<String> exchange = restTemplate.exchange("http://127.0.0.1:7004/api/account/v4?userId=" + userId + "&channelType=" + type, HttpMethod.GET, formEntity, String.class);
JSONObject jsonArray = JSONArray.parseObject(exchange.getBody());
AccountDTO accountDTO = JSONArray.parseObject(jsonArray.get("data").toString(), AccountDTO.class);
System.out.println(accountDTO);
return accountDTO;
}
/**
* 获取地区信息
*/
@Override
public List<OrganVo> getOrganCode(String code) {
/**获取拓客accessToken**/
RestTemplate client = new RestTemplate();
Map parse = getToken();
HttpHeaders header = new HttpHeaders();
header.set("Authorization", "bearer " + parse.get("access_token"));
// 封装参数
MultiValueMap<String, String> par = new LinkedMultiValueMap<String, String>();
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(par, header);
// 执行HTTP请求
ResponseEntity<String> re = client.exchange(organparentCode + code, HttpMethod.GET, request, String.class);
List<OrganVo> jsonArrayList = null;
try {
String seqResult = new String(re.getBody().getBytes("ISO8859-1"), "utf-8");
jsonArrayList = JSONArray.parseArray(seqResult, OrganVo.class);
// jsonArrayList = (List<OrganVo>) JSONArray.parse(seqResult);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return jsonArrayList;
}
/**
* 获取银行地区信息
*/
public String bankOrgen(String code) {
RestTemplate client = new RestTemplate();
Map parse = getToken();
HttpHeaders header = new HttpHeaders();
header.set("Authorization", "bearer " + parse.get("access_token"));
MultiValueMap<String, String> par = new LinkedMultiValueMap<String, String>();
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(par, header);
// 执行HTTP请求
ResponseEntity<String> re = client.exchange(organizationBank + code, HttpMethod.GET, request, String.class);
try {
String seqResult = new String(re.getBody().getBytes("ISO8859-1"), "utf-8");
return seqResult;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
/**
* 银行列表查询
*/
public String banList(String areaCode) {
Map parse = getToken();
//请求头
HttpHeaders header = new HttpHeaders();
header.add("Authorization", "bearer " + parse.get("access_token"));
MultiValueMap<String, Object> param = new LinkedMultiValueMap<String, Object>();
//封装请求头
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(param, header);
RestTemplate restTemplate = new RestTemplate();
try {
//访问地址
ResponseEntity<String> result4 = restTemplate.exchange("https://htkactvi.lakala.com/registration/bank?areaCode=" + areaCode, HttpMethod.GET, formEntity, String.class);
String seqResult = new String(result4.getBody().getBytes("ISO8859-1"), "utf-8");
return seqResult;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 商户类别查询
* 一般商户传1 小微系统商户传2 拓客现在只传2
*/
public String htkRegistration() {
/**获取拓客accessToken**/
RestTemplate client = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
// 表单提交
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// 封装参数
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("grant_type", "client_credentials");
params.add("client_id", "testsit");
params.add("client_secret", "EguwEckByf2I6u6z");
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(params, headers);
// 执行HTTP请求
ResponseEntity<String> response = client.exchange("https://test.wsmsd.cn/sit/htkauth/oauth/token", HttpMethod.POST, requestEntity, String.class);
System.out.println(response.getBody().toString());
Map parse = (Map) JSONArray.parse(response.getBody().toString());
HttpHeaders header = new HttpHeaders();
header.set("Authorization", "bearer " + parse.get("access_token"));
// 封装参数
MultiValueMap<String, String> par = new LinkedMultiValueMap<String, String>();
par.add("businessScene", "2");
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(par, header);
// 执行HTTP请求
ResponseEntity<String> re = client.exchange("https://test.wsmsd.cn/sit/htkregistration/customer/category", HttpMethod.GET, request, String.class);
try {
String seqResult = new String(re.getBody().getBytes("ISO8859-1"), "utf-8");
return seqResult;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
/**
* 获取大类和小类
*/
public String getRegistrationChid() {
/**获取拓客accessToken**/
RestTemplate client = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
// 表单提交
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// 封装参数
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("grant_type", "client_credentials");
params.add("client_id", "testsit");
params.add("client_secret", "EguwEckByf2I6u6z");
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(params, headers);
// 执行HTTP请求
ResponseEntity<String> response = client.exchange("https://test.wsmsd.cn/sit/htkauth/oauth/token", HttpMethod.POST, requestEntity, String.class);
System.out.println(response.getBody().toString());
Map parse = (Map) JSONArray.parse(response.getBody().toString());
HttpHeaders header = new HttpHeaders();
header.set("Authorization", "bearer " + parse.get("access_token"));
// 封装参数
MultiValueMap<String, String> par = new LinkedMultiValueMap<String, String>();
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(par, header);
// 执行HTTP请求
ResponseEntity<String> re = client.exchange("https://test.wsmsd.cn/sit/htkregistration/customer/category", HttpMethod.GET, request, String.class);
try {
String seqResult = new String(re.getBody().getBytes("ISO8859-1"), "utf-8");
return seqResult;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
/**
* 拓客文件上传接口
*/
@SneakyThrows
public String laKaLaFileUpload(String url1) {
RestTemplate restTemplate = new RestTemplate();
String url = fileUpload;
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
// String url1 = "https://czg-oss.oss-cn-hangzhou.aliyuncs.com/images/9b42a8f68e2b4682bdb72490abe131fe.png?Expires=1994642722&OSSAccessKeyId=LTAI5tPdEfYSZcqHbjCrtPRD&Signature=cTcS0ey%2F6NYWQnyvVCMQsO6rZMU%3D";
URI uri = null;
try {
uri = new URI(url1);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
RestTemplate restTemplate1 = new RestTemplate();
ResponseEntity<byte[]> exchange = restTemplate1.exchange(uri, HttpMethod.GET, null, byte[].class);
MultipartFile file1 = new MockMultipartFile("file", exchange.getBody());
ByteArrayResource fileAsResource = new ByteArrayResource(file1.getBytes()) {
@Override
public String getFilename() {
return file1.getOriginalFilename();
// return null;
}
@Override
public long contentLength() {
// return 0L;
return file1.getSize();
}
};
params.add("file", fileAsResource);
params.add("imgType", "ID_CARD_FRONT");
params.add("sourcechnl", "1");
params.add("isOcr", "false");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
Map token = getToken();
headers.set("Authorization", "bearer " + token.get("access_token"));
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
String result = restTemplate.postForObject(url, requestEntity, String.class);
Map parse = (Map) JSONArray.parse(result);
return parse.get("url").toString();
}
/**
* 银行地区对象
*/
@Data
static class BankInfo {
private String clearNo;
private String branchBankNo;
private String branchBankName;
private String bankNo;
private String areaCode;
}
/**
* 银行对象
*/
@Data
static class Region {
private String code;
private String name;
}
public void ff() {
LaKalaInterfaceImpl laKalaInterface = new LaKalaInterfaceImpl();
String s = laKalaInterface.bankOrgen("1");
List<Region> lists = JSONArray.parseArray(s, Region.class);
for (Region list : lists) {
String s1 = laKalaInterface.bankOrgen(list.getCode());
List<Region> lists1 = JSONArray.parseArray(s1, Region.class);
for (Region bank : lists1) {
String s2 = laKalaInterface.banList(bank.getCode());
List<BankInfo> bankInfos = JSONArray.parseArray(s2, BankInfo.class);
for (BankInfo bankInfo : bankInfos) {
TbLklRegionBankInfoEntity entity = new TbLklRegionBankInfoEntity();
entity.setSCode(list.getCode());
entity.setSName(list.getName());
entity.setRCode(bank.getCode());
entity.setRName(bank.getName());
entity.setAreaCode(bankInfo.getAreaCode());
entity.setBankNo(bankInfo.getBankNo());
entity.setBranchBankName(bankInfo.getBranchBankName());
entity.setBranchBankNo(bankInfo.getBranchBankNo());
entity.setClearNo(bankInfo.getClearNo());
tbLklRegionBankInfoServiceImpl.aa(entity);
}
}
}
}
public static void main(String[] args) {
// getToken();
LaKalaInterfaceImpl laKalaInterface = new LaKalaInterfaceImpl();
laKalaInterface.getOrganCode("1");
// try {
// laKalaInterface.laKaLaFileUpload1();
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// System.out.println(getBase64("testsit:EguwEckByf2I6u6z"));
// String str = new String("20180301");
// String s1 = "";
//
// s1 = str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(6, str.length());
//
// System.out.println(s1);
}
}

View File

@@ -0,0 +1,11 @@
package cn.pluss.platform.klk.service.impl;
import cn.pluss.platform.entity.PlussMerchantLklEntity;
import cn.pluss.platform.klk.service.PlussMerchantLklService;
import cn.pluss.platform.mapper.PlussMerchantLklDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class PlussMerchantLklServiceImpl extends ServiceImpl<PlussMerchantLklDao, PlussMerchantLklEntity> implements PlussMerchantLklService {
}

View File

@@ -0,0 +1,20 @@
package cn.pluss.platform.klk.service.impl;
import cn.pluss.platform.entity.TbLklRegionBankInfoEntity;
import cn.pluss.platform.klk.service.TbLklRegionBankInfoService;
import cn.pluss.platform.mapper.TbLklRegionBankInfoDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service("tbLklRegionBankInfoServiceImpl")
public class TbLklRegionBankInfoServiceImpl extends ServiceImpl<TbLklRegionBankInfoDao, TbLklRegionBankInfoEntity> implements TbLklRegionBankInfoService {
@Resource
TbLklRegionBankInfoDao regionBankInfoDao;
public void aa(TbLklRegionBankInfoEntity entity){
// QueryWrapper<TbLklRegionBankInfoEntity> wrapper =new QueryWrapper<>();
regionBankInfoDao.insert(entity);
}
}

View File

@@ -0,0 +1,12 @@
package cn.pluss.platform.klk.service.impl;
import cn.pluss.platform.entity.TbPlussBankBranchLklEntity;
import cn.pluss.platform.klk.service.TbPlussBankBranchLklService;
import cn.pluss.platform.mapper.TbPlussBankBranchLklMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class TbPlussBankBranchLklServiceImpl extends ServiceImpl<TbPlussBankBranchLklMapper, TbPlussBankBranchLklEntity> implements TbPlussBankBranchLklService {
}

View File

@@ -0,0 +1,11 @@
package cn.pluss.platform.klk.service.impl;
import cn.pluss.platform.entity.TbPlussBankRegionLklEntity;
import cn.pluss.platform.klk.service.TbPlussBankRegionLklService;
import cn.pluss.platform.mapper.TbPlussBankRegionLklMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class TbPlussBankRegionLklServiceImpl extends ServiceImpl<TbPlussBankRegionLklMapper, TbPlussBankRegionLklEntity> implements TbPlussBankRegionLklService {
}

View File

@@ -0,0 +1,11 @@
package cn.pluss.platform.klk.service.impl;
import cn.pluss.platform.entity.TbPlussBusinessSmallLklEntity;
import cn.pluss.platform.klk.service.TbPlussBusinessSmallLklService;
import cn.pluss.platform.mapper.TbPlussBusinessSmallLklDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class TbPlussBusinessSmallLklServiceImpl extends ServiceImpl<TbPlussBusinessSmallLklDao, TbPlussBusinessSmallLklEntity> implements TbPlussBusinessSmallLklService {
}

View File

@@ -0,0 +1,11 @@
package cn.pluss.platform.klk.service.impl;
import cn.pluss.platform.entity.TbPlussRegionLklEntity;
import cn.pluss.platform.klk.service.TbPlussRegionLklService;
import cn.pluss.platform.mapper.TbPlussRegionLklMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class TbPlussRegionLklServiceImpl extends ServiceImpl<TbPlussRegionLklMapper, TbPlussRegionLklEntity> implements TbPlussRegionLklService {
}

View File

@@ -0,0 +1,9 @@
package cn.pluss.platform.klk.vo;
import lombok.Data;
@Data
public class AttchmentsVo {
private String id;
private String type;
}

View File

@@ -0,0 +1,11 @@
package cn.pluss.platform.klk.vo;
import lombok.Data;
@Data
public class CallBackVo {
private String status;
private String sysFlowId;
private String note;
private String jsoon;
}

View File

@@ -0,0 +1,9 @@
package cn.pluss.platform.klk.vo;
import lombok.Data;
@Data
public class FeesSetVo {
private String feeCode;
private String feeValue;
}

View File

@@ -0,0 +1,14 @@
package cn.pluss.platform.klk.vo;
import lombok.Data;
@Data
public class OrganVo {
private String id;
private String createTime;
private String optimistic;
private String updateTime;
private String code;
private String name;
private String parentCode;
}

View File

@@ -0,0 +1,68 @@
package cn.pluss.platform.klk.vo;
import lombok.Data;
import java.util.Set;
@Data
public class TuoKeVo {
private String userNo;
private String email;
private String busiCode;
private String merchantCode;
private String merRegName;
private String merType;
private String merName;
private String merAddr;
private String provinceCode;
private String cityCode;
private String countyCode;
private String licenseName;
private String licenseNo;
private String licenseDtStart;
private String licenseDtEnd;
private String latitude;
private String longtude;
private String source;
private String businessContent;
private String larName;
private String larIdType;
private String larIdCard;
private String larIdCardStart;
private String larIdCardEnd;
private String contactMobile;
private String contactName;
private String openningBankCode;
private String openningBankName;
private String clearingBankCode;
private String settleProvinceCode;
private String settleProvinceName;
private String settleCityCode;
private String settleCityName;
private String accountNo;
private String accountName;
private String accountType;
private String accountIdCard;
private String ccountIdDtStart;
private String accountIdDtEnd;
private String accountIdType;
private String bizContent;
private String settleType;
private String shopId;
private String settlementType;
private String regularSettlementTime;
private String merchantNo;
private String id;
private String type;
private String termNum;
private String termVer;
private String fees;
private String mcc;
private String feeCode;
private String feeValue;
private String topFee;
private String activityId;
private Set<Object> set;
}

View File

@@ -20,6 +20,7 @@ import cn.pluss.platform.entity.*;
import cn.pluss.platform.enums.UserRoleEnum;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.jfShop.JfShopHandler;
import cn.pluss.platform.klk.service.impl.LaKalaInterfaceImpl;
import cn.pluss.platform.leshua.BizConstants;
import cn.pluss.platform.leshua.ExpandDto;
import cn.pluss.platform.mapper.*;
@@ -65,6 +66,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -735,7 +737,8 @@ public class UserAppServiceImpl extends ServiceImpl<UserAppMapper, UserApp> impl
return result;
}
@Resource
LaKalaInterfaceImpl laKalaInterface;
@Override
@Transactional(rollbackFor = Exception.class)
public void merchantAudit(JSONObject jsonObject, String channelId) {
@@ -801,6 +804,8 @@ public class UserAppServiceImpl extends ServiceImpl<UserAppMapper, UserApp> impl
//ysAuditServiceV2.merchantAudit(userId, false);
ysAuditServiceV3.merchantAuditV3(userId, false);
break;
case "5":
laKalaInterface.createTuoKeInfo(userId);
default:
MsgException.throwException("未知的进件通道");
}

View File

@@ -88,6 +88,7 @@
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
</dependencies>
<!-- <dependencyManagement>-->

View File

@@ -66,6 +66,9 @@ import cn.pluss.platform.wechat.*;
import cn.pluss.platform.wx.WxAccessTokenRequest;
import cn.pluss.platform.wx.WxCommonService;
import cn.pluss.platform.wx.WxOauth2AccessTokenResponse;
import cn.pluss.platform.ys.YSConstants;
import cn.pluss.platform.ys.YsEnum;
import cn.pluss.platform.ys.YsService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
@@ -168,6 +171,9 @@ public class MerchantController {
@Setter(onMethod_ = {@Autowired, @Qualifier("ysPayOldService")})
private PayService ysPayOldService;
@Setter(onMethod_ = {@Autowired, @Qualifier("lkLPayService")})
private PayService lkLPayService;
@Setter(onMethod_ = {@Autowired})
private RyxPayService ryxPayService;
@@ -565,6 +571,8 @@ public class MerchantController {
unionInfo = ryxPayService.getUnionInfo(userAuthCode, payMentApp, channel.getMerchantId());
} else if (channel.getChannel() == 4) {
unionInfo = ysPayOldService.getUnionInfo(userAuthCode, payMentApp, null);
} else if (channel.getChannel() == 5) {
unionInfo = lkLPayService.getUnionInfo(userAuthCode, payMentApp, null);
} else {
view.addObject("error", "未知通道类型");
return view;
@@ -1698,6 +1706,8 @@ public class MerchantController {
unionInfo = ryxPayService.getUnionInfo(userAuthCode, payMentApp, channel.getMerchantId());
} else if (channel.getChannel() == 4) {
unionInfo = ysPayOldService.getUnionInfo(userAuthCode, payMentApp, null);
} else if (channel.getChannel() == 5) {
unionInfo = lkLPayService.getUnionInfo(userAuthCode, payMentApp, null);
} else {
view.addObject("error", "未知通道类型");
return view;
@@ -1929,6 +1939,8 @@ public class MerchantController {
return modelAndView;
} else if (channel.getChannel() == 4) {
unionInfo = ysPayOldService.getUnionInfo(userAuthCode, payMentApp, null);
} else if (channel.getChannel() == 5) {
unionInfo = lkLPayService.getUnionInfo(userAuthCode, payMentApp, null);
} else {
modelAndView.addObject("error", "未知通道类型");
modelAndView.setViewName("/merchant/errorInfo2");