generated from root/miduo_server
133 lines
5.4 KiB
Java
133 lines
5.4 KiB
Java
package com.jmfy.controller;
|
||
|
||
import com.jmfy.dto.CPayOrder;
|
||
import com.jmfy.dto.CUserDao;
|
||
import com.jmfy.dto.CUserInfo;
|
||
import com.jmfy.paramBean.PaySdkEnum;
|
||
import com.jmfy.thrift.idl.RPCRequestIFace;
|
||
import com.jmfy.thrift.idl.Result;
|
||
import com.jmfy.thrift.pool.ClientAdapterPo;
|
||
import com.jmfy.thrift.pool.ServiceKey;
|
||
import com.jmfy.util.JsonUtil;
|
||
import org.apache.commons.lang.ArrayUtils;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.stereotype.Component;
|
||
|
||
import javax.annotation.Resource;
|
||
import java.text.DateFormat;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.Date;
|
||
|
||
/**
|
||
* @Author hj
|
||
* @Date 2021/6/23 17:06
|
||
* @Description:
|
||
* @Version 1.0
|
||
*/
|
||
@SuppressWarnings("ALL")
|
||
@Component
|
||
public class PayLogic {
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(PayLogic.class);
|
||
|
||
@Resource
|
||
private CUserDao cuserDao;
|
||
|
||
private PayLogic() {
|
||
}
|
||
|
||
public String initOrder(String collBackInfo, String orderId, String amount, Date time, String openId, PaySdkEnum sdk){
|
||
return initOrder(collBackInfo,orderId,amount,time,openId,sdk,"");
|
||
}
|
||
|
||
/**
|
||
*
|
||
* @param collBackInfo 回调参数
|
||
* @param orderId 自己订单号
|
||
* @param amount 金钱,单位是分
|
||
* @param time 支付时间
|
||
* @param openId 渠道的用户id,目前用不到
|
||
* @param sdk sdk,支付渠道标识
|
||
* @return
|
||
*/
|
||
public String initOrder(String collBackInfo, String orderId, String amount, Date time, String openId, PaySdkEnum sdk, String ext){
|
||
try {
|
||
// 角色id_物品id_ccId_平台
|
||
String[] collback = collBackInfo.split("_");
|
||
LOGGER.info("支付透传参数,分割前:{},分割后:{},长度:{},支付:{}",collBackInfo, ArrayUtils.toString(collback,","),collback.length,sdk.getName());
|
||
String uid = collback.length > 0 ? collback[0] : "0";
|
||
String goodsId = collback.length > 1 ? collback[1] : "0";
|
||
String ccId = collback.length > 2 ? collback[2] : "0";
|
||
String platform = collback.length > 3 ? collback[3] : "ANDROID";
|
||
|
||
CUserInfo cUserInfo = cuserDao.findUserInfo(Integer.valueOf(uid));
|
||
//0为了兼容
|
||
if (!"0".equals(uid) && cUserInfo == null) {
|
||
LOGGER.info("该用户无此角色" + uid);
|
||
return "USER_IS_NOT";
|
||
}
|
||
|
||
CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(orderId);
|
||
|
||
if (cPayOrder != null) {
|
||
LOGGER.info("callback==>creditId={},uId={} orderId is exit!!!", cUserInfo.getId(), cUserInfo.getOpenId());
|
||
return "ORDER_IS_EXIST";
|
||
} else {
|
||
DateFormat dateTimeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
String date = dateTimeformat.format(time);
|
||
cPayOrder = new CPayOrder();
|
||
cPayOrder.setOrderId(orderId);
|
||
cPayOrder.setServerId(cUserInfo.getServerid());
|
||
cPayOrder.setDelivery_time(date);
|
||
cPayOrder.setUserId(uid);
|
||
cPayOrder.setAmount(amount);
|
||
cPayOrder.setGoodsId(goodsId);
|
||
cPayOrder.setCc_id(ccId);
|
||
cPayOrder.setPaySdk(sdk.getName());
|
||
cPayOrder.setPlatform(platform);
|
||
|
||
Result result = null;
|
||
String userAddress = cuserDao.findUserAddress(cUserInfo.getId());
|
||
if (userAddress != null) {
|
||
LOGGER.info("callback==>userAddress={} ", userAddress);
|
||
String[] split = userAddress.split(":");
|
||
String ip = split[0];
|
||
String port = split[1];
|
||
LOGGER.info("RPC address --> IP : " + ip + "; PORT : " + port);
|
||
ClientAdapterPo<RPCRequestIFace.Client> rPCClient = null;
|
||
String serviceKey = JsonUtil.getServiceKey(ServiceKey.RPCCore, ip, port);
|
||
LOGGER.info("serviceKey : " + serviceKey);
|
||
try {
|
||
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
||
result = rPCClient.getClient().deliveryRecharge(cUserInfo.getId(), goodsId, openId, orderId, 0, (int)Double.parseDouble(amount));
|
||
} catch (Exception e) {
|
||
LOGGER.info("callback=>", e);
|
||
} finally {
|
||
if (rPCClient != null) {
|
||
rPCClient.returnObject(serviceKey);
|
||
} else {
|
||
LOGGER.info("callback=> rPCClient is null ");
|
||
}
|
||
}
|
||
} else {
|
||
LOGGER.info("not get the user url,the openID={} ", uid);
|
||
return "REDIS_ADDRESS_NULL";
|
||
}
|
||
if (result != null && result.getResultCode() == 1) {
|
||
LOGGER.info(" callback==>RPC result : ResultCode : " + result.getResultCode() + "; ResultMsg : " + result.getResultMsg());
|
||
cuserDao.addCpayOrder(cPayOrder);
|
||
} else {
|
||
LOGGER.error("发送订单到游戏服,返回数据异常");
|
||
return "GAME_SERVER_RESULT_ERROR";
|
||
}
|
||
}
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
LOGGER.info("callback==>err " + e.toString());
|
||
return "FAIL";
|
||
}
|
||
return "SUCCESS";
|
||
}
|
||
}
|