package project.web.api;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
import kernel.web.ApplicationUtil;
|
import com.mysql.cj.util.StringUtils;
|
import project.party.PartyService;
|
import project.party.model.Party;
|
import kernel.exception.BusinessException;
|
import kernel.web.BaseAction;
|
import kernel.web.ResultObject;
|
import project.user.idcode.IdentifyingCodeService;
|
import project.web.api.JsonUtils;
|
import project.web.api.SafeUtils;
|
|
import java.io.BufferedReader;
|
import java.io.IOException;
|
import java.util.*;
|
import project.web.api.HttpsTransport;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
import project.wallet.WalletService;
|
import project.wallet.WalletLog;
|
import project.wallet.WalletLogService;
|
import project.Constants;
|
import project.log.MoneyLog;
|
import project.log.MoneyLogService;
|
import kernel.util.Arith;
|
import project.wallet.Wallet;
|
import project.wallet.WalletExtend;
|
import project.blockchain.RechargeBlockchain;
|
import project.blockchain.RechargeBlockchainService;
|
import com.alibaba.fastjson.JSONObject;
|
import java.util.HashMap;
|
import project.log.MoneyLogService;
|
|
/**
|
* 邮箱或手机绑定
|
* 发送验证码
|
*
|
*/
|
@RestController
|
@CrossOrigin
|
public class IdentifyingCodeController extends BaseAction {
|
|
@Autowired
|
private IdentifyingCodeService identifyingCodeService;
|
@Autowired
|
private PartyService partyService;
|
@Autowired
|
private WalletService walletService;
|
@Autowired
|
private WalletLogService walletLogService;
|
@Autowired
|
private RechargeBlockchainService rechargeBlockchainService;
|
@Autowired
|
private MoneyLogService moneyLogService;
|
|
@RequestMapping("/api/idcode!execute.action")
|
public Object execute(HttpServletRequest request) {
|
ResultObject resultObject = new ResultObject();
|
try {
|
// 邮件或手机号
|
String target = request.getParameter("target");
|
if (StringUtils.isNullOrEmpty(target)) {
|
throw new BusinessException("不能为空");
|
}
|
identifyingCodeService.send(target, this.getIp());
|
} catch (BusinessException e) {
|
resultObject.setCode("1");
|
resultObject.setMsg(e.getMessage());
|
}
|
return resultObject;
|
}
|
|
@RequestMapping("/api/rechargeCallback!execute.action")
|
public void rechargeCallback(HttpServletRequest request) {
|
try {
|
System.out.println("支付回调start...");
|
// Map<String, String> paramsMap = SafeUtils.convertRequestParamsToMap(request);
|
//将异步通知中收到的待验证所有参数都存放到map中
|
StringBuilder sb = new StringBuilder();
|
BufferedReader reader = request.getReader();
|
String line;
|
while ((line = reader.readLine()) != null) {
|
sb.append(line);
|
}
|
String json = sb.toString();
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
Map<String, String> paramsMap = new HashMap<String,String>();
|
if(jsonObject.containsKey("recharge_hash")){
|
paramsMap.put("recharge_hash",jsonObject.getString("recharge_hash"));
|
}
|
if(jsonObject.containsKey("user_id")){
|
paramsMap.put("user_id",jsonObject.getString("user_id"));
|
}
|
if(jsonObject.containsKey("from_address")){
|
paramsMap.put("from_address",jsonObject.getString("from_address"));
|
}
|
if(jsonObject.containsKey("address")){
|
paramsMap.put("address",jsonObject.getString("address"));
|
}
|
if(jsonObject.containsKey("num")){
|
paramsMap.put("num",jsonObject.getString("num"));
|
}
|
|
if(jsonObject.containsKey("confirmations")){
|
paramsMap.put("confirmations",jsonObject.getString("confirmations"));
|
}
|
if(jsonObject.containsKey("currency")){
|
paramsMap.put("currency",jsonObject.getString("currency"));
|
}
|
System.out.println("响应字符串为paramsMap:"+paramsMap);
|
|
if(null != paramsMap && null != paramsMap.get("recharge_hash")){
|
JdbcTemplate jdbcTemplate=ApplicationUtil.getBean(JdbcTemplate.class);
|
Integer count = jdbcTemplate.queryForObject("SELECT count(ID) FROM PAT_HASH WHERE HASH=? AND status = 1", Integer.class,paramsMap.get("recharge_hash"));
|
System.out.println("支付回调hashcount.."+count);
|
if(count == 0){
|
//币种
|
String currency = (String) paramsMap.get("currency");
|
|
System.out.println("支付回调currency..."+currency);
|
//数量
|
String num = paramsMap.get("num").toString();
|
System.out.println("支付回调num..."+num);
|
//充值地址
|
String address = (String) paramsMap.get("address");
|
//来源地址
|
String from = (String) paramsMap.get("from_address");
|
|
Double doubleNum = Double.parseDouble(num);
|
System.out.println("支付回调doubleNum..."+doubleNum);
|
String usercode = paramsMap.get("user_id").toString();
|
System.out.println("支付回调usercode..."+usercode);
|
String partyId = jdbcTemplate.queryForObject("SELECT UUID FROM PAT_PARTY WHERE USERCODE=?", String.class,usercode);
|
System.out.println("支付回调partyId..."+partyId);
|
Party party = this.partyService.cachePartyBy(partyId, false);
|
|
double amount_before = 0;
|
double amount_after = 0;
|
String wallettype = "";
|
String symbol = "";
|
if("TRC20-USDT".equals(currency) || "ERC20-USDT".equals(currency)){
|
if("TRC20-USDT".equals(currency)){
|
symbol = "TRC20";
|
}else{
|
symbol = "ERC20";
|
}
|
// 交易所修改usdt
|
Wallet wallet = this.walletService.saveWalletByPartyId(partyId);
|
amount_before = wallet.getMoney();
|
System.out.println("交易所修改usdt amount_before"+amount_before);
|
// 更新金额
|
this.walletService.update(wallet.getPartyId().toString(), doubleNum);
|
amount_after = Arith.add(wallet.getMoney(), doubleNum);
|
System.out.println("交易所修改usdt amount_after"+amount_after);
|
System.out.println("symbol symbol"+symbol);
|
wallettype = "USDT";
|
}else{
|
currency = currency.toLowerCase();
|
WalletExtend walletExtend = this.walletService.saveExtendByPara(partyId, currency);
|
amount_before = walletExtend.getAmount();
|
this.walletService.updateExtend(walletExtend.getPartyId().toString(), currency, doubleNum);
|
amount_after = Arith.add(walletExtend.getAmount(), doubleNum);
|
wallettype = currency;
|
symbol = currency;
|
}
|
String uuid = UUID.randomUUID().toString();
|
String uuidReplace = uuid.replace("-", "");
|
System.out.println("存储充值申请订单记录uuid" + uuidReplace);
|
String insertSql = "INSERT INTO T_RECHARGE_BLOCKCHAIN_ORDER(UUID,ORDER_NO,PARTY_ID,SUCCEEDED,CREATED,COIN,DESCRIPTION,BLOCKCHAIN_NAME,IMG,CHANNEL_AMOUNT,ADDRESS,CHANNEL_ADDRESS,REVIEWTIME,TX) VALUES(?,?,?,1,?,?,'',?,'',?,?,?,?,?)";
|
jdbcTemplate.update(insertSql
|
,uuidReplace,"R"+System.currentTimeMillis(),
|
partyId,new Date(),wallettype,symbol,
|
doubleNum,from,address,new Date(),paramsMap.get("recharge_hash"));
|
|
// recharge.setChannel_address(channel_address);
|
// recharge.setTx(StringUtils.isEmptyString(tx) ? "" : tx);
|
// 账变日志
|
MoneyLog moneyLog = new MoneyLog();
|
moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_RECHARGE);
|
moneyLog.setAmount_before(amount_before);
|
moneyLog.setAmount(doubleNum);
|
moneyLog.setAmount_after(amount_after);
|
moneyLog.setPartyId(partyId);
|
moneyLog.setLog("充值到账");
|
moneyLog.setWallettype(Constants.WALLET);
|
moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
|
this.moneyLogService.save(moneyLog);
|
System.out.println("支付回调doubleNum..."+doubleNum);
|
// 钱包日志
|
WalletLog walletLog = new WalletLog();
|
walletLog.setCategory(Constants.MONEYLOG_CATEGORY_RECHARGE);
|
walletLog.setPartyId(partyId);
|
walletLog.setOrder_no("R"+ System.currentTimeMillis());
|
walletLog.setStatus(1);
|
walletLog.setAmount(doubleNum);
|
walletLog.setWallettype(wallettype);
|
this.walletLogService.save(walletLog);
|
jdbcTemplate.update("INSERT INTO PAT_HASH(HASH,STATUS) VALUES(?,?)",paramsMap.get("recharge_hash"),1);
|
}
|
}
|
|
} catch (BusinessException e) {
|
System.out.println("出异常了");
|
System.out.println(e.getMessage());
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
}
|
|
@RequestMapping("/api/withdrawCallback!execute.action")
|
public void withdrawCallback(HttpServletRequest request) {
|
try {
|
System.out.println("提现回调start...");
|
//将异步通知中收到的待验证所有参数都存放到map中
|
Map<String, String> paramsMap = SafeUtils.convertRequestParamsToMap(request);
|
System.out.println("响应字符串为paramsMap:"+paramsMap);
|
if(null != paramsMap && null != paramsMap.get("withdraw_hash")){
|
JdbcTemplate jdbcTemplate = ApplicationUtil.getBean(JdbcTemplate.class);
|
String withdrawHash = (String) paramsMap.get("withdraw_hash");
|
Integer count = jdbcTemplate.queryForObject("SELECT count(ID) FROM PAT_HASH WHERE HASH=? AND status = 1", Integer.class,withdrawHash);
|
System.out.println("提现回调hashcount.."+count);
|
if(count == 0){
|
//2:提币成功 3:提币失败
|
String status = (String) paramsMap.get("status");
|
System.out.println("提现回调status.."+status);
|
System.out.println("2".equals(status));
|
|
if("2".equals(status)){
|
String partyId = jdbcTemplate.queryForObject("SELECT PARTY_ID FROM T_WITHDRAW_ORDER WHERE WITHDRAW_HASH=?", String.class,withdrawHash);
|
System.out.println("提现回调partyId.."+partyId);
|
Party party = this.partyService.cachePartyBy(partyId, false);
|
|
jdbcTemplate.update("INSERT INTO PAT_HASH(HASH,STATUS) VALUES(?,?)",withdrawHash,1);
|
|
jdbcTemplate.update("UPDATE T_WITHDRAW_ORDER SET SUCCEEDED = 1 WHERE WITHDRAW_HASH = ?",withdrawHash);
|
}
|
}
|
}
|
|
} catch (BusinessException e) {
|
}
|
}
|
|
}
|